Lines Matching refs:tp

25     ThreadPool *tp = (ThreadPool *) context;  in ThreadPool_start()  local
26 assert(NULL != tp); in ThreadPool_start()
28 Closure *pClosure = ThreadPool_remove(tp); in ThreadPool_start()
81 static void ThreadPool_deinit_internal(ThreadPool *tp, unsigned initialized, unsigned nThreads);
87 SLresult ThreadPool_init(ThreadPool *tp, unsigned maxClosures, unsigned maxThreads) in ThreadPool_init() argument
89 assert(NULL != tp); in ThreadPool_init()
90 memset(tp, 0, sizeof(ThreadPool)); in ThreadPool_init()
91 tp->mShutdown = SL_BOOLEAN_FALSE; in ThreadPool_init()
98 err = pthread_mutex_init(&tp->mMutex, (const pthread_mutexattr_t *) NULL); in ThreadPool_init()
103 err = pthread_cond_init(&tp->mCondNotFull, (const pthread_condattr_t *) NULL); in ThreadPool_init()
108 err = pthread_cond_init(&tp->mCondNotEmpty, (const pthread_condattr_t *) NULL); in ThreadPool_init()
115 tp->mWaitingNotFull = 0; in ThreadPool_init()
116 tp->mWaitingNotEmpty = 0; in ThreadPool_init()
119 tp->mMaxClosures = maxClosures; in ThreadPool_init()
122 tp->mMaxThreads = maxThreads; in ThreadPool_init()
126 tp->mClosureArray = tp->mClosureTypical; in ThreadPool_init()
128 tp->mClosureArray = (Closure **) malloc((maxClosures + 1) * sizeof(Closure *)); in ThreadPool_init()
129 if (NULL == tp->mClosureArray) { in ThreadPool_init()
134 tp->mClosureFront = tp->mClosureArray; in ThreadPool_init()
135 tp->mClosureRear = tp->mClosureArray; in ThreadPool_init()
139 tp->mThreadArray = tp->mThreadTypical; in ThreadPool_init()
141 tp->mThreadArray = (pthread_t *) malloc(maxThreads * sizeof(pthread_t)); in ThreadPool_init()
142 if (NULL == tp->mThreadArray) { in ThreadPool_init()
149 int err = pthread_create(&tp->mThreadArray[i], (const pthread_attr_t *) NULL, in ThreadPool_init()
150 ThreadPool_start, tp); in ThreadPool_init()
156 tp->mInitialized = initialized; in ThreadPool_init()
163 ThreadPool_deinit_internal(tp, initialized, nThreads); in ThreadPool_init()
167 static void ThreadPool_deinit_internal(ThreadPool *tp, unsigned initialized, unsigned nThreads) in ThreadPool_deinit_internal() argument
171 assert(NULL != tp); in ThreadPool_deinit_internal()
175 ok = pthread_mutex_lock(&tp->mMutex); in ThreadPool_deinit_internal()
177 tp->mShutdown = SL_BOOLEAN_TRUE; in ThreadPool_deinit_internal()
178 ok = pthread_cond_broadcast(&tp->mCondNotEmpty); in ThreadPool_deinit_internal()
180 ok = pthread_cond_broadcast(&tp->mCondNotFull); in ThreadPool_deinit_internal()
182 ok = pthread_mutex_unlock(&tp->mMutex); in ThreadPool_deinit_internal()
186 ok = pthread_join(tp->mThreadArray[i], (void **) NULL); in ThreadPool_deinit_internal()
191 ok = pthread_mutex_lock(&tp->mMutex); in ThreadPool_deinit_internal()
193 Closure **oldFront = tp->mClosureFront; in ThreadPool_deinit_internal()
194 while (oldFront != tp->mClosureRear) { in ThreadPool_deinit_internal()
196 if (++newFront == &tp->mClosureArray[tp->mMaxClosures + 1]) in ThreadPool_deinit_internal()
197 newFront = tp->mClosureArray; in ThreadPool_deinit_internal()
201 tp->mClosureFront = newFront; in ThreadPool_deinit_internal()
202 ok = pthread_mutex_unlock(&tp->mMutex); in ThreadPool_deinit_internal()
205 ok = pthread_mutex_lock(&tp->mMutex); in ThreadPool_deinit_internal()
208 ok = pthread_mutex_unlock(&tp->mMutex); in ThreadPool_deinit_internal()
215 ok = pthread_cond_destroy(&tp->mCondNotEmpty); in ThreadPool_deinit_internal()
219 ok = pthread_cond_destroy(&tp->mCondNotFull); in ThreadPool_deinit_internal()
223 ok = pthread_mutex_destroy(&tp->mMutex); in ThreadPool_deinit_internal()
226 tp->mInitialized = INITIALIZED_NONE; in ThreadPool_deinit_internal()
229 if (tp->mClosureTypical != tp->mClosureArray && NULL != tp->mClosureArray) { in ThreadPool_deinit_internal()
230 free(tp->mClosureArray); in ThreadPool_deinit_internal()
231 tp->mClosureArray = NULL; in ThreadPool_deinit_internal()
235 if (tp->mThreadTypical != tp->mThreadArray && NULL != tp->mThreadArray) { in ThreadPool_deinit_internal()
236 free(tp->mThreadArray); in ThreadPool_deinit_internal()
237 tp->mThreadArray = NULL; in ThreadPool_deinit_internal()
242 void ThreadPool_deinit(ThreadPool *tp) in ThreadPool_deinit() argument
244 ThreadPool_deinit_internal(tp, tp->mInitialized, tp->mMaxThreads); in ThreadPool_deinit()
250 SLresult ThreadPool_add(ThreadPool *tp, ClosureKind kind, ClosureHandler_generic handler, in ThreadPool_add() argument
253 assert(NULL != tp); in ThreadPool_add()
280 ok = pthread_mutex_lock(&tp->mMutex); in ThreadPool_add()
283 if (tp->mShutdown) { in ThreadPool_add()
284 ok = pthread_mutex_unlock(&tp->mMutex); in ThreadPool_add()
290 Closure **oldRear = tp->mClosureRear; in ThreadPool_add()
292 if (++newRear == &tp->mClosureArray[tp->mMaxClosures + 1]) in ThreadPool_add()
293 newRear = tp->mClosureArray; in ThreadPool_add()
295 if (newRear == tp->mClosureFront) { in ThreadPool_add()
296 ++tp->mWaitingNotFull; in ThreadPool_add()
297 ok = pthread_cond_wait(&tp->mCondNotFull, &tp->mMutex); in ThreadPool_add()
300 if (tp->mShutdown) { in ThreadPool_add()
301 assert(0 < tp->mWaitingNotFull); in ThreadPool_add()
302 --tp->mWaitingNotFull; in ThreadPool_add()
303 ok = pthread_mutex_unlock(&tp->mMutex); in ThreadPool_add()
312 tp->mClosureRear = newRear; in ThreadPool_add()
314 if (0 < tp->mWaitingNotEmpty) { in ThreadPool_add()
315 --tp->mWaitingNotEmpty; in ThreadPool_add()
316 ok = pthread_cond_signal(&tp->mCondNotEmpty); in ThreadPool_add()
321 ok = pthread_mutex_unlock(&tp->mMutex); in ThreadPool_add()
327 Closure *ThreadPool_remove(ThreadPool *tp) in ThreadPool_remove() argument
331 ok = pthread_mutex_lock(&tp->mMutex); in ThreadPool_remove()
335 if (tp->mShutdown) { in ThreadPool_remove()
339 Closure **oldFront = tp->mClosureFront; in ThreadPool_remove()
341 if (oldFront == tp->mClosureRear) { in ThreadPool_remove()
342 ++tp->mWaitingNotEmpty; in ThreadPool_remove()
343 ok = pthread_cond_wait(&tp->mCondNotEmpty, &tp->mMutex); in ThreadPool_remove()
350 if (++newFront == &tp->mClosureArray[tp->mMaxClosures + 1]) { in ThreadPool_remove()
351 newFront = tp->mClosureArray; in ThreadPool_remove()
356 tp->mClosureFront = newFront; in ThreadPool_remove()
358 if (0 < tp->mWaitingNotFull) { in ThreadPool_remove()
359 --tp->mWaitingNotFull; in ThreadPool_remove()
360 ok = pthread_cond_signal(&tp->mCondNotFull); in ThreadPool_remove()
365 ok = pthread_mutex_unlock(&tp->mMutex); in ThreadPool_remove()
371 SLresult ThreadPool_add_ppi(ThreadPool *tp, ClosureHandler_ppi handler, in ThreadPool_add_ppi() argument
375 return ThreadPool_add(tp, CLOSURE_KIND_PPI, (ClosureHandler_generic) handler, in ThreadPool_add_ppi()
379 SLresult ThreadPool_add_ppii(ThreadPool *tp, ClosureHandler_ppii handler, in ThreadPool_add_ppii() argument
383 return ThreadPool_add(tp, CLOSURE_KIND_PPII, (ClosureHandler_generic) handler, in ThreadPool_add_ppii()
387 SLresult ThreadPool_add_piipp(ThreadPool *tp, ClosureHandler_piipp handler, in ThreadPool_add_piipp() argument
391 return ThreadPool_add(tp, CLOSURE_KIND_PIIPP, (ClosureHandler_generic) handler, in ThreadPool_add_piipp()