diff --git a/include/uv-private/ngx-queue.h b/include/uv-private/ngx-queue.h index 3c3ed1b0..c47934d9 100644 --- a/include/uv-private/ngx-queue.h +++ b/include/uv-private/ngx-queue.h @@ -106,6 +106,17 @@ struct ngx_queue_s { while (0) +#define ngx_queue_move(h, n) \ + do { \ + if (ngx_queue_empty(h)) \ + ngx_queue_init(n); \ + else { \ + ngx_queue_t* q = ngx_queue_head(h); \ + ngx_queue_split(h, q, n); \ + } \ + } \ + while (0) + #define ngx_queue_add(h, n) \ do { \ (h)->prev->next = (n)->next; \ diff --git a/src/unix/darwin.c b/src/unix/darwin.c index f37d58df..c8c79dc7 100644 --- a/src/unix/darwin.c +++ b/src/unix/darwin.c @@ -133,15 +133,12 @@ static void uv__cf_loop_cb(void* arg) { loop = arg; uv_mutex_lock(&loop->cf_mutex); - ngx_queue_init(&split_head); - if (!ngx_queue_empty(&loop->cf_signals)) { - ngx_queue_t* split_pos = ngx_queue_next(&loop->cf_signals); - ngx_queue_split(&loop->cf_signals, split_pos, &split_head); - } + ngx_queue_move(&loop->cf_signals, &split_head); uv_mutex_unlock(&loop->cf_mutex); while (!ngx_queue_empty(&split_head)) { item = ngx_queue_head(&split_head); + ngx_queue_remove(item); s = ngx_queue_data(item, uv__cf_loop_signal_t, member); @@ -151,7 +148,6 @@ static void uv__cf_loop_cb(void* arg) { else s->cb(s->arg); - ngx_queue_remove(item); free(s); } } diff --git a/src/unix/fsevents.c b/src/unix/fsevents.c index d8603242..753705cf 100644 --- a/src/unix/fsevents.c +++ b/src/unix/fsevents.c @@ -55,11 +55,7 @@ struct uv__fsevents_event_s { ngx_queue_t split_head; \ uv__fsevents_event_t* event; \ uv_mutex_lock(&(handle)->cf_mutex); \ - ngx_queue_init(&split_head); \ - if (!ngx_queue_empty(&(handle)->cf_events)) { \ - ngx_queue_t* split_pos = ngx_queue_next(&(handle)->cf_events); \ - ngx_queue_split(&(handle)->cf_events, split_pos, &split_head); \ - } \ + ngx_queue_move(&(handle)->cf_events, &split_head); \ uv_mutex_unlock(&(handle)->cf_mutex); \ while (!ngx_queue_empty(&split_head)) { \ curr = ngx_queue_head(&split_head); \ diff --git a/src/unix/threadpool.c b/src/unix/threadpool.c index 6e5adc40..7bc847ff 100644 --- a/src/unix/threadpool.c +++ b/src/unix/threadpool.c @@ -202,13 +202,8 @@ void uv__work_done(uv_async_t* handle, int status) { int err; loop = container_of(handle, uv_loop_t, wq_async); - ngx_queue_init(&wq); - uv_mutex_lock(&loop->wq_mutex); - if (!ngx_queue_empty(&loop->wq)) { - q = ngx_queue_head(&loop->wq); - ngx_queue_split(&loop->wq, q, &wq); - } + ngx_queue_move(&loop->wq, &wq); uv_mutex_unlock(&loop->wq_mutex); while (!ngx_queue_empty(&wq)) {