From 1867a6c1ce015462db5038739e3d15b6b47e6a74 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 8 Oct 2015 16:24:10 +0200 Subject: [PATCH] src: replace QUEUE_SPLIT with QUEUE_MOVE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All uses of QUEUE_SPLIT in libuv split the list at the head so introduce a QUEUE_MOVE macro that automates that. PR-URL: https://github.com/libuv/libuv/pull/565 Reviewed-By: Fedor Indutny Reviewed-By: Saúl Ibarra Corretgé --- src/queue.h | 11 +++++++++++ src/threadpool.c | 7 +------ src/unix/core.c | 4 +--- src/unix/fsevents.c | 14 +++----------- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/queue.h b/src/queue.h index 60c80000..f942e13f 100644 --- a/src/queue.h +++ b/src/queue.h @@ -66,6 +66,17 @@ typedef void *QUEUE[2]; } \ while (0) +#define QUEUE_MOVE(h, n) \ + do { \ + if (QUEUE_EMPTY(h)) \ + QUEUE_INIT(n); \ + else { \ + QUEUE* q = QUEUE_HEAD(h); \ + QUEUE_SPLIT(h, q, n); \ + } \ + } \ + while (0) + #define QUEUE_INSERT_HEAD(h, q) \ do { \ QUEUE_NEXT(q) = QUEUE_NEXT(h); \ diff --git a/src/threadpool.c b/src/threadpool.c index 15d71994..2c5152b4 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -223,13 +223,8 @@ void uv__work_done(uv_async_t* handle) { int err; loop = container_of(handle, uv_loop_t, wq_async); - QUEUE_INIT(&wq); - uv_mutex_lock(&loop->wq_mutex); - if (!QUEUE_EMPTY(&loop->wq)) { - q = QUEUE_HEAD(&loop->wq); - QUEUE_SPLIT(&loop->wq, q, &wq); - } + QUEUE_MOVE(&loop->wq, &wq); uv_mutex_unlock(&loop->wq_mutex); while (!QUEUE_EMPTY(&wq)) { diff --git a/src/unix/core.c b/src/unix/core.c index e149357e..48dbfd0a 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -721,9 +721,7 @@ static int uv__run_pending(uv_loop_t* loop) { if (QUEUE_EMPTY(&loop->pending_queue)) return 0; - QUEUE_INIT(&pq); - q = QUEUE_HEAD(&loop->pending_queue); - QUEUE_SPLIT(&loop->pending_queue, q, &pq); + QUEUE_MOVE(&loop->pending_queue, &pq); while (!QUEUE_EMPTY(&pq)) { q = QUEUE_HEAD(&pq); diff --git a/src/unix/fsevents.c b/src/unix/fsevents.c index 8143f7c1..8f582c41 100644 --- a/src/unix/fsevents.c +++ b/src/unix/fsevents.c @@ -149,11 +149,7 @@ static void (*pFSEventStreamStop)(FSEventStreamRef); int err; \ uv_mutex_lock(&(handle)->cf_mutex); \ /* Split-off all events and empty original queue */ \ - QUEUE_INIT(&events); \ - if (!QUEUE_EMPTY(&(handle)->cf_events)) { \ - q = QUEUE_HEAD(&(handle)->cf_events); \ - QUEUE_SPLIT(&(handle)->cf_events, q, &events); \ - } \ + QUEUE_MOVE(&(handle)->cf_events, &events); \ /* Get error (if any) and zero original one */ \ err = (handle)->cf_error; \ (handle)->cf_error = 0; \ @@ -735,17 +731,14 @@ static void uv__cf_loop_cb(void* arg) { loop = arg; state = loop->cf_state; - QUEUE_INIT(&split_head); uv_mutex_lock(&loop->cf_mutex); - if (!QUEUE_EMPTY(&loop->cf_signals)) { - QUEUE* split_pos = QUEUE_HEAD(&loop->cf_signals); - QUEUE_SPLIT(&loop->cf_signals, split_pos, &split_head); - } + QUEUE_MOVE(&loop->cf_signals, &split_head); uv_mutex_unlock(&loop->cf_mutex); while (!QUEUE_EMPTY(&split_head)) { item = QUEUE_HEAD(&split_head); + QUEUE_REMOVE(item); s = QUEUE_DATA(item, uv__cf_loop_signal_t, member); @@ -755,7 +748,6 @@ static void uv__cf_loop_cb(void* arg) { else uv__fsevents_reschedule(s->handle); - QUEUE_REMOVE(item); uv__free(s); } }