VOID CloseThreadpool(PTP_POOL ptpp) { #ifdef _WIN32 module_init(); if (pCloseThreadpool) pCloseThreadpool(ptpp); #else SetEvent(ptpp->TerminateEvent); ArrayList_Free(ptpp->Threads); Queue_Free(ptpp->PendingQueue); CountdownEvent_Free(ptpp->WorkComplete); CloseHandle(ptpp->TerminateEvent); if (ptpp == &DEFAULT_POOL) { ptpp->Threads = NULL; ptpp->PendingQueue = NULL; ptpp->WorkComplete = NULL; ptpp->TerminateEvent = NULL; } else { free(ptpp); } #endif }
VOID winpr_CloseThreadpool(PTP_POOL ptpp) { #ifdef _WIN32 InitOnceExecuteOnce(&init_once_module, init_module, NULL, NULL); if (pCloseThreadpool) { pCloseThreadpool(ptpp); return; } #endif SetEvent(ptpp->TerminateEvent); ArrayList_Free(ptpp->Threads); Queue_Free(ptpp->PendingQueue); CountdownEvent_Free(ptpp->WorkComplete); CloseHandle(ptpp->TerminateEvent); if (ptpp == &DEFAULT_POOL) { ptpp->Threads = NULL; ptpp->PendingQueue = NULL; ptpp->WorkComplete = NULL; ptpp->TerminateEvent = NULL; } else { free(ptpp); } }
static BOOL InitializeThreadpool(PTP_POOL pool) { int index; HANDLE thread; if (pool->Threads) return TRUE; pool->Minimum = 0; pool->Maximum = 500; if (!(pool->PendingQueue = Queue_New(TRUE, -1, -1))) goto fail_queue_new; if (!(pool->WorkComplete = CountdownEvent_New(0))) goto fail_countdown_event; if (!(pool->TerminateEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) goto fail_terminate_event; if (!(pool->Threads = ArrayList_New(TRUE))) goto fail_thread_array; pool->Threads->object.fnObjectFree = threads_close; for (index = 0; index < 4; index++) { if (!(thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) thread_pool_work_func, (void*) pool, 0, NULL))) { goto fail_create_threads; } if (ArrayList_Add(pool->Threads, thread) < 0) goto fail_create_threads; } return TRUE; fail_create_threads: SetEvent(pool->TerminateEvent); ArrayList_Free(pool->Threads); pool->Threads = NULL; fail_thread_array: CloseHandle(pool->TerminateEvent); pool->TerminateEvent = NULL; fail_terminate_event: CountdownEvent_Free(pool->WorkComplete); pool->WorkComplete = NULL; fail_countdown_event: Queue_Free(pool->PendingQueue); pool->WorkComplete = NULL; fail_queue_new: return FALSE; }