MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / ThreadPool

Method ThreadPool

Libraries/unrar/threadpool.cpp:10–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#endif
9
10ThreadPool::ThreadPool(uint MaxThreads)
11{
12 MaxAllowedThreads = MaxThreads;
13 if (MaxAllowedThreads>MaxPoolThreads)
14 MaxAllowedThreads=MaxPoolThreads;
15 if (MaxAllowedThreads==0)
16 MaxAllowedThreads=1;
17
18 ThreadsCreatedCount=0;
19
20 // If we have more threads than queue size, we'll hang on pool destroying,
21 // not releasing all waiting threads.
22 if (MaxAllowedThreads>ASIZE(TaskQueue))
23 MaxAllowedThreads=ASIZE(TaskQueue);
24
25 Closing=false;
26
27 bool Success = CriticalSectionCreate(&CritSection);
28#ifdef _WIN_ALL
29 QueuedTasksCnt=CreateSemaphore(NULL,0,ASIZE(TaskQueue),NULL);
30 NoneActive=CreateEvent(NULL,TRUE,TRUE,NULL);
31 Success=Success && QueuedTasksCnt!=NULL && NoneActive!=NULL;
32#elif defined(_UNIX)
33 AnyActive = false;
34 QueuedTasksCnt = 0;
35 Success=Success && pthread_cond_init(&AnyActiveCond,NULL)==0 &&
36 pthread_mutex_init(&AnyActiveMutex,NULL)==0 &&
37 pthread_cond_init(&QueuedTasksCntCond,NULL)==0 &&
38 pthread_mutex_init(&QueuedTasksCntMutex,NULL)==0;
39#endif
40 if (!Success)
41 {
42 ErrHandler.GeneralErrMsg(L"\nThread pool initialization failed.");
43 ErrHandler.Exit(RARX_FATAL);
44 }
45
46 QueueTop = 0;
47 QueueBottom = 0;
48 ActiveThreads = 0;
49}
50
51
52ThreadPool::~ThreadPool()

Callers

nothing calls this directly

Calls 3

CriticalSectionCreateFunction · 0.85
GeneralErrMsgMethod · 0.80
ExitMethod · 0.80

Tested by

no test coverage detected