src: replace ngx_queue_split with ngx_queue_move
All uses of ngx_queue_split in libuv split the list at the head so
introduce a ngx_queue_move macro that automates that.
This is a backport of commit 1867a6c from the v1.x branch.
PR-URL: https://github.com/libuv/libuv/pull/566
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
parent
cbc83c6d0c
commit
82f025e036
@ -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; \
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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); \
|
||||
|
||||
@ -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)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user