libwinpr-pool: fix InitializeThreadpoolEnvironment
This commit is contained in:
parent
74bba0e767
commit
fb189989af
@ -55,7 +55,32 @@ typedef struct _TP_CLEANUP_GROUP TP_CLEANUP_GROUP, *PTP_CLEANUP_GROUP;
|
||||
|
||||
typedef VOID (*PTP_CLEANUP_GROUP_CANCEL_CALLBACK)(PVOID ObjectContext, PVOID CleanupContext);
|
||||
|
||||
#if 0
|
||||
typedef struct _TP_CALLBACK_ENVIRON_V1
|
||||
{
|
||||
TP_VERSION Version;
|
||||
PTP_POOL Pool;
|
||||
PTP_CLEANUP_GROUP CleanupGroup;
|
||||
PTP_CLEANUP_GROUP_CANCEL_CALLBACK CleanupGroupCancelCallback;
|
||||
PVOID RaceDll;
|
||||
struct _ACTIVATION_CONTEXT* ActivationContext;
|
||||
PTP_SIMPLE_CALLBACK FinalizationCallback;
|
||||
|
||||
union
|
||||
{
|
||||
DWORD Flags;
|
||||
struct
|
||||
{
|
||||
DWORD LongFunction:1;
|
||||
DWORD Persistent:1;
|
||||
DWORD Private:30;
|
||||
} s;
|
||||
} u;
|
||||
} TP_CALLBACK_ENVIRON_V1;
|
||||
|
||||
#endif
|
||||
|
||||
/* Non-Windows and pre Windows 7 */
|
||||
#if ((!defined(_WIN32)) || (defined(_WIN32) && (_WIN32_WINNT < 0x0601)))
|
||||
|
||||
typedef struct _TP_CALLBACK_ENVIRON_V3
|
||||
{
|
||||
@ -83,33 +108,7 @@ typedef struct _TP_CALLBACK_ENVIRON_V3
|
||||
DWORD Size;
|
||||
} TP_CALLBACK_ENVIRON_V3;
|
||||
|
||||
typedef TP_CALLBACK_ENVIRON_V3 TP_CALLBACK_ENVIRON, *PTP_CALLBACK_ENVIRON;
|
||||
|
||||
#else
|
||||
|
||||
typedef struct _TP_CALLBACK_ENVIRON_V1
|
||||
{
|
||||
TP_VERSION Version;
|
||||
PTP_POOL Pool;
|
||||
PTP_CLEANUP_GROUP CleanupGroup;
|
||||
PTP_CLEANUP_GROUP_CANCEL_CALLBACK CleanupGroupCancelCallback;
|
||||
PVOID RaceDll;
|
||||
struct _ACTIVATION_CONTEXT* ActivationContext;
|
||||
PTP_SIMPLE_CALLBACK FinalizationCallback;
|
||||
|
||||
union
|
||||
{
|
||||
DWORD Flags;
|
||||
struct
|
||||
{
|
||||
DWORD LongFunction:1;
|
||||
DWORD Persistent:1;
|
||||
DWORD Private:30;
|
||||
} s;
|
||||
} u;
|
||||
} TP_CALLBACK_ENVIRON_V1;
|
||||
|
||||
#endif
|
||||
//typedef TP_CALLBACK_ENVIRON_V3 TP_CALLBACK_ENVIRON, *PTP_CALLBACK_ENVIRON;
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -26,13 +26,41 @@
|
||||
|
||||
#include "pool.h"
|
||||
|
||||
VOID InitializeCallbackEnvironment_V1(TP_CALLBACK_ENVIRON_V1* pcbe)
|
||||
{
|
||||
pcbe->Version = 1;
|
||||
|
||||
pcbe->Pool = NULL;
|
||||
pcbe->CleanupGroup = NULL;
|
||||
pcbe->CleanupGroupCancelCallback = NULL;
|
||||
pcbe->RaceDll = NULL;
|
||||
pcbe->ActivationContext = NULL;
|
||||
pcbe->FinalizationCallback = NULL;
|
||||
pcbe->u.Flags = 0;
|
||||
}
|
||||
|
||||
VOID InitializeCallbackEnvironment_V3(TP_CALLBACK_ENVIRON_V3* pcbe)
|
||||
{
|
||||
pcbe->Version = 3;
|
||||
|
||||
pcbe->Pool = NULL;
|
||||
pcbe->CleanupGroup = NULL;
|
||||
pcbe->CleanupGroupCancelCallback = NULL;
|
||||
pcbe->RaceDll = NULL;
|
||||
pcbe->ActivationContext = NULL;
|
||||
pcbe->FinalizationCallback = NULL;
|
||||
pcbe->u.Flags = 0;
|
||||
|
||||
pcbe->CallbackPriority = TP_CALLBACK_PRIORITY_NORMAL;
|
||||
pcbe->Size = sizeof(TP_CALLBACK_ENVIRON);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
static BOOL module_initialized = FALSE;
|
||||
static BOOL module_available = FALSE;
|
||||
static HMODULE kernel32_module = NULL;
|
||||
|
||||
static VOID (WINAPI * pInitializeThreadpoolEnvironment)(PTP_CALLBACK_ENVIRON pcbe);
|
||||
static VOID (WINAPI * pDestroyThreadpoolEnvironment)(PTP_CALLBACK_ENVIRON pcbe);
|
||||
static VOID (WINAPI * pSetThreadpoolCallbackPool)(PTP_CALLBACK_ENVIRON pcbe, PTP_POOL ptpp);
|
||||
static VOID (WINAPI * pSetThreadpoolCallbackCleanupGroup)(PTP_CALLBACK_ENVIRON pcbe, PTP_CLEANUP_GROUP ptpcg, PTP_CLEANUP_GROUP_CANCEL_CALLBACK pfng);
|
||||
@ -53,7 +81,7 @@ static void module_init()
|
||||
|
||||
module_available = TRUE;
|
||||
|
||||
pInitializeThreadpoolEnvironment = (void*) GetProcAddress(kernel32_module, "InitializeThreadpoolEnvironment");
|
||||
/* InitializeThreadpoolEnvironment is an inline function */
|
||||
pDestroyThreadpoolEnvironment = (void*) GetProcAddress(kernel32_module, "DestroyThreadpoolEnvironment");
|
||||
pSetThreadpoolCallbackPool = (void*) GetProcAddress(kernel32_module, "SetThreadpoolCallbackPool");
|
||||
pSetThreadpoolCallbackCleanupGroup = (void*) GetProcAddress(kernel32_module, "SetThreadpoolCallbackCleanupGroup");
|
||||
@ -90,23 +118,10 @@ PTP_CALLBACK_ENVIRON GetDefaultThreadpoolEnvironment()
|
||||
|
||||
VOID InitializeThreadpoolEnvironment(PTP_CALLBACK_ENVIRON pcbe)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
module_init();
|
||||
|
||||
if (pInitializeThreadpoolEnvironment)
|
||||
pInitializeThreadpoolEnvironment(pcbe);
|
||||
#else
|
||||
pcbe->Version = 1;
|
||||
pcbe->Pool = NULL;
|
||||
pcbe->CleanupGroup = NULL;
|
||||
pcbe->CleanupGroupCancelCallback = NULL;
|
||||
pcbe->RaceDll = NULL;
|
||||
pcbe->ActivationContext = NULL;
|
||||
pcbe->FinalizationCallback = NULL;
|
||||
pcbe->u.s.LongFunction = FALSE;
|
||||
pcbe->u.s.Persistent = FALSE;
|
||||
pcbe->u.s.Private = 0;
|
||||
#endif
|
||||
if (pcbe->Version == 3)
|
||||
InitializeCallbackEnvironment_V3((TP_CALLBACK_ENVIRON_V3*) pcbe);
|
||||
else
|
||||
InitializeCallbackEnvironment_V1(pcbe);
|
||||
}
|
||||
|
||||
VOID DestroyThreadpoolEnvironment(PTP_CALLBACK_ENVIRON pcbe)
|
||||
|
@ -1,17 +1,19 @@
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/pool.h>
|
||||
#include <winpr/interlocked.h>
|
||||
|
||||
static int count = 0;
|
||||
static LONG count = 0;
|
||||
|
||||
void test_WorkCallback(PTP_CALLBACK_INSTANCE instance, void* context, PTP_WORK work)
|
||||
void CALLBACK test_WorkCallback(PTP_CALLBACK_INSTANCE instance, void* context, PTP_WORK work)
|
||||
{
|
||||
int index;
|
||||
BYTE a[1024];
|
||||
BYTE b[1024];
|
||||
BYTE c[1024];
|
||||
|
||||
printf("Hello %s: %d (thread: %d)\n", context, count++, GetCurrentThreadId());
|
||||
printf("Hello %s: %d (thread: %d)\n", context,
|
||||
InterlockedIncrement(&count), GetCurrentThreadId());
|
||||
|
||||
for (index = 0; index < 100; index++)
|
||||
{
|
||||
@ -93,6 +95,7 @@ int TestPoolWork(int argc, char* argv[])
|
||||
|
||||
DestroyThreadpoolEnvironment(&environment);
|
||||
|
||||
CloseThreadpoolWork(work);
|
||||
CloseThreadpool(pool);
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user