diff --git a/CMakeLists.txt b/CMakeLists.txt index 64e40e96..ae891778 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/Makefile.am b/Makefile.am index 9f8c867e..472646a9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/src/win/core.c b/src/win/core.c index 00b6b0a3..d4c53da3 100644 --- a/src/win/core.c +++ b/src/win/core.c @@ -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); } } diff --git a/test/test-async-multi.c b/test/test-async-multi.c new file mode 100644 index 00000000..316d2190 --- /dev/null +++ b/test/test-async-multi.c @@ -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 +#include + +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; +} diff --git a/test/test-list.h b/test/test-list.h index f86a5d30..10cc7ef8 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -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) diff --git a/test/test.gyp b/test/test.gyp index 00f76b15..4f58c9de 100644 --- a/test/test.gyp +++ b/test/test.gyp @@ -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',