Lines Matching refs:p_thread_pool
58 cl_thread_pool_t *p_thread_pool = (cl_thread_pool_t *) context; in thread_pool_routine() local
61 pthread_mutex_lock(&p_thread_pool->mutex); in thread_pool_routine()
62 pthread_cleanup_push(cleanup_mutex, p_thread_pool); in thread_pool_routine()
63 while (!p_thread_pool->events) in thread_pool_routine()
64 pthread_cond_wait(&p_thread_pool->cond, in thread_pool_routine()
65 &p_thread_pool->mutex); in thread_pool_routine()
66 p_thread_pool->events--; in thread_pool_routine()
69 (*p_thread_pool->pfn_callback) (p_thread_pool->context); in thread_pool_routine()
75 cl_status_t cl_thread_pool_init(IN cl_thread_pool_t * const p_thread_pool, in cl_thread_pool_init() argument
82 CL_ASSERT(p_thread_pool); in cl_thread_pool_init()
85 memset(p_thread_pool, 0, sizeof(*p_thread_pool)); in cl_thread_pool_init()
90 pthread_mutex_init(&p_thread_pool->mutex, NULL); in cl_thread_pool_init()
91 pthread_cond_init(&p_thread_pool->cond, NULL); in cl_thread_pool_init()
93 p_thread_pool->events = 0; in cl_thread_pool_init()
95 p_thread_pool->pfn_callback = pfn_callback; in cl_thread_pool_init()
96 p_thread_pool->context = context; in cl_thread_pool_init()
98 p_thread_pool->tid = calloc(count, sizeof(*p_thread_pool->tid)); in cl_thread_pool_init()
99 if (!p_thread_pool->tid) { in cl_thread_pool_init()
100 cl_thread_pool_destroy(p_thread_pool); in cl_thread_pool_init()
104 p_thread_pool->running_count = count; in cl_thread_pool_init()
107 if (pthread_create(&p_thread_pool->tid[i], NULL, in cl_thread_pool_init()
108 thread_pool_routine, p_thread_pool) != 0) { in cl_thread_pool_init()
109 cl_thread_pool_destroy(p_thread_pool); in cl_thread_pool_init()
117 void cl_thread_pool_destroy(IN cl_thread_pool_t * const p_thread_pool) in cl_thread_pool_destroy() argument
121 CL_ASSERT(p_thread_pool); in cl_thread_pool_destroy()
123 for (i = 0; i < p_thread_pool->running_count; i++) in cl_thread_pool_destroy()
124 if (p_thread_pool->tid[i]) in cl_thread_pool_destroy()
125 pthread_cancel(p_thread_pool->tid[i]); in cl_thread_pool_destroy()
127 for (i = 0; i < p_thread_pool->running_count; i++) in cl_thread_pool_destroy()
128 if (p_thread_pool->tid[i]) in cl_thread_pool_destroy()
129 pthread_join(p_thread_pool->tid[i], NULL); in cl_thread_pool_destroy()
131 p_thread_pool->running_count = 0; in cl_thread_pool_destroy()
133 free(p_thread_pool->tid); in cl_thread_pool_destroy()
135 pthread_cond_destroy(&p_thread_pool->cond); in cl_thread_pool_destroy()
136 pthread_mutex_destroy(&p_thread_pool->mutex); in cl_thread_pool_destroy()
138 p_thread_pool->events = 0; in cl_thread_pool_destroy()
141 cl_status_t cl_thread_pool_signal(IN cl_thread_pool_t * const p_thread_pool) in cl_thread_pool_signal() argument
144 CL_ASSERT(p_thread_pool); in cl_thread_pool_signal()
145 pthread_mutex_lock(&p_thread_pool->mutex); in cl_thread_pool_signal()
146 p_thread_pool->events++; in cl_thread_pool_signal()
147 ret = pthread_cond_signal(&p_thread_pool->cond); in cl_thread_pool_signal()
148 pthread_mutex_unlock(&p_thread_pool->mutex); in cl_thread_pool_signal()