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.
18 #endif /* USE_PTHREADS */
23 //#define DEBUG_THREAD 1
24 //#define DEBUG_MUTEX 1
25 //#define DEBUG_CONDITION 1
46 static bool threadingAvailable();
49 virtual void run() = 0;
55 static DWORD WINAPI staticRun(LPVOID lpParam);
60 static void *staticRun(void *);
78 #ifndef NO_THREAD_CHECKS
83 pthread_mutex_t m_mutex;
84 #ifndef NO_THREAD_CHECKS
105 Condition(std::string name);
108 // Condition bundles a pthread-style condition variable and mutex
111 // To wait on a condition, call lock(), test termination variables
112 // as appropriate, and then wait(). The condition will be
113 // unlocked for the duration of the wait() call, which will end
114 // when the condition is signalled. The condition will be locked
115 // again when wait() returns.
117 // To signal a condition, call signal(). If the waiting thread
118 // will be performing tests between its own lock() and wait(),
119 // then the signalling thread should also lock() before it signals
120 // (and then unlock afterwards). If the signalling thread always
121 // locks the mutex during signalling, then the waiting thread
122 // knows that signals will only happen during wait() and not be
123 // missed at other times.
127 void wait(int us = 0);
139 pthread_mutex_t m_mutex;
140 pthread_cond_t m_condition;
144 #ifdef DEBUG_CONDITION