Commit Graph

96 Commits

Author SHA1 Message Date
Paul Gofman bdba5ba5f6 ntdll: Manage TPIO object destruction based on the expected completions.
Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-07-28 22:07:04 +02:00
Paul Gofman 4dcc87cfff ntdll: Clear thread_running flag on exiting ioqueue_thread_proc().
Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-07-28 22:07:04 +02:00
Paul Gofman fa9bbe8a22 ntdll: Only queue IO callback if IO is pending in ioqueue_thread_proc().
Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-07-28 22:07:04 +02:00
Paul Gofman 217ae19d03 ntdll: Decrement IO pending count in ioqueue_thread_proc().
Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-07-28 22:07:04 +02:00
Alexandre Julliard 40165dfa58 ntdll: RtlCreateUserThread() also takes a zero_bits parameter.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-05-07 22:22:49 +02:00
Paul Gofman 6e75cc98e8 ntdll: Release IO thread pool object from ioqueue_thread_proc().
Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-04-20 21:07:09 +02:00
Alexandre Julliard 58eceff167 ntdll: Don't use wine/server.h from the PE side.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-02-16 23:01:37 +01:00
Rémi Bernon b922b5aeef kernel32: Write the wait handle before executing the callback.
Otherwise we may execute the callback before the value is actually
returned from RegisterWaitForSingleObject.

Gears Tactics shares a pointer to the returned handle with its callbacks
and calls UnregisterWait from there. This creates a race condition that
sometimes causes a double free.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47843
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-02-11 22:26:36 +01:00
Rémi Bernon 26ee9134d5 ntdll: Re-implement RtlRegisterWait using TpSetWait.
This adds several internal flags to TP_WAIT object to support the
implementation:

* WT_EXECUTEONLYONCE: waits are re-queued unless it is set.

* WT_EXECUTEINWAITTHREAD: call the callback in the wait thread when set.

* WT_EXECUTEINIOTHREAD: call alertable NtWaitForMultipleObjects in wait
  thread when set, as well the callback in the wait thread, as for
  WT_EXECUTEINWAITTHREAD. The worker threads use non-alertable waits
  otherwise.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47843
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-02-11 22:26:36 +01:00
Rémi Bernon 304d811924 ntdll: Introduce new tp_object_execute helper.
To execute a threadpool_object callbacks.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47843
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-02-11 22:26:36 +01:00
Rémi Bernon 3ed3e031ff ntdll: Don't force submit wait in TpSetWait if timeout is 0.
It'll be submitted eventually, no need to force it and it makes support
for WT_EXECUTEINWAITTHREAD flag harder.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47843
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-02-11 22:26:36 +01:00
Rémi Bernon de6fce48ac ntdll: Move Rtl(Un)RegisterWait code below threadpool structs.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47843
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-02-11 22:26:36 +01:00
Alexandre Julliard 8a169390c9 ntdll: Build with msvcrt.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-06-30 12:25:08 +02:00
Paul Gofman 6d712a42ca ntdll: Increment num_busy_workers when queuing TP object.
Otherwise two consequative submits may have the same
num_busy_workers value if threadpool_worker_proc did not
have a chance to pick the work in between. A new thread is
not created in tp_submit() for the second submit and if the
first submit queues an (infinitely long) wait
the next submitted callback is not called for indefinite
time period.

Fixes hang on exit in Detroit Become Human.

Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-06-22 16:43:12 +02:00
Alexandre Julliard 39e4b788d6 ntdll: Use the standard Interlocked* functions.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-05-02 15:10:04 +02:00
Jacek Caban b66e13ef24 kernelbase: Implement CreateThreadpoolIo.
Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-04-15 11:40:49 +02:00
Zebediah Figura 75e8c4493a ntdll: Implement threadpool I/O queues.
Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-04-13 11:57:46 +02:00
Zebediah Figura 74d830755c ntdll: Factor out object_is_finished().
Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-04-13 11:57:43 +02:00
Nikolay Sivov 480d8b8253 kernel32: Add StartThreadpoolIo() stub.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-02-12 16:54:03 +01:00
Nikolay Sivov b2f5b03429 ntdll: Add threadpool stack information exports.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-02-12 16:54:03 +01:00
Nikolay Sivov 733b438583 ntdll/threadpool: Add support for callback priority.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2019-03-13 10:59:50 +01:00
Stefan Dösinger 759e6f1d8d ntdll: Avoid more race conditions in RtlDeregisterWaitEx.
af35aada9b left some issues unfixed.
Instead of running the callback and returning a retval that indicates
the callback is not running, we sometimes wait for it when we are not
supposed to.

Signed-off-by: Stefan Dösinger <stefan@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2018-10-31 19:13:15 +01:00
Stefan Dösinger af35aada9b ntdll: Make RtlDeregisterWaitEx(handle, INVALID_HANDLE_VALUE) thread safe.
Chromium signals the wait semaphore and calls DeregisterWaitEx with
CompletionHandle = INVALID_HANDLE_VALUE in close succession. Sometimes
the worker thread decides to run the callback, but before it sets
CallbackInProgress RtlDeregisterWaitEx decides that the callback is not
running and returns STATUS_SUCCESS. Chromium then releases resources
that the callback needs to run, resulting in random crashes.

Signed-off-by: Stefan Dösinger <stefan@codeweavers.com>
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2017-09-06 20:32:07 +02:00
Bruno Jesus 3b3c0d9e09 ntdll: Use a helper to allocate threadpool workers.
Signed-off-by: Bruno Jesus <00cpxxx@gmail.com>
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-08-23 12:16:49 +09:00
Keno Fischer 90173ce448 ntdll: Tolerate null handle in DeregisterWait.
Signed-off-by: Keno Fischer <keno@juliacomputing.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-08-22 23:05:22 +09:00
Sebastian Lackner a9f648ef69 ntdll: Do not call group cancel callback for finished simple callbacks.
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-08-22 12:51:24 +09:00
Sebastian Lackner be7bcdc0f9 ntdll: Group cancel callbacks should be executed after waiting for pending callbacks.
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-08-22 12:50:50 +09:00
Sebastian Lackner a8830a2478 ntdll: Call group cancel callback with the correct arguments.
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-08-22 12:50:44 +09:00
Sebastian Lackner 53db77b5d7 ntdll: Allow to release threadpool objects while waiting for group.
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-08-22 12:50:33 +09:00
Sebastian Lackner d085042ab9 ntdll: Convert an ERR to a WARN when wait is triggered while destroying threadpool object.
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-08-19 16:15:01 +09:00
Nikolay Sivov 7de025c970 ntdll: Fix its vs it's typos.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-08-01 20:57:23 -05:00
Frédéric Delanoy 07a87666a1 ntdll: Fix a typo in an comment.
Signed-off-by: Frédéric Delanoy <frederic.delanoy@gmail.com>
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-05-18 21:18:17 +09:00
Sebastian Lackner a919a02ac3 ntdll: Don't warn about unsupported environment version 3.
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2016-03-31 15:57:32 +09:00
Sebastian Lackner 381c034be3 ntdll: Wait_thread_proc should not terminate on user APC.
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2015-10-09 20:56:27 +09:00
Francois Gouget e0e2ee3487 ntdll: Add a trailing '\n' to a FIXME() trace. 2015-08-07 23:50:20 +09:00
Sebastian Lackner 5bd9d58016 ntdll: Mark newly spawned worker threads as busy. 2015-07-29 22:23:56 +02:00
Sebastian Lackner 9562e81810 ntdll: Reimplement RtlQueueWorkItem on top of new threadpool API. 2015-07-28 09:54:18 +02:00
Sebastian Lackner b687fee66f ntdll: Fix incorrect assignment in assert statement (Coverity). 2015-07-13 14:44:40 +09:00
Sebastian Lackner f65f645c3f ntdll: Add missing calls to RtlExitUserThread. 2015-07-08 16:02:24 +09:00
Sebastian Lackner 0021569778 ntdll: Try to merge threadpool wait queue buckets if possible.
When the number of elements per bucket is too small, then try to reduce
the number of threads by merging buckets. This is to ensure that the
number of running wait queue threads doesn't get too big.
2015-07-06 14:49:39 +09:00
Sebastian Lackner 185247576b ntdll: Implement TpSetWait and TpWaitForWait. 2015-07-06 14:49:39 +09:00
Sebastian Lackner f1be5dcac0 ntdll: Implement threadpool wait queues.
To implement waiting for an arbitrary number of handles, we group them
in buckets up to (MAXIMUM_WAIT_OBJECTS - 1) objects, and then assign a
dedicated wait queue thread. The last handle is used to notify about
changes.
2015-07-06 14:49:38 +09:00
Sebastian Lackner 4523a54c62 ntdll: Implement TpAllocWait and TpReleaseWait. 2015-07-06 14:34:20 +09:00
Sebastian Lackner cb2aae1af8 ntdll: Implement threadpool timer queues. 2015-07-03 13:06:41 +09:00
Sebastian Lackner bd7cb07358 ntdll: Implement TpAllocTimer and TpReleaseTimer. 2015-07-03 13:06:31 +09:00
Sebastian Lackner 775d3dcecb ntdll: Implement TpDisassociateCallback and add a separate group completion event. 2015-07-03 13:06:15 +09:00
Sebastian Lackner 8965511957 ntdll: Implement TpCallbackUnloadDllOnCompletion. 2015-07-02 14:54:13 +09:00
Sebastian Lackner 15110b1770 ntdll: Implement TpCallbackSetEventOnCompletion. 2015-07-02 14:54:04 +09:00
Sebastian Lackner eb39cb1323 ntdll: Implement TpCallbackReleaseSemaphoreOnCompletion. 2015-07-02 14:53:50 +09:00
Sebastian Lackner 02ee5bb52d ntdll: Implement TpCallbackReleaseMutexOnCompletion.
Various internal details about the order and error handling of completion
actions are documented in "Concurrent Programming on Windows" by Joe Duffy.
2015-07-02 14:53:41 +09:00