/[svn]/linuxsampler/trunk/src/common/Condition.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/common/Condition.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2323 by persson, Sat Feb 18 13:51:38 2012 UTC revision 2324 by persson, Sun Mar 4 09:01:32 2012 UTC
# Line 268  Condition::~Condition() { Line 268  Condition::~Condition() {
268  #endif  #endif
269  }  }
270    
271    #ifndef WIN32
272    namespace {
273        // If the thread is cancelled while waiting for the condition
274        // variable, the mutex will be locked. It needs to be unlocked so
275        // the Condition can be reused if the thread is restarted.
276        void condition_cleanup(void* c) {
277            static_cast<Condition*>(c)->Unlock();
278        }
279    }
280    #endif
281    
282  int Condition::WaitIf(bool bCondition, long TimeoutSeconds, long TimeoutNanoSeconds) {  int Condition::WaitIf(bool bCondition, long TimeoutSeconds, long TimeoutNanoSeconds) {
283      dmsg(7,("Condition::WaitIf: bCondition=%d  TimeoutSeconds=%d  TimeoutNanoSeconds=%d\n",bCondition, TimeoutSeconds, TimeoutNanoSeconds));      dmsg(7,("Condition::WaitIf: bCondition=%d  TimeoutSeconds=%d  TimeoutNanoSeconds=%d\n",bCondition, TimeoutSeconds, TimeoutNanoSeconds));
284      dmsg(7,("Condition::Waitif() -> LOCK()\n"));      dmsg(7,("Condition::Waitif() -> LOCK()\n"));
285      Lock();      Lock();
286      dmsg(7,("Condition::Waitif() -> LOCK() passed\n"));      dmsg(7,("Condition::Waitif() -> LOCK() passed\n"));
287      int res = 0;      int res = 0;
288        #ifndef WIN32
289        pthread_cleanup_push(condition_cleanup, this);
290        #endif
291      if (this->bCondition == bCondition) {      if (this->bCondition == bCondition) {
292          if (bCondition) { // wait until condition turned 'false'          if (bCondition) { // wait until condition turned 'false'
293              #if defined(WIN32)              #if defined(WIN32)
# Line 328  int Condition::WaitIf(bool bCondition, l Line 342  int Condition::WaitIf(bool bCondition, l
342              #endif              #endif
343          }          }
344      }      }
345        #ifndef WIN32
346        pthread_cleanup_pop(0);
347        #endif
348      return res;      return res;
349  }  }
350    

Legend:
Removed from v.2323  
changed lines
  Added in v.2324

  ViewVC Help
Powered by ViewVC