[rkward-cvs] SF.net SVN: rkward: [2341] branches/release_branch_0.4.9/rkward/windows

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Jan 23 12:33:11 UTC 2008


Revision: 2341
          http://rkward.svn.sourceforge.net/rkward/?rev=2341&view=rev
Author:   tfry
Date:     2008-01-23 04:33:10 -0800 (Wed, 23 Jan 2008)

Log Message:
-----------
Add mutex locks to RControlWindow, liberally, hoping that it will put an end to race conditions

Modified Paths:
--------------
    branches/release_branch_0.4.9/rkward/windows/rcontrolwindow.cpp
    branches/release_branch_0.4.9/rkward/windows/rcontrolwindow.h

Modified: branches/release_branch_0.4.9/rkward/windows/rcontrolwindow.cpp
===================================================================
--- branches/release_branch_0.4.9/rkward/windows/rcontrolwindow.cpp	2008-01-22 18:25:55 UTC (rev 2340)
+++ branches/release_branch_0.4.9/rkward/windows/rcontrolwindow.cpp	2008-01-23 12:33:10 UTC (rev 2341)
@@ -70,12 +70,29 @@
 
 	paused = false;
 	initialized = false;
+	mutex_lockcount = 0;
 }
 
 RControlWindow::~RControlWindow () {
 	RK_TRACE (APP);
 }
 
+void RControlWindow::lockMutex () {
+	if (!mutex_lockcount) {
+		RK_TRACE (APP);
+		MUTEX_LOCK;
+	}
+	++mutex_lockcount;
+}
+
+void RControlWindow::unlockMutex () {
+	--mutex_lockcount;
+	if (!mutex_lockcount) {
+		RK_TRACE (APP);
+		MUTEX_UNLOCK;
+	}
+}
+
 bool RControlWindow::isActive () {
 	// don't trace!
 	return (initialized && isShown ());
@@ -114,25 +131,34 @@
 	if (!isActive ()) return;	// do expensive GUI stuff only when visible
 	RK_TRACE (APP);
 
-	RChainOrCommand *dummy = new RChainOrCommand;
-	dummy->command = 0;
-	dummy->chain = chain;
-	addCommands (dummy, itemForChain (chain->parent));
-	delete dummy;
+	lockMutex ();
+
+	RChainOrCommand dummy;
+	dummy.command = 0;
+	dummy.chain = chain;
+	addCommands (&dummy, itemForChain (chain->parent));
+
+	unlockMutex ();
 }
 
 void RControlWindow::addCommand (RCommand *command, RCommandChain *parent) {
 	if (!isActive ()) return;	// do expensive GUI stuff only when visible
 	RK_TRACE (APP);
 
+	lockMutex ();
+
 	if (!parent) parent = RCommandStack::regular_stack;
 	addCommand (command, itemForChain (parent));
+
+	unlockMutex ();
 }
 
 void RControlWindow::updateChain (RCommandChain *chain) {
 	if (!isActive ()) return;	// do expensive GUI stuff only when visible
 	RK_TRACE (APP);
 
+	lockMutex ();
+
 	RControlWindowListViewItem *chainitem = itemForChain (chain);
 	if (!chainitem) {
 		RK_ASSERT (false);
@@ -140,6 +166,8 @@
 	}
 	chainitem->update (chain);
 	checkCleanChain (chainitem);
+
+	unlockMutex ();
 }
 
 void RControlWindow::updateCommand (RCommand *command) {
@@ -178,12 +206,16 @@
 	if (!isActive ()) return;	// do expensive GUI stuff only when visible
 	RK_TRACE (APP);
 
+	lockMutex ();
+
 	while (chain && chain->chain_closed && chain->parent () && (!chain->firstChild ())) {
 		RControlWindowListViewItem *del = chain;
 		chain = static_cast<RControlWindowListViewItem *> (chain->parent ());
 		chain_map.remove (del->chain);
 		delete del;
 	}
+
+	unlockMutex ();
 }
 
 void RControlWindow::setCommandRunning (RCommand *command) {
@@ -202,18 +234,18 @@
 void RControlWindow::refreshCommands () {
 	RK_TRACE (APP);
 
+	lockMutex ();
+
 	commands_view->clear ();
 	command_map.clear ();
 	chain_map.clear ();
 
-	RChainOrCommand *dummy = new RChainOrCommand;
-	dummy->command = 0;
-	dummy->chain = RCommandStack::regular_stack;
+	RChainOrCommand dummy;
+	dummy.command = 0;
+	dummy.chain = RCommandStack::regular_stack;
 
-	addCommands (dummy, 0);
+	addCommands (&dummy, 0);
 
-	delete dummy;
-
 /* add the currently running command (if needed). It is not in the stack. */
 	RCommand *running = RKGlobals::rInterface ()->runningCommand ();
 	if (running && (!command_map.contains (running))) {
@@ -226,11 +258,15 @@
 	if (running) setCommandRunning (running);
 
 	cancel_button->setEnabled (false);
+
+	unlockMutex ();
 }
 
 void RControlWindow::addCommands (RChainOrCommand *coc, RControlWindowListViewItem *parent) {
 	RK_TRACE (APP);
 
+	lockMutex ();
+
 	if (coc->chain) {
 		RControlWindowListViewItem *item;
 		RCommandChain *chain = coc->chain;
@@ -250,6 +286,8 @@
 		RK_ASSERT (parent);
 		addCommand (coc->command, parent);
 	}
+
+	unlockMutex ();
 }
 
 void RControlWindow::addCommand (RCommand *command, RControlWindowListViewItem *parent) {
@@ -409,7 +447,7 @@
 void RControlWindowListViewItem::update (RCommandChain *cchain) {
 	RK_TRACE (APP);
 	RK_ASSERT (this);
-	
+
 	chain = cchain;
 	chain_closed = cchain->closed;
 

Modified: branches/release_branch_0.4.9/rkward/windows/rcontrolwindow.h
===================================================================
--- branches/release_branch_0.4.9/rkward/windows/rcontrolwindow.h	2008-01-22 18:25:55 UTC (rev 2340)
+++ branches/release_branch_0.4.9/rkward/windows/rcontrolwindow.h	2008-01-23 12:33:10 UTC (rev 2341)
@@ -107,6 +107,11 @@
 	bool paused;
 	bool isActive ();
 	bool initialized;
+
+	void lockMutex ();
+	void unlockMutex ();
+	int mutex_lockcount;
+
 friend class RKWardMainWindow;
 	static RControlWindow *control_window;
 };


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list