/[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 1560 by schoenebeck, Thu Dec 6 17:19:16 2007 UTC revision 2324 by persson, Sun Mar 4 09:01:32 2012 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005 - 2007 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2012 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 27  Line 27 
27    
28  #include "global_private.h"  #include "global_private.h"
29    
30    #if CONFIG_PTHREAD_TESTCANCEL
31    #include "Thread.h"
32    #endif
33    
34  namespace LinuxSampler {  namespace LinuxSampler {
35    
36  // *************** Internal data types (for Windows only) ***************  // *************** Internal data types (for Windows only) ***************
# Line 264  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 324  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    
# Line 344  void Condition::Set(bool bCondition) { Line 365  void Condition::Set(bool bCondition) {
365          if (bCondition) {          if (bCondition) {
366              dmsg(7,("Condition::Set() -> broadcasting 'true' condition\n"));              dmsg(7,("Condition::Set() -> broadcasting 'true' condition\n"));
367              #if defined(WIN32)              #if defined(WIN32)
368              win32thread_cond_broadcast(&__win32_true_condition);              ConditionInternal::win32thread_cond_broadcast(&__win32_true_condition);
369              #else              #else
370              pthread_cond_broadcast(&__posix_true_condition);              pthread_cond_broadcast(&__posix_true_condition);
371              #endif              #endif
# Line 352  void Condition::Set(bool bCondition) { Line 373  void Condition::Set(bool bCondition) {
373          else {          else {
374              dmsg(7,("Condition::Set() -> broadcasting 'false' condition\n"));              dmsg(7,("Condition::Set() -> broadcasting 'false' condition\n"));
375              #if defined(WIN32)              #if defined(WIN32)
376              win32thread_cond_broadcast(&__win32_false_condition);              ConditionInternal::win32thread_cond_broadcast(&__win32_false_condition);
377              #else              #else
378              pthread_cond_broadcast(&__posix_false_condition);              pthread_cond_broadcast(&__posix_false_condition);
379              #endif              #endif
# Line 365  bool Condition::GetUnsafe() { Line 386  bool Condition::GetUnsafe() {
386      return bCondition;      return bCondition;
387  }  }
388    
389    #ifdef WIN32
390    void Condition::Reset() {
391        __win32_true_condition.waiters_count_ = 0;
392        __win32_true_condition.was_broadcast_ = 0;
393        __win32_false_condition.waiters_count_ = 0;
394        __win32_false_condition.was_broadcast_ = 0;
395    }
396    #endif
397    
398  } // namespace LinuxSampler  } // namespace LinuxSampler

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

  ViewVC Help
Powered by ViewVC