ntdll-Vista_Threadpool: Simplify code to determine the current threadpool.

This commit is contained in:
Sebastian Lackner 2015-03-25 11:01:39 +01:00
parent 44094b9175
commit 4bfbd720eb
4 changed files with 62 additions and 83 deletions

View File

@ -1,4 +1,4 @@
From 4693a9204a3131172e0d1be292ecbe70777057de Mon Sep 17 00:00:00 2001
From 05e4482c93eec3e57ca2c6d83357c85b240494b2 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Tue, 24 Feb 2015 05:42:07 +0100
Subject: ntdll: Implement TpSimpleTryPost and basic threadpool infrastructure.
@ -45,7 +45,7 @@ index 2e31b34..6f164e9 100644
"TpSimpleTryPost unexpectedly returned status %x\n", status);
if (!status)
diff --git a/dlls/ntdll/threadpool.c b/dlls/ntdll/threadpool.c
index 513c13d..df92ef2 100644
index 513c13d..cc5f8e9 100644
--- a/dlls/ntdll/threadpool.c
+++ b/dlls/ntdll/threadpool.c
@@ -2,6 +2,7 @@
@ -206,13 +206,19 @@ index 513c13d..df92ef2 100644
+ return TRUE;
+}
+
+/* allocates or returns the default threadpool */
+static struct threadpool *get_default_threadpool( void )
+/* returns the threadpool based on the environment structure */
+static struct threadpool *get_threadpool( TP_CALLBACK_ENVIRON *environment )
+{
+ struct threadpool *pool;
+
+ if (environment)
+ {
+ pool = (struct threadpool *)environment->Pool;
+ if (pool) return pool;
+ }
+
+ if (!default_threadpool)
+ {
+ struct threadpool *pool;
+
+ if (tp_threadpool_alloc( &pool ) != STATUS_SUCCESS)
+ return NULL;
+
@ -222,6 +228,7 @@ index 513c13d..df92ef2 100644
+ tp_threadpool_release( pool );
+ }
+ }
+
+ return default_threadpool;
+}
+
@ -415,19 +422,12 @@ index 513c13d..df92ef2 100644
+ TP_CALLBACK_ENVIRON *environment )
+{
+ struct threadpool_object *object;
+ struct threadpool *pool = NULL;
+ struct threadpool *pool;
+
+ TRACE("%p %p %p\n", callback, userdata, environment);
+
+ if (environment)
+ pool = (struct threadpool *)environment->Pool;
+
+ if (!pool)
+ {
+ pool = get_default_threadpool();
+ if (!pool)
+ return STATUS_NO_MEMORY;
+ }
+ if (!(pool = get_threadpool( environment )))
+ return STATUS_NO_MEMORY;
+
+ object = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*object) );
+ if (!object)

View File

@ -1,12 +1,12 @@
From d4b4fc976cad98a6e483584da8de8f011f029c20 Mon Sep 17 00:00:00 2001
From 4814babb31750124d8d2d600a5894634fefe28f7 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Wed, 4 Mar 2015 01:30:57 +0100
Subject: ntdll: Implement threadpool work item functions.
---
dlls/ntdll/ntdll.spec | 4 ++
dlls/ntdll/threadpool.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 104 insertions(+), 1 deletion(-)
dlls/ntdll/ntdll.spec | 4 +++
dlls/ntdll/threadpool.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 97 insertions(+), 1 deletion(-)
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index 853ca09..96edd67 100644
@ -30,7 +30,7 @@ index 853ca09..96edd67 100644
@ stdcall ZwAcceptConnectPort(ptr long ptr long long ptr) NtAcceptConnectPort
@ stdcall ZwAccessCheck(ptr long long ptr ptr ptr ptr ptr) NtAccessCheck
diff --git a/dlls/ntdll/threadpool.c b/dlls/ntdll/threadpool.c
index 092fa6f..1989d56 100644
index 10ce6fd..01308d6 100644
--- a/dlls/ntdll/threadpool.c
+++ b/dlls/ntdll/threadpool.c
@@ -156,7 +156,8 @@ struct threadpool
@ -68,7 +68,7 @@ index 092fa6f..1989d56 100644
static inline struct threadpool_group *impl_from_TP_CLEANUP_GROUP( TP_CLEANUP_GROUP *group )
{
return (struct threadpool_group *)group;
@@ -1478,6 +1490,15 @@ static void CALLBACK threadpool_worker_proc( void *param )
@@ -1485,6 +1497,15 @@ static void CALLBACK threadpool_worker_proc( void *param )
break;
}
@ -84,7 +84,7 @@ index 092fa6f..1989d56 100644
default:
assert(0);
break;
@@ -1539,6 +1560,53 @@ NTSTATUS WINAPI TpAllocPool( TP_POOL **out, PVOID reserved )
@@ -1546,6 +1567,46 @@ NTSTATUS WINAPI TpAllocPool( TP_POOL **out, PVOID reserved )
}
/***********************************************************************
@ -94,19 +94,12 @@ index 092fa6f..1989d56 100644
+ TP_CALLBACK_ENVIRON *environment )
+{
+ struct threadpool_object *object;
+ struct threadpool *pool = NULL;
+ struct threadpool *pool;
+
+ TRACE("%p %p %p %p\n", out, callback, userdata, environment);
+
+ if (environment)
+ pool = (struct threadpool *)environment->Pool;
+
+ if (!pool)
+ {
+ pool = get_default_threadpool();
+ if (!pool)
+ return STATUS_NO_MEMORY;
+ }
+ if (!(pool = get_threadpool( environment )))
+ return STATUS_NO_MEMORY;
+
+ object = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*object) );
+ if (!object)
@ -138,7 +131,7 @@ index 092fa6f..1989d56 100644
* TpReleaseCleanupGroup (NTDLL.@)
*/
VOID WINAPI TpReleaseCleanupGroup( TP_CLEANUP_GROUP *group )
@@ -1633,6 +1701,21 @@ VOID WINAPI TpReleasePool( TP_POOL *pool )
@@ -1640,6 +1701,21 @@ VOID WINAPI TpReleasePool( TP_POOL *pool )
}
/***********************************************************************
@ -160,7 +153,7 @@ index 092fa6f..1989d56 100644
* TpSetPoolMaxThreads (NTDLL.@)
*/
VOID WINAPI TpSetPoolMaxThreads( TP_POOL *pool, DWORD maximum )
@@ -1696,3 +1779,19 @@ NTSTATUS WINAPI TpSimpleTryPost( PTP_SIMPLE_CALLBACK callback, PVOID userdata,
@@ -1696,3 +1772,19 @@ NTSTATUS WINAPI TpSimpleTryPost( PTP_SIMPLE_CALLBACK callback, PVOID userdata,
return STATUS_SUCCESS;
}

View File

@ -1,12 +1,12 @@
From fa631b5349a02927f1fec95235a40e7b9a75e7b6 Mon Sep 17 00:00:00 2001
From 90370a65b5f492ebe3fafb5e35548eb4b6681dac Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Wed, 4 Mar 2015 08:19:47 +0100
Subject: ntdll: Implement threadpool timer functions. (rev 2)
---
dlls/ntdll/ntdll.spec | 10 +-
dlls/ntdll/threadpool.c | 383 +++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 387 insertions(+), 6 deletions(-)
dlls/ntdll/threadpool.c | 376 +++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 380 insertions(+), 6 deletions(-)
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index 19e63a5..7aa8bda 100644
@ -58,7 +58,7 @@ index 19e63a5..7aa8bda 100644
@ stdcall TpWaitForWork(ptr long)
@ stdcall -ret64 VerSetConditionMask(int64 long long)
diff --git a/dlls/ntdll/threadpool.c b/dlls/ntdll/threadpool.c
index aa2d8e9..afb35aa 100644
index 351c1bd..493e0af 100644
--- a/dlls/ntdll/threadpool.c
+++ b/dlls/ntdll/threadpool.c
@@ -157,7 +157,8 @@ struct threadpool
@ -377,7 +377,7 @@ index aa2d8e9..afb35aa 100644
/* allocate a new threadpool (with at least one worker thread) */
static NTSTATUS tp_threadpool_alloc( struct threadpool **out )
{
@@ -1466,6 +1738,9 @@ static void tp_object_wait( struct threadpool_object *object )
@@ -1473,6 +1745,9 @@ static void tp_object_wait( struct threadpool_object *object )
/* mark an object as 'shutdown', submitting is no longer possible */
static void tp_object_shutdown( struct threadpool_object *object )
{
@ -387,7 +387,7 @@ index aa2d8e9..afb35aa 100644
object->shutdown = TRUE;
}
@@ -1673,6 +1948,15 @@ static void CALLBACK threadpool_worker_proc( void *param )
@@ -1680,6 +1955,15 @@ static void CALLBACK threadpool_worker_proc( void *param )
break;
}
@ -403,7 +403,7 @@ index aa2d8e9..afb35aa 100644
default:
assert(0);
break;
@@ -1747,6 +2031,48 @@ NTSTATUS WINAPI TpAllocPool( TP_POOL **out, PVOID reserved )
@@ -1754,6 +2038,41 @@ NTSTATUS WINAPI TpAllocPool( TP_POOL **out, PVOID reserved )
}
/***********************************************************************
@ -413,20 +413,13 @@ index aa2d8e9..afb35aa 100644
+ TP_CALLBACK_ENVIRON *environment )
+{
+ struct threadpool_object *object;
+ struct threadpool *pool = NULL;
+ struct threadpool *pool;
+ NTSTATUS status;
+
+ TRACE("%p %p %p %p\n", out, callback, userdata, environment);
+
+ if (environment)
+ pool = (struct threadpool *)environment->Pool;
+
+ if (!pool)
+ {
+ pool = get_default_threadpool();
+ if (!pool)
+ return STATUS_NO_MEMORY;
+ }
+ if (!(pool = get_threadpool( environment )))
+ return STATUS_NO_MEMORY;
+
+ object = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*object) );
+ if (!object)
@ -452,7 +445,7 @@ index aa2d8e9..afb35aa 100644
* TpAllocWork (NTDLL.@)
*/
NTSTATUS WINAPI TpAllocWork( TP_WORK **out, PTP_WORK_CALLBACK callback, PVOID userdata,
@@ -1909,6 +2235,17 @@ VOID WINAPI TpDisassociateCallback( TP_CALLBACK_INSTANCE *instance )
@@ -1909,6 +2228,17 @@ VOID WINAPI TpDisassociateCallback( TP_CALLBACK_INSTANCE *instance )
}
/***********************************************************************
@ -470,7 +463,7 @@ index aa2d8e9..afb35aa 100644
* TpPostWork (NTDLL.@)
*/
VOID WINAPI TpPostWork( TP_WORK *work )
@@ -2017,6 +2354,21 @@ VOID WINAPI TpReleasePool( TP_POOL *pool )
@@ -2017,6 +2347,21 @@ VOID WINAPI TpReleasePool( TP_POOL *pool )
}
/***********************************************************************
@ -492,7 +485,7 @@ index aa2d8e9..afb35aa 100644
* TpReleaseWork (NTDLL.@)
*/
VOID WINAPI TpReleaseWork( TP_WORK *work )
@@ -2065,6 +2417,20 @@ BOOL WINAPI TpSetPoolMinThreads( TP_POOL *pool, DWORD minimum )
@@ -2065,6 +2410,20 @@ BOOL WINAPI TpSetPoolMinThreads( TP_POOL *pool, DWORD minimum )
}
/***********************************************************************
@ -513,7 +506,7 @@ index aa2d8e9..afb35aa 100644
* TpSimpleTryPost (NTDLL.@)
*/
NTSTATUS WINAPI TpSimpleTryPost( PTP_SIMPLE_CALLBACK callback, PVOID userdata,
@@ -2097,6 +2463,21 @@ NTSTATUS WINAPI TpSimpleTryPost( PTP_SIMPLE_CALLBACK callback, PVOID userdata,
@@ -2090,6 +2449,21 @@ NTSTATUS WINAPI TpSimpleTryPost( PTP_SIMPLE_CALLBACK callback, PVOID userdata,
}
/***********************************************************************

View File

@ -1,12 +1,12 @@
From 56bf4aa534b59ba3a7d6175bea587b7b2aba1206 Mon Sep 17 00:00:00 2001
From 80175d154f0de20f916422684d9ae6708d532743 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Wed, 4 Mar 2015 13:33:25 +0100
Subject: ntdll: Implement threadpool wait objects.
---
dlls/ntdll/ntdll.spec | 8 +-
dlls/ntdll/threadpool.c | 479 +++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 476 insertions(+), 11 deletions(-)
dlls/ntdll/threadpool.c | 472 +++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 469 insertions(+), 11 deletions(-)
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index 7aa8bda..7c15f76 100644
@ -49,7 +49,7 @@ index 7aa8bda..7c15f76 100644
@ stdcall -ret64 VerSetConditionMask(int64 long long)
@ stdcall ZwAcceptConnectPort(ptr long ptr long long ptr) NtAcceptConnectPort
diff --git a/dlls/ntdll/threadpool.c b/dlls/ntdll/threadpool.c
index afb35aa..706d62b 100644
index 493e0af..cda5a12 100644
--- a/dlls/ntdll/threadpool.c
+++ b/dlls/ntdll/threadpool.c
@@ -137,6 +137,7 @@ struct timer_queue
@ -471,7 +471,7 @@ index afb35aa..706d62b 100644
/* allocate a new threadpool (with at least one worker thread) */
static NTSTATUS tp_threadpool_alloc( struct threadpool **out )
{
@@ -1633,7 +1981,7 @@ static void tp_object_initialize( struct threadpool_object *object, struct threa
@@ -1640,7 +1988,7 @@ static void tp_object_initialize( struct threadpool_object *object, struct threa
* to the cleanup group. As soon as the cleanup group members are released ->shutdown
* will be set, and tp_object_submit would fail with an assertion. */
if (simple_cb)
@ -480,7 +480,7 @@ index afb35aa..706d62b 100644
if (object->group)
{
@@ -1654,7 +2002,7 @@ static void tp_object_initialize( struct threadpool_object *object, struct threa
@@ -1661,7 +2009,7 @@ static void tp_object_initialize( struct threadpool_object *object, struct threa
}
/* submits an object to a threadpool */
@ -489,7 +489,7 @@ index afb35aa..706d62b 100644
{
struct threadpool *pool = object->pool;
@@ -1689,6 +2037,10 @@ out:
@@ -1696,6 +2044,10 @@ out:
if (!object->num_pending_callbacks++)
list_add_tail( &pool->pool, &object->pool_entry );
@ -500,7 +500,7 @@ index afb35aa..706d62b 100644
RtlLeaveCriticalSection( &pool->cs );
}
@@ -1707,6 +2059,9 @@ static void tp_object_cancel( struct threadpool_object *object, BOOL group_cance
@@ -1714,6 +2066,9 @@ static void tp_object_cancel( struct threadpool_object *object, BOOL group_cance
list_remove( &object->pool_entry );
}
@ -510,7 +510,7 @@ index afb35aa..706d62b 100644
RtlLeaveCriticalSection( &pool->cs );
/* Execute group cancellation callback if defined, and if this was actually a group cancel. */
@@ -1740,6 +2095,8 @@ static void tp_object_shutdown( struct threadpool_object *object )
@@ -1747,6 +2102,8 @@ static void tp_object_shutdown( struct threadpool_object *object )
{
if (object->type == TP_OBJECT_TYPE_TIMER)
tp_timerqueue_release( object );
@ -519,7 +519,7 @@ index afb35aa..706d62b 100644
object->shutdown = TRUE;
}
@@ -1905,6 +2262,7 @@ static void CALLBACK threadpool_worker_proc( void *param )
@@ -1912,6 +2269,7 @@ static void CALLBACK threadpool_worker_proc( void *param )
struct threadpool_instance instance;
TP_CALLBACK_INSTANCE *cb_instance = (TP_CALLBACK_INSTANCE *)&instance;
struct threadpool *pool = param;
@ -527,7 +527,7 @@ index afb35aa..706d62b 100644
LARGE_INTEGER timeout;
struct list *ptr;
@@ -1922,6 +2280,18 @@ static void CALLBACK threadpool_worker_proc( void *param )
@@ -1929,6 +2287,18 @@ static void CALLBACK threadpool_worker_proc( void *param )
if (--object->num_pending_callbacks)
list_add_tail( &pool->pool, &object->pool_entry );
@ -546,7 +546,7 @@ index afb35aa..706d62b 100644
/* Leave critical section and do the actual callback. */
object->num_running_callbacks++;
pool->num_busy_workers++;
@@ -1957,6 +2327,15 @@ static void CALLBACK threadpool_worker_proc( void *param )
@@ -1964,6 +2334,15 @@ static void CALLBACK threadpool_worker_proc( void *param )
break;
}
@ -562,7 +562,7 @@ index afb35aa..706d62b 100644
default:
assert(0);
break;
@@ -2073,6 +2452,48 @@ NTSTATUS WINAPI TpAllocTimer( TP_TIMER **out, PTP_TIMER_CALLBACK callback, PVOID
@@ -2073,6 +2452,41 @@ NTSTATUS WINAPI TpAllocTimer( TP_TIMER **out, PTP_TIMER_CALLBACK callback, PVOID
}
/***********************************************************************
@ -572,20 +572,13 @@ index afb35aa..706d62b 100644
+ TP_CALLBACK_ENVIRON *environment )
+{
+ struct threadpool_object *object;
+ struct threadpool *pool = NULL;
+ struct threadpool *pool;
+ NTSTATUS status;
+
+ TRACE("%p %p %p %p\n", out, callback, userdata, environment);
+
+ if (environment)
+ pool = (struct threadpool *)environment->Pool;
+
+ if (!pool)
+ {
+ pool = get_default_threadpool();
+ if (!pool)
+ return STATUS_NO_MEMORY;
+ }
+ if (!(pool = get_threadpool( environment )))
+ return STATUS_NO_MEMORY;
+
+ object = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*object) );
+ if (!object)
@ -611,7 +604,7 @@ index afb35aa..706d62b 100644
* TpAllocWork (NTDLL.@)
*/
NTSTATUS WINAPI TpAllocWork( TP_WORK **out, PTP_WORK_CALLBACK callback, PVOID userdata,
@@ -2255,7 +2676,7 @@ VOID WINAPI TpPostWork( TP_WORK *work )
@@ -2248,7 +2662,7 @@ VOID WINAPI TpPostWork( TP_WORK *work )
if (this)
{
@ -620,7 +613,7 @@ index afb35aa..706d62b 100644
}
}
@@ -2369,6 +2790,21 @@ VOID WINAPI TpReleaseTimer( TP_TIMER *timer )
@@ -2362,6 +2776,21 @@ VOID WINAPI TpReleaseTimer( TP_TIMER *timer )
}
/***********************************************************************
@ -642,7 +635,7 @@ index afb35aa..706d62b 100644
* TpReleaseWork (NTDLL.@)
*/
VOID WINAPI TpReleaseWork( TP_WORK *work )
@@ -2431,6 +2867,20 @@ VOID WINAPI TpSetTimer( TP_TIMER *timer, LARGE_INTEGER *timeout, LONG period, LO
@@ -2424,6 +2853,20 @@ VOID WINAPI TpSetTimer( TP_TIMER *timer, LARGE_INTEGER *timeout, LONG period, LO
}
/***********************************************************************
@ -663,7 +656,7 @@ index afb35aa..706d62b 100644
* TpSimpleTryPost (NTDLL.@)
*/
NTSTATUS WINAPI TpSimpleTryPost( PTP_SIMPLE_CALLBACK callback, PVOID userdata,
@@ -2478,6 +2928,21 @@ VOID WINAPI TpWaitForTimer( TP_TIMER *timer, BOOL cancel_pending )
@@ -2464,6 +2907,21 @@ VOID WINAPI TpWaitForTimer( TP_TIMER *timer, BOOL cancel_pending )
}
/***********************************************************************