2 #include <winpr/wtypes.h>
4 #include <winpr/pool.h>
5 #include <winpr/interlocked.h>
9 static void CALLBACK test_WorkCallback(PTP_CALLBACK_INSTANCE instance,
void* context, PTP_WORK work)
11 printf(
"Hello %s: %03" PRId32
" (thread: 0x%08" PRIX32
")\n", (
char*)context,
12 InterlockedIncrement(&count), GetCurrentThreadId());
14 for (
int index = 0; index < 100; index++)
20 FillMemory(a, ARRAYSIZE(a), 0xAA);
21 FillMemory(b, ARRAYSIZE(b), 0xBB);
23 CopyMemory(c, a, ARRAYSIZE(a));
24 CopyMemory(c, b, ARRAYSIZE(b));
28 static BOOL test1(
void)
31 printf(
"Global Thread Pool\n");
32 work = CreateThreadpoolWork(test_WorkCallback,
"world", NULL);
36 printf(
"CreateThreadpoolWork failure\n");
46 for (
int index = 0; index < 10; index++)
47 SubmitThreadpoolWork(work);
49 WaitForThreadpoolWorkCallbacks(work, FALSE);
50 CloseThreadpoolWork(work);
54 static BOOL test2(
void)
59 PTP_CLEANUP_GROUP cleanupGroup = NULL;
61 printf(
"Private Thread Pool\n");
63 if (!(pool = CreateThreadpool(NULL)))
65 printf(
"CreateThreadpool failure\n");
69 if (!SetThreadpoolThreadMinimum(pool, 4))
71 printf(
"SetThreadpoolThreadMinimum failure\n");
75 SetThreadpoolThreadMaximum(pool, 8);
76 InitializeThreadpoolEnvironment(&environment);
77 SetThreadpoolCallbackPool(&environment, pool);
78 cleanupGroup = CreateThreadpoolCleanupGroup();
82 printf(
"CreateThreadpoolCleanupGroup failure\n");
86 SetThreadpoolCallbackCleanupGroup(&environment, cleanupGroup, NULL);
87 work = CreateThreadpoolWork(test_WorkCallback,
"world", &environment);
91 printf(
"CreateThreadpoolWork failure\n");
95 for (
int index = 0; index < 10; index++)
96 SubmitThreadpoolWork(work);
98 WaitForThreadpoolWorkCallbacks(work, FALSE);
104 CloseThreadpoolCleanupGroupMembers(cleanupGroup, TRUE, NULL);
105 CloseThreadpoolCleanupGroup(cleanupGroup);
106 DestroyThreadpoolEnvironment(&environment);
115 CloseThreadpoolWork(work);
119 CloseThreadpool(pool);
123 int TestPoolWork(
int argc,
char* argv[])