From: Daniel Lehman Subject: [PATCH 6/6] msvcp140_atomic_wait: Implement __std_bulk_submit_threadpool_work. Message-Id: Date: Wed, 26 Jan 2022 22:50:34 +0000 From 53df50bc7555bfff9252c979702e36991a66cf1b Mon Sep 17 00:00:00 2001 From: Daniel Lehman Date: Fri, 21 Jan 2022 16:41:22 -0800 Subject: [PATCH 6/6] msvcp140_atomic_wait: Implement __std_bulk_submit_threadpool_work. Signed-off-by: Daniel Lehman --- dlls/msvcp140_atomic_wait/main.c | 7 +++++ .../msvcp140_atomic_wait.spec | 2 +- .../tests/msvcp140_atomic_wait.c | 29 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/dlls/msvcp140_atomic_wait/main.c b/dlls/msvcp140_atomic_wait/main.c index c00ed08bffe..adf78589522 100644 --- a/dlls/msvcp140_atomic_wait/main.c +++ b/dlls/msvcp140_atomic_wait/main.c @@ -31,6 +31,13 @@ unsigned int __stdcall __std_parallel_algorithms_hw_threads(void) return _Thrd_hardware_concurrency(); } +void __stdcall __std_bulk_submit_threadpool_work(PTP_WORK work, size_t count) +{ + TRACE("(%p %u)\n", work, count); + while (count--) + SubmitThreadpoolWork(work); +} + void __stdcall __std_close_threadpool_work(PTP_WORK work) { TRACE("(%p)\n", work); diff --git a/dlls/msvcp140_atomic_wait/msvcp140_atomic_wait.spec b/dlls/msvcp140_atomic_wait/msvcp140_atomic_wait.spec index 5b03b7ccfe8..bb4edfb76e5 100644 --- a/dlls/msvcp140_atomic_wait/msvcp140_atomic_wait.spec +++ b/dlls/msvcp140_atomic_wait/msvcp140_atomic_wait.spec @@ -11,7 +11,7 @@ @ stub __std_atomic_wait_get_deadline @ stub __std_atomic_wait_get_remaining_timeout @ stub __std_atomic_wait_indirect -@ stub __std_bulk_submit_threadpool_work +@ stdcall __std_bulk_submit_threadpool_work(ptr long) @ stub __std_calloc_crt @ stdcall __std_close_threadpool_work(ptr) @ stdcall __std_create_threadpool_work(ptr ptr ptr) diff --git a/dlls/msvcp140_atomic_wait/tests/msvcp140_atomic_wait.c b/dlls/msvcp140_atomic_wait/tests/msvcp140_atomic_wait.c index f72135d36d3..351e6cfeb31 100644 --- a/dlls/msvcp140_atomic_wait/tests/msvcp140_atomic_wait.c +++ b/dlls/msvcp140_atomic_wait/tests/msvcp140_atomic_wait.c @@ -24,6 +24,7 @@ static unsigned int (__stdcall *p___std_parallel_algorithms_hw_threads)(void); +static void (__stdcall *p___std_bulk_submit_threadpool_work)(PTP_WORK, size_t); static void (__stdcall *p___std_close_threadpool_work)(PTP_WORK); static PTP_WORK (__stdcall *p___std_create_threadpool_work)(PTP_WORK_CALLBACK, void*, PTP_CALLBACK_ENVIRON); static void (__stdcall *p___std_submit_threadpool_work)(PTP_WORK); @@ -40,6 +41,7 @@ static HMODULE init(void) SET(p___std_parallel_algorithms_hw_threads, "__std_parallel_algorithms_hw_threads"); + SET(p___std_bulk_submit_threadpool_work, "__std_bulk_submit_threadpool_work"); SET(p___std_close_threadpool_work, "__std_close_threadpool_work"); SET(p___std_create_threadpool_work, "__std_create_threadpool_work"); SET(p___std_submit_threadpool_work, "__std_submit_threadpool_work"); @@ -86,6 +88,7 @@ static void test_threadpool_work(void) if (0) /* crash on windows */ { + p___std_bulk_submit_threadpool_work(NULL, 5); p___std_create_threadpool_work(NULL, NULL, NULL); p___std_submit_threadpool_work(NULL); p___std_wait_for_threadpool_work_callbacks(NULL, FALSE); @@ -103,6 +106,32 @@ static void test_threadpool_work(void) ok(cb_work == work, "expected %p, got %p\n", work, cb_work); ok(cb_context == &workcalled, "expected %p, got %p\n", &workcalled, cb_context); + /* bulk submit */ + workcalled = 0; + work = p___std_create_threadpool_work(threadpool_workcallback, &workcalled, NULL); + ok(!!work, "failed to create threadpool_work\n"); + p___std_bulk_submit_threadpool_work(work, 13); + p___std_wait_for_threadpool_work_callbacks(work, FALSE); + p___std_close_threadpool_work(work); + ok(workcalled == 13, "expected work to be called 13 times, got %d\n", workcalled); + + workcalled = 0; + work = p___std_create_threadpool_work(threadpool_workcallback, &workcalled, NULL); + ok(!!work, "failed to create threadpool_work\n"); + p___std_bulk_submit_threadpool_work(work, 0); + p___std_wait_for_threadpool_work_callbacks(work, FALSE); + p___std_close_threadpool_work(work); + ok(workcalled == 0, "expected no work, got %d\n", workcalled); + + /* canceling bulk submit */ + workcalled = 0; + work = p___std_create_threadpool_work(threadpool_workcallback, &workcalled, NULL); + ok(!!work, "failed to create threadpool_work\n"); + p___std_bulk_submit_threadpool_work(work, 1234); + p___std_wait_for_threadpool_work_callbacks(work, TRUE); + p___std_close_threadpool_work(work); + ok(workcalled < 1234, "expected some work to be canceled, got %d\n", workcalled); + /* test with environment */ cb_event = CreateEventW(NULL, TRUE, FALSE, NULL); memset(&environment, 0, sizeof(environment)); -- 2.34.1