win,async: queue the async wakeup req only once

The refactoring in #980 changed to having only one instance of the async
req (like on Unix), so like on Unix, we also need to drain the queue of
all pending messages when we make the callback pending.

Fixes: https://github.com/libuv/libuv/pull/1951
PR-URL: https://github.com/libuv/libuv/pull/1960
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit is contained in:
Spencer Russell 2018-08-27 15:59:23 -04:00 committed by Jameson Nash
parent c39e0217aa
commit 16910d23a3
6 changed files with 102 additions and 0 deletions

View File

@ -40,6 +40,7 @@ set(uv_test_sources
test/test-active.c
test/test-async-null-cb.c
test/test-async.c
test/test-async-multi.c
test/test-barrier.c
test/test-buf.c
test/test-callback-order.c

View File

@ -155,6 +155,7 @@ test_run_tests_SOURCES = test/blackhole-server.c \
test/task.h \
test/test-active.c \
test/test-async.c \
test/test-async-multi.c \
test/test-async-null-cb.c \
test/test-barrier.c \
test/test-buf.c \

View File

@ -308,6 +308,7 @@ static void uv__poll(uv_loop_t* loop, int timeout) {
ULONG i;
int repeat;
uint64_t timeout_time;
BOOL gotwakeup = FALSE;
timeout_time = loop->time + timeout;
@ -326,6 +327,16 @@ static void uv__poll(uv_loop_t* loop, int timeout) {
*/
if (overlappeds[i].lpOverlapped) {
req = container_of(overlappeds[i].lpOverlapped, uv_req_t, u.io.overlapped);
/* If multiple async handles were triggered we might end up with
* multiple UV_WAKEUP requests (IOCP completion events). They all
* share the same req however, so we need to be careful to only make
* it pending once.
*/
if (req->type == UV_WAKEUP) {
if (gotwakeup)
continue;
gotwakeup = TRUE;
}
uv_insert_pending_req(loop, req);
}
}

86
test/test-async-multi.c Normal file
View File

@ -0,0 +1,86 @@
/* Copyright libuv project contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "uv.h"
#include "task.h"
#include <stdio.h>
#include <stdlib.h>
static uv_pipe_t pipe_dummy;
static uv_connect_t connect_req;
static uv_prepare_t prepare;
static int async_cb_called;
static int close_cb_called;
void close_cb(uv_handle_t* handle) {
close_cb_called++;
}
void connect_cb(uv_connect_t* req, int status) {
ASSERT(status == UV_ENOENT);
uv_close((uv_handle_t*) req->handle, close_cb);
}
void async_cb(uv_async_t* handle) {
async_cb_called++;
uv_close((uv_handle_t*) handle, close_cb);
}
void prepare_cb(uv_prepare_t* handle) {
uv_pipe_connect(&connect_req,
&pipe_dummy,
"nonexistent_file_path",
connect_cb);
uv_close((uv_handle_t*) handle, close_cb);
}
TEST_IMPL(async_multi) {
uv_loop_t* loop;
uv_async_t async1;
uv_async_t async2;
loop = uv_default_loop();
ASSERT(0 == uv_async_init(loop, &async1, async_cb));
ASSERT(0 == uv_async_init(loop, &async2, async_cb));
/* Create a pending notification */
ASSERT(0 == uv_pipe_init(loop, &pipe_dummy, 0));
ASSERT(0 == uv_prepare_init(loop, &prepare));
ASSERT(0 == uv_prepare_start(&prepare, prepare_cb));
ASSERT(0 == uv_async_send(&async1));
ASSERT(0 == uv_async_send(&async2));
uv_run(loop, UV_RUN_DEFAULT);
ASSERT(async_cb_called == 2);
ASSERT(close_cb_called == 4);
MAKE_VALGRIND_HAPPY();
return 0;
}

View File

@ -248,6 +248,7 @@ TEST_DECLARE (has_ref)
TEST_DECLARE (active)
TEST_DECLARE (embed)
TEST_DECLARE (async)
TEST_DECLARE (async_multi)
TEST_DECLARE (async_null_cb)
TEST_DECLARE (eintr_handling)
TEST_DECLARE (get_currentexe)
@ -808,6 +809,7 @@ TASK_LIST_START
TEST_ENTRY (embed)
TEST_ENTRY (async)
TEST_ENTRY (async_multi)
TEST_ENTRY (async_null_cb)
TEST_ENTRY (eintr_handling)

View File

@ -14,6 +14,7 @@
'task.h',
'test-active.c',
'test-async.c',
'test-async-multi.c',
'test-async-null-cb.c',
'test-callback-stack.c',
'test-callback-order.c',