ntdll: Use a helper to allocate threadpool workers

Bruno Jesus 00cpxxx at gmail.com
Mon Aug 22 15:39:10 CDT 2016


Signed-off-by: Bruno Jesus <00cpxxx at gmail.com>
-------------- next part --------------
diff --git a/dlls/ntdll/threadpool.c b/dlls/ntdll/threadpool.c
index 5d5b49d..c8f8467 100644
--- a/dlls/ntdll/threadpool.c
+++ b/dlls/ntdll/threadpool.c
@@ -1279,6 +1279,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
@@ -1710,18 +1732,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 );
@@ -2410,16 +2410,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
         {
@@ -2697,16 +2688,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)


More information about the wine-patches mailing list