1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright Chris Cannam, used with permission.
20 #error Must have either _WIN32 or USE_PTHREADS defined
21 #endif /* USE_PTHREADS */
26 //#define DEBUG_THREAD 1
27 //#define DEBUG_MUTEX 1
28 //#define DEBUG_CONDITION 1
49 static bool threadingAvailable();
52 virtual void run() = 0;
58 static DWORD WINAPI staticRun(LPVOID lpParam);
63 static void *staticRun(void *);
81 #ifndef NO_THREAD_CHECKS
86 pthread_mutex_t m_mutex;
87 #ifndef NO_THREAD_CHECKS
108 Condition(std::string name);
111 // Condition bundles a pthread-style condition variable and mutex
114 // To wait on a condition, call lock(), test termination variables
115 // as appropriate, and then wait(). The condition will be
116 // unlocked for the duration of the wait() call, which will end
117 // when the condition is signalled. The condition will be locked
118 // again when wait() returns.
120 // To signal a condition, call signal(). If the waiting thread
121 // will be performing tests between its own lock() and wait(),
122 // then the signalling thread should also lock() before it signals
123 // (and then unlock afterwards). If the signalling thread always
124 // locks the mutex during signalling, then the waiting thread
125 // knows that signals will only happen during wait() and not be
126 // missed at other times.
130 void wait(int us = 0);
142 pthread_mutex_t m_mutex;
143 pthread_cond_t m_condition;
147 #ifdef DEBUG_CONDITION