• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src/router/samba-3.5.8/source3/lib/

Lines Matching refs:pool

3  * thread pool implementation
89 * Initialize a thread pool
94 struct pthreadpool *pool;
100 pool = (struct pthreadpool *)malloc(size);
101 if (pool == NULL) {
105 ret = pthread_mutex_init(&pool->mutex, NULL);
107 free(pool);
111 ret = pthread_cond_init(&pool->condvar, NULL);
113 pthread_mutex_destroy(&pool->mutex);
114 free(pool);
118 pool->shutdown = 0;
119 pool->jobs = pool->last_job = NULL;
120 pool->num_threads = 0;
121 pool->num_exited = 0;
122 pool->max_threads = max_threads;
123 pool->num_idle = 0;
124 pool->sig_pipe[0] = -1;
125 pool->sig_pipe[1] = -1;
127 *presult = pool;
136 int pthreadpool_sig_fd(struct pthreadpool *pool)
140 ret = pthread_mutex_lock(&pool->mutex);
146 if (pool->sig_pipe[0] != -1) {
147 result = pool->sig_pipe[0];
151 ret = pipe(pool->sig_pipe);
157 result = pool->sig_pipe[0];
159 ret = pthread_mutex_unlock(&pool->mutex);
165 * Do a pthread_join() on all children that have exited, pool->mutex must be
168 static void pthreadpool_join_children(struct pthreadpool *pool)
172 for (i=0; i<pool->num_exited; i++) {
173 pthread_join(pool->exited[i], NULL);
175 pool->num_exited = 0;
182 int pthreadpool_finished_job(struct pthreadpool *pool)
187 ret = pthread_mutex_lock(&pool->mutex);
196 pthreadpool_join_children(pool);
198 fd = pool->sig_pipe[0];
200 ret = pthread_mutex_unlock(&pool->mutex);
228 ret = pthread_mutex_lock(&pool->mutex);
234 ret = pthread_mutex_unlock(&pool->mutex);
241 * Destroy a thread pool, finishing all threads working for it
244 int pthreadpool_destroy(struct pthreadpool *pool)
248 ret = pthread_mutex_lock(&pool->mutex);
253 if (pool->num_threads > 0) {
258 pool->shutdown = 1;
260 if (pool->num_idle > 0) {
262 * Wake the idle threads. They will find pool->quit to
265 ret = pthread_cond_broadcast(&pool->condvar);
267 pthread_mutex_unlock(&pool->mutex);
272 while ((pool->num_threads > 0) || (pool->num_exited > 0)) {
274 if (pool->num_exited > 0) {
275 pthreadpool_join_children(pool);
280 * pool->condvar
282 ret = pthread_cond_wait(&pool->condvar, &pool->mutex);
284 pthread_mutex_unlock(&pool->mutex);
290 ret = pthread_mutex_unlock(&pool->mutex);
294 ret = pthread_mutex_destroy(&pool->mutex);
295 ret1 = pthread_cond_destroy(&pool->condvar);
298 free(pool);
308 * Prepare for pthread_exit(), pool->mutex must be locked
310 static void pthreadpool_server_exit(struct pthreadpool *pool)
312 pool->num_threads -= 1;
313 pool->exited[pool->num_exited] = pthread_self();
314 pool->num_exited += 1;
319 struct pthreadpool *pool = (struct pthreadpool *)arg;
322 res = pthread_mutex_lock(&pool->mutex);
339 while ((pool->jobs == NULL) && (pool->shutdown == 0)) {
341 pool->num_idle += 1;
343 &pool->condvar, &pool->mutex, &timeout);
344 pool->num_idle -= 1;
348 if (pool->jobs == NULL) {
353 pthreadpool_server_exit(pool);
354 pthread_mutex_unlock(&pool->mutex);
363 job = pool->jobs;
366 int fd = pool->sig_pipe[1];
373 pool->jobs = job->next;
374 if (pool->last_job == job) {
375 pool->last_job = NULL;
382 res = pthread_mutex_unlock(&pool->mutex);
389 res = pthread_mutex_lock(&pool->mutex);
399 pthreadpool_server_exit(pool);
400 pthread_mutex_unlock(&pool->mutex);
405 if ((pool->jobs == NULL) && (pool->shutdown != 0)) {
410 pthreadpool_server_exit(pool);
412 if (pool->num_threads == 0) {
417 pthread_cond_broadcast(&pool->condvar);
420 pthread_mutex_unlock(&pool->mutex);
426 int pthreadpool_add_job(struct pthreadpool *pool, int job_id,
444 res = pthread_mutex_lock(&pool->mutex);
453 pthreadpool_join_children(pool);
458 if (pool->jobs == NULL) {
459 pool->jobs = job;
462 pool->last_job->next = job;
464 pool->last_job = job;
466 if (pool->num_idle > 0) {
470 res = pthread_cond_signal(&pool->condvar);
471 pthread_mutex_unlock(&pool->mutex);
475 if (pool->num_threads >= pool->max_threads) {
479 pthread_mutex_unlock(&pool->mutex);
491 pthread_mutex_unlock(&pool->mutex);
496 (void *)pool);
498 pool->num_threads += 1;
503 pthread_mutex_unlock(&pool->mutex);