Module: wine Branch: master Commit: 3b3c0d9e09c609e9fada24a451f7cb878b2d3f14 URL: http://source.winehq.org/git/wine.git/?a=commit;h=3b3c0d9e09c609e9fada24a451...
Author: Bruno Jesus 00cpxxx@gmail.com Date: Mon Aug 22 17:39:10 2016 -0300
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
---
dlls/ntdll/threadpool.c | 68 +++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 42 deletions(-)
diff --git a/dlls/ntdll/threadpool.c b/dlls/ntdll/threadpool.c index 173e865..6063d51 100644 --- a/dlls/ntdll/threadpool.c +++ b/dlls/ntdll/threadpool.c @@ -1282,6 +1282,28 @@ static void CALLBACK timerqueue_thread_proc( void *param ) }
/*********************************************************************** + * tp_new_worker_thread (internal) + * + * Create and account a new worker thread for the desired pool. + */ +static NTSTATUS tp_new_worker_thread( struct threadpool *pool ) +{ + HANDLE thread; + NTSTATUS status; + + status = RtlCreateUserThread( GetCurrentProcess(), NULL, FALSE, NULL, 0, 0, + threadpool_worker_proc, pool, &thread, NULL ); + if (status == STATUS_SUCCESS) + { + interlocked_inc( &pool->refcount ); + pool->num_workers++; + pool->num_busy_workers++; + NtClose( thread ); + } + return status; +} + +/*********************************************************************** * tp_timerqueue_lock (internal) * * Acquires a lock on the global timerqueue. When the lock is acquired @@ -1713,18 +1735,7 @@ static NTSTATUS tp_threadpool_lock( struct threadpool **out, TP_CALLBACK_ENVIRON
/* Make sure that the threadpool has at least one thread. */ if (!pool->num_workers) - { - HANDLE thread; - status = RtlCreateUserThread( GetCurrentProcess(), NULL, FALSE, NULL, 0, 0, - threadpool_worker_proc, pool, &thread, NULL ); - if (status == STATUS_SUCCESS) - { - interlocked_inc( &pool->refcount ); - pool->num_workers++; - pool->num_busy_workers++; - NtClose( thread ); - } - } + status = tp_new_worker_thread( pool );
/* Keep a reference, and increment objcount to ensure that the * last thread doesn't terminate. */ @@ -1910,18 +1921,7 @@ static void tp_object_submit( struct threadpool_object *object, BOOL signaled ) /* Start new worker threads if required. */ if (pool->num_busy_workers >= pool->num_workers && pool->num_workers < pool->max_workers) - { - HANDLE thread; - status = RtlCreateUserThread( GetCurrentProcess(), NULL, FALSE, NULL, 0, 0, - threadpool_worker_proc, pool, &thread, NULL ); - if (status == STATUS_SUCCESS) - { - interlocked_inc( &pool->refcount ); - pool->num_workers++; - pool->num_busy_workers++; - NtClose( thread ); - } - } + status = tp_new_worker_thread( pool );
/* Queue work item and increment refcount. */ interlocked_inc( &object->refcount ); @@ -2406,16 +2406,7 @@ NTSTATUS WINAPI TpCallbackMayRunLong( TP_CALLBACK_INSTANCE *instance ) { if (pool->num_workers < pool->max_workers) { - HANDLE thread; - status = RtlCreateUserThread( GetCurrentProcess(), NULL, FALSE, NULL, 0, 0, - threadpool_worker_proc, pool, &thread, NULL ); - if (status == STATUS_SUCCESS) - { - interlocked_inc( &pool->refcount ); - pool->num_workers++; - pool->num_busy_workers++; - NtClose( thread ); - } + status = tp_new_worker_thread( pool ); } else { @@ -2708,16 +2699,9 @@ BOOL WINAPI TpSetPoolMinThreads( TP_POOL *pool, DWORD minimum )
while (this->num_workers < minimum) { - HANDLE thread; - status = RtlCreateUserThread( GetCurrentProcess(), NULL, FALSE, NULL, 0, 0, - threadpool_worker_proc, this, &thread, NULL ); + status = tp_new_worker_thread( this ); if (status != STATUS_SUCCESS) break; - - interlocked_inc( &this->refcount ); - this->num_workers++; - this->num_busy_workers++; - NtClose( thread ); }
if (status == STATUS_SUCCESS)