typedef struct {
- ngx_thread_mutex_t mtx;
ngx_thread_task_t *first;
ngx_thread_task_t **last;
} ngx_thread_pool_queue_t;
+#define ngx_thread_pool_queue_init(q) \
+ (q)->first = NULL; \
+ (q)->last = &(q)->first
+
struct ngx_thread_pool_s {
+ ngx_thread_mutex_t mtx;
ngx_thread_pool_queue_t queue;
ngx_int_t waiting;
ngx_thread_cond_t cond;
static ngx_int_t ngx_thread_pool_init(ngx_thread_pool_t *tp, ngx_log_t *log,
ngx_pool_t *pool);
-static ngx_int_t ngx_thread_pool_queue_init(ngx_thread_pool_queue_t *queue,
- ngx_log_t *log);
-static ngx_int_t ngx_thread_pool_queue_destroy(ngx_thread_pool_queue_t *queue,
- ngx_log_t *log);
static void ngx_thread_pool_destroy(ngx_thread_pool_t *tp);
static void *ngx_thread_pool_cycle(void *data);
return NGX_ERROR;
}
- if (ngx_thread_pool_queue_init(&tp->queue, log) != NGX_OK) {
+ ngx_thread_pool_queue_init(&tp->queue);
+
+ if (ngx_thread_mutex_create(&tp->mtx, log) != NGX_OK) {
return NGX_ERROR;
}
if (ngx_thread_cond_create(&tp->cond, log) != NGX_OK) {
- (void) ngx_thread_pool_queue_destroy(&tp->queue, log);
+ (void) ngx_thread_mutex_destroy(&tp->mtx, log);
return NGX_ERROR;
}
}
-static ngx_int_t
-ngx_thread_pool_queue_init(ngx_thread_pool_queue_t *queue, ngx_log_t *log)
-{
- queue->first = NULL;
- queue->last = &queue->first;
-
- return ngx_thread_mutex_create(&queue->mtx, log);
-}
-
-
-static ngx_int_t
-ngx_thread_pool_queue_destroy(ngx_thread_pool_queue_t *queue, ngx_log_t *log)
-{
-#if 0
- return ngx_thread_mutex_destroy(&queue->mtx, log);
-#else
- return NGX_OK;
-#endif
-}
-
-
static void
ngx_thread_pool_destroy(ngx_thread_pool_t *tp)
{
#if 0
(void) ngx_thread_cond_destroy(&tp->cond, tp->log);
-#endif
- (void) ngx_thread_pool_queue_destroy(&tp->queue, tp->log);
+ (void) ngx_thread_mutex_destroy(&tp->mtx, tp->log);
+ #endif
}
return NGX_ERROR;
}
- if (ngx_thread_mutex_lock(&tp->queue.mtx, tp->log) != NGX_OK) {
+ if (ngx_thread_mutex_lock(&tp->mtx, tp->log) != NGX_OK) {
return NGX_ERROR;
}
if (tp->waiting >= tp->max_queue) {
- (void) ngx_thread_mutex_unlock(&tp->queue.mtx, tp->log);
+ (void) ngx_thread_mutex_unlock(&tp->mtx, tp->log);
ngx_log_error(NGX_LOG_ERR, tp->log, 0,
"thread pool \"%V\" queue overflow: %i tasks waiting",
task->next = NULL;
if (ngx_thread_cond_signal(&tp->cond, tp->log) != NGX_OK) {
- (void) ngx_thread_mutex_unlock(&tp->queue.mtx, tp->log);
+ (void) ngx_thread_mutex_unlock(&tp->mtx, tp->log);
return NGX_ERROR;
}
tp->waiting++;
- (void) ngx_thread_mutex_unlock(&tp->queue.mtx, tp->log);
+ (void) ngx_thread_mutex_unlock(&tp->mtx, tp->log);
ngx_log_debug2(NGX_LOG_DEBUG_CORE, tp->log, 0,
"task #%ui added to thread pool \"%V\"",
}
for ( ;; ) {
- if (ngx_thread_mutex_lock(&tp->queue.mtx, tp->log) != NGX_OK) {
+ if (ngx_thread_mutex_lock(&tp->mtx, tp->log) != NGX_OK) {
return NULL;
}
tp->waiting--;
while (tp->queue.first == NULL) {
- if (ngx_thread_cond_wait(&tp->cond, &tp->queue.mtx, tp->log)
+ if (ngx_thread_cond_wait(&tp->cond, &tp->mtx, tp->log)
!= NGX_OK)
{
- (void) ngx_thread_mutex_unlock(&tp->queue.mtx, tp->log);
+ (void) ngx_thread_mutex_unlock(&tp->mtx, tp->log);
return NULL;
}
}
tp->queue.last = &tp->queue.first;
}
- if (ngx_thread_mutex_unlock(&tp->queue.mtx, tp->log) != NGX_OK) {
+ if (ngx_thread_mutex_unlock(&tp->mtx, tp->log) != NGX_OK) {
return NULL;
}
return NGX_OK;
}
- if (ngx_thread_pool_queue_init(&ngx_thread_pool_done, cycle->log)
- != NGX_OK)
- {
- return NGX_ERROR;
- }
+ ngx_thread_pool_queue_init(&ngx_thread_pool_done);
tpp = tcf->pools.elts;
for (i = 0; i < tcf->pools.nelts; i++) {
ngx_thread_pool_destroy(tpp[i]);
}
-
- (void) ngx_thread_pool_queue_destroy(&ngx_thread_pool_done, cycle->log);
}