20 #include <znc/zncconfig.h>
39 friend class CConditionVariable;
42 int i = pthread_mutex_init(&m_mutex, NULL);
50 int i = pthread_mutex_destroy(&m_mutex);
58 int i = pthread_mutex_lock(&m_mutex);
66 int i = pthread_mutex_unlock(&m_mutex);
74 pthread_mutex_t m_mutex;
84 CMutexLocker(CMutex& mutex,
bool initiallyLocked =
true)
85 : m_mutex(mutex), m_locked(false) {
116 class CConditionVariable {
118 CConditionVariable() {
119 int i = pthread_cond_init(&m_cond, NULL);
127 ~CConditionVariable() {
128 int i = pthread_cond_destroy(&m_cond);
136 void wait(CMutex& mutex) {
137 int i = pthread_cond_wait(&m_cond, &mutex.m_mutex);
146 int i = pthread_cond_signal(&m_cond);
155 int i = pthread_cond_broadcast(&m_cond);
164 pthread_cond_t m_cond;
169 typedef void *threadRoutine(
void *);
170 static void startThread(threadRoutine *func,
void *arg) {
172 sigset_t old_sigmask, sigmask;
177 int i = sigfillset(&sigmask);
178 i |= pthread_sigmask(SIG_SETMASK, &sigmask, &old_sigmask);
179 i |= pthread_create(&thr, NULL, func, arg);
180 i |= pthread_sigmask(SIG_SETMASK, &old_sigmask, NULL);
181 i |= pthread_detach(thr);
193 virtual void runThread() = 0;
194 virtual void runMain() = 0;
203 static CThreadPool& Get();
205 void addJob(CJob *job);
207 int getReadFD()
const {
208 return m_iJobPipe[0];
211 void handlePipeReadable()
const;
214 void jobDone(
const CJob* pJob)
const;
217 bool threadNeeded()
const;
220 static void *threadPoolFunc(
void *arg) {
221 CThreadPool &pool = *
reinterpret_cast<CThreadPool *
>(arg);
230 CConditionVariable m_cond;
236 size_t m_num_threads;
245 std::list<CJob *> m_jobs;
248 #endif // HAVE_PTHREAD
249 #endif // !_THREADS_H
String class that is used inside ZNC.
Definition: ZNCString.h:67
static void PrintError(const CString &sMessage)