14 #define INITMUTEX(m) pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER
15 #define STATICINITMUTEX(m) static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER
16 #define MUTEXLOCK(m) pthread_mutex_lock (m)
17 #define MUTEXUNLOCK(m) pthread_mutex_unlock (m)
20 #define STATICINITMUTEX(m)
22 #define MUTEXUNLOCK(m)
31 void Task_Init (
int nth);
37 static int nProcessor();
40 static void SetThreadCount (
int _nthread) { nthread = _nthread; }
44 static int GetThreadCount () {
return nthread; }
47 static double GetThreadCPUTiming () {
return ttime; }
53 static double GetThreadWallTiming () {
return wtime; }
56 static void Multiprocess (
void (*func)(task_data*),
void *data,
int np = 0);
61 static bool IsMultiprocessing() {
return is_multiprocessing; }
63 inline static void UserMutex_lock() { pthread_mutex_lock (&user_mutex); }
64 inline static void UserMutex_unlock() {pthread_mutex_unlock (&user_mutex);}
70 static pthread_mutex_t user_mutex;
71 static bool is_multiprocessing;
77 typedef struct tpool_work {
78 void (*routine)(
void*,int,int);
83 struct tpool_work *next;
86 typedef struct tpool {
90 tpool_work_t *queue_head, *queue_tail;
92 pthread_mutex_t queue_lock;
93 pthread_cond_t queue_not_empty;
94 pthread_cond_t thread_done;
99 ThreadPool (
int num_threads);
102 void ProcessSequence (
void (*routine)(
void*,
int,
int),
void *arg,
103 int from,
int to,
int grain=1);
109 inline void LockUserMutex() { pthread_mutex_lock (&user_lock); }
110 inline void UnlockUserMutex() { pthread_mutex_unlock (&user_lock); }
114 pthread_mutex_t user_lock;
122 void(*task)(int,
void*);
124 pthread_mutex_t mutex;
130 pthread_mutex_t wakeup_mutex;
131 pthread_mutex_t done_mutex;
132 pthread_cond_t wakeup_cond;
133 pthread_cond_t done_cond;
141 ThreadPool2 (
int num_threads);
143 static void Initialise (
int num_threads);
144 static ThreadPool2 *Pool() {
return g_tpool2; }
146 void MutexLock() { pthread_mutex_lock (&tg.mutex); }
147 void MutexUnlock() { pthread_mutex_unlock (&tg.mutex); }
148 inline int NumThread()
const {
return nthread; }
150 void Invoke (
void(*func)(
int,
void*),
void *context);
156 static ThreadPool2 *g_tpool2;
158 static void *tpool_thread (
void *context);
163 void TPool_Init (
int nt);
164 extern ThreadPool *g_tpool;
168 #endif // TOAST_THREAD