Update of /cvsroot/audacity/audacity-src/src/ondemand
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv20772/ondemand

Modified Files:
        ODManager.cpp ODManager.h ODTaskThread.cpp ODTaskThread.h 
Log Message:
changing OD queue from polling to condition variables.  Mac build tested 
(pthreads) but PC to be checked.

Index: ODManager.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/ondemand/ODManager.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- ODManager.cpp       19 Sep 2009 00:03:57 -0000      1.29
+++ ODManager.cpp       6 Oct 2009 15:56:41 -0000       1.30
@@ -125,6 +125,10 @@
    mTerminate = false;
    mTerminated = false;
    mPause= gPause;
+   
+   //must set up the queue condition
+   mQueueNotEmptyCond = new ODCondition(&mQueueNotEmptyCondLock);
+   
 }
 
 //private constructor - delete with static method Quit()
@@ -134,7 +138,8 @@
    //nothing else should be running on OD related threads at this point, so we 
don't lock.
    for(unsigned int i=0;i<mQueues.size();i++)
       delete mQueues[i];
-      
+
+   delete mQueueNotEmptyCond;
 }
 
 
@@ -145,6 +150,10 @@
    mTasksMutex.Lock();
    mTasks.push_back(task);
    mTasksMutex.Unlock();
+   //signal the queue not empty condition.
+   mQueueNotEmptyCondLock.Lock();
+   mQueueNotEmptyCond->Signal();
+   mQueueNotEmptyCondLock.Unlock();
 }
 
 ///removes a task from the active task queue
@@ -318,20 +327,20 @@
       }
 
       mCurrentThreadsMutex.Unlock();
-      //TODO: use a conditon variable to block here instead of a sleep.  
-      //Also find out if the condition variable polls to quickly - we don't 
want that either.
-      wxThread::Sleep(200);
-//wxSleep can't be called from non-main thread.
-//      ::wxMilliSleep(250);
-      
-      //if there is some ODTask running, then there will be something in the 
queue.  If so then redraw to show progress
+      //use a conditon variable to block here instead of a sleep.  
+      //wxThread::Sleep(200);
+      mQueueNotEmptyCondLock.Lock();
+      if(tasksInArray<=0)
+         mQueueNotEmptyCond->Wait();
+      mQueueNotEmptyCondLock.Unlock();
       
+      //if there is some ODTask running, then there will be something in the 
queue.  If so then redraw to show progress      
       mQueuesMutex.Lock();
       mNeedsDraw += mQueues.size()>0?1:0;
       mQueuesMutex.Unlock();
 
       //redraw the current project only (ODTasks will send a redraw on 
complete even if the projects are in the background)
-      if(mNeedsDraw > 11)
+      if(mNeedsDraw )
       {
          mNeedsDraw=0;
          wxCommandEvent event( EVT_ODTASK_UPDATE );
@@ -386,6 +395,11 @@
       {
          ODManager::Instance()->mTerminatedMutex.Unlock();
          wxThread::Sleep(200);
+         
+         //signal the queue not empty condition since the ODMan thread will 
wait on the queue condition
+         ODManager::Instance()->mQueueNotEmptyCondLock.Lock();
+         ODManager::Instance()->mQueueNotEmptyCond->Signal();
+         ODManager::Instance()->mQueueNotEmptyCondLock.Unlock();
          ODManager::Instance()->mTerminatedMutex.Lock();
       }
       ODManager::Instance()->mTerminatedMutex.Unlock();

Index: ODTaskThread.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/ondemand/ODTaskThread.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- ODTaskThread.cpp    7 Jul 2008 23:20:57 -0000       1.5
+++ ODTaskThread.cpp    6 Oct 2009 15:56:41 -0000       1.6
@@ -55,4 +55,34 @@
    return NULL;
 #endif
 }
+
+#ifdef __WXMAC__
+ODCondition::ODCondition(ODLock *lock)
+{
+   condition = (pthread_cond_t *) malloc (sizeof (pthread_cond_t));
+   pthread_cond_init(condition, NULL);
+   m_lock=lock;
+}
+ODCondition::~ODCondition()
+{
+   pthread_cond_destroy (condition); 
+   free(condition);
+}
+
+void ODCondition::Signal()
+{
+   pthread_cond_signal(condition);
+}
+   
+void ODCondition::Broadcast()
+{
+   pthread_cond_broadcast(condition);
+}
+void ODCondition::Wait()
+{
+   pthread_cond_wait(condition,m_lock->mutex);
+}
+   
+#endif
+
   
\ No newline at end of file

Index: ODTaskThread.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/ondemand/ODTaskThread.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- ODTaskThread.h      10 Feb 2009 16:04:50 -0000      1.7
+++ ODTaskThread.h      6 Oct 2009 15:56:41 -0000       1.8
@@ -104,9 +104,23 @@
    }
   
 private:
+   friend class ODCondition; //needs friendship for wait()
    pthread_mutex_t *mutex ;
 };
 
+class ODCondition 
+{
+public:
+   ODCondition(ODLock *lock);
+   virtual ~ODCondition();
+   void Signal();
+   void Broadcast();
+   void Wait();
+   
+protected:
+   pthread_cond_t *condition;
+   ODLock* m_lock;
+};
 
 #else
 
@@ -137,6 +151,18 @@
   virtual ~ODLock(){}   
 };
 
+class ODCondition : public wxCondition
+{
+public:
+   ODCondition(ODLock *lock):wxCondition(*lock){}
+   virtual ~ODCondition(){}
+   //these calls are implemented in wxCondition:
+   //void Signal();
+   //void Broadcast();
+   //void Wait();
+   
+protected:
+};
 
 #endif // __WXMAC__
 

Index: ODManager.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/ondemand/ODManager.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- ODManager.h 19 Sep 2009 00:03:57 -0000      1.18
+++ ODManager.h 6 Oct 2009 15:56:41 -0000       1.19
@@ -160,6 +160,10 @@
    bool mTerminated;
    ODLock mTerminatedMutex;
    
+   //for the queue not empty comdition
+   ODLock         mQueueNotEmptyCondLock;
+   ODCondition*   mQueueNotEmptyCond;
+   
 #ifdef __WXMAC__
 
 // On Mac OS X, it's better not to use the wxThread class.


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Audacity-cvs mailing list
Audacity-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to