mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
1) Added missing checks for CreateEvent which also required the following related changes: - changed freerdp_context_new API to BOOL - changed freerdp_peer_context_new API to BOOL - changed pRdpClientNew callback to BOOL - changed pContextNew callback to BOOL - changed psPeerAccepted callback to BOOL - changed psPeerContextNew callback to BOOL 2) Fixed lots of missing alloc and error checks in the changed code's neighbourhood. 3) Check freerdp_client_codecs_prepare result to avoid segfaults caused by using non-initialized codecs. 4) Fixed deadlocks in x11 caused by missing xf_unlock_x11() calls in some error handlers 5) Some fixes in thread pool: - DEFAULT_POOL assignment did not match TP_POOL definition - don't free the pool pointer if it points to the static DEFAULT_POOL - added error handling and cleanup in InitializeThreadpool
107 lines
2.3 KiB
C
107 lines
2.3 KiB
C
|
|
#include <winpr/crt.h>
|
|
#include <winpr/pool.h>
|
|
#include <winpr/interlocked.h>
|
|
|
|
static LONG count = 0;
|
|
|
|
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", (char*) context,
|
|
InterlockedIncrement(&count), GetCurrentThreadId());
|
|
|
|
for (index = 0; index < 100; index++)
|
|
{
|
|
ZeroMemory(a, 1024);
|
|
ZeroMemory(b, 1024);
|
|
ZeroMemory(c, 1024);
|
|
FillMemory(a, 1024, 0xAA);
|
|
FillMemory(b, 1024, 0xBB);
|
|
CopyMemory(c, a, 1024);
|
|
CopyMemory(c, b, 1024);
|
|
}
|
|
}
|
|
|
|
int TestPoolWork(int argc, char* argv[])
|
|
{
|
|
int index;
|
|
PTP_POOL pool;
|
|
PTP_WORK work;
|
|
PTP_CLEANUP_GROUP cleanupGroup;
|
|
TP_CALLBACK_ENVIRON environment;
|
|
|
|
printf("Global Thread Pool\n");
|
|
|
|
work = CreateThreadpoolWork((PTP_WORK_CALLBACK) test_WorkCallback, "world", NULL);
|
|
|
|
if (!work)
|
|
{
|
|
printf("CreateThreadpoolWork failure\n");
|
|
return -1;
|
|
}
|
|
|
|
/**
|
|
* You can post a work object one or more times (up to MAXULONG) without waiting for prior callbacks to complete.
|
|
* The callbacks will execute in parallel. To improve efficiency, the thread pool may throttle the threads.
|
|
*/
|
|
|
|
for (index = 0; index < 10; index++)
|
|
SubmitThreadpoolWork(work);
|
|
|
|
WaitForThreadpoolWorkCallbacks(work, FALSE);
|
|
CloseThreadpoolWork(work);
|
|
|
|
printf("Private Thread Pool\n");
|
|
|
|
if (!(pool = CreateThreadpool(NULL)))
|
|
{
|
|
printf("CreateThreadpool failure\n");
|
|
return -1;
|
|
}
|
|
|
|
SetThreadpoolThreadMinimum(pool, 4);
|
|
SetThreadpoolThreadMaximum(pool, 8);
|
|
|
|
InitializeThreadpoolEnvironment(&environment);
|
|
SetThreadpoolCallbackPool(&environment, pool);
|
|
|
|
cleanupGroup = CreateThreadpoolCleanupGroup();
|
|
|
|
if (!cleanupGroup)
|
|
{
|
|
printf("CreateThreadpoolCleanupGroup failure\n");
|
|
return -1;
|
|
}
|
|
|
|
SetThreadpoolCallbackCleanupGroup(&environment, cleanupGroup, NULL);
|
|
|
|
work = CreateThreadpoolWork((PTP_WORK_CALLBACK) test_WorkCallback, "world", &environment);
|
|
|
|
if (!work)
|
|
{
|
|
printf("CreateThreadpoolWork failure\n");
|
|
return -1;
|
|
}
|
|
|
|
for (index = 0; index < 10; index++)
|
|
SubmitThreadpoolWork(work);
|
|
|
|
WaitForThreadpoolWorkCallbacks(work, FALSE);
|
|
|
|
CloseThreadpoolCleanupGroupMembers(cleanupGroup, TRUE, NULL);
|
|
|
|
CloseThreadpoolCleanupGroup(cleanupGroup);
|
|
|
|
DestroyThreadpoolEnvironment(&environment);
|
|
|
|
CloseThreadpoolWork(work);
|
|
CloseThreadpool(pool);
|
|
|
|
return 0;
|
|
}
|