| 50 | |
| 51 | |
| 52 | ThreadPool::~ThreadPool() |
| 53 | { |
| 54 | WaitDone(); |
| 55 | Closing=true; |
| 56 | |
| 57 | #ifdef _WIN_ALL |
| 58 | ReleaseSemaphore(QueuedTasksCnt,ASIZE(TaskQueue),NULL); |
| 59 | #elif defined(_UNIX) |
| 60 | // Threads still can access QueuedTasksCnt for a short time after WaitDone(), |
| 61 | // so lock is required. We would occassionally hang without it. |
| 62 | pthread_mutex_lock(&QueuedTasksCntMutex); |
| 63 | QueuedTasksCnt+=ASIZE(TaskQueue); |
| 64 | pthread_mutex_unlock(&QueuedTasksCntMutex); |
| 65 | |
| 66 | pthread_cond_broadcast(&QueuedTasksCntCond); |
| 67 | #endif |
| 68 | |
| 69 | for(uint I=0;I<ThreadsCreatedCount;I++) |
| 70 | { |
| 71 | #ifdef _WIN_ALL |
| 72 | // Waiting until the thread terminates. |
| 73 | CWaitForSingleObject(ThreadHandles[I]); |
| 74 | #endif |
| 75 | // Close the thread handle. In Unix it results in pthread_join call, |
| 76 | // which also waits for thread termination. |
| 77 | ThreadClose(ThreadHandles[I]); |
| 78 | } |
| 79 | |
| 80 | CriticalSectionDelete(&CritSection); |
| 81 | #ifdef _WIN_ALL |
| 82 | CloseHandle(QueuedTasksCnt); |
| 83 | CloseHandle(NoneActive); |
| 84 | #elif defined(_UNIX) |
| 85 | pthread_cond_destroy(&AnyActiveCond); |
| 86 | pthread_mutex_destroy(&AnyActiveMutex); |
| 87 | pthread_cond_destroy(&QueuedTasksCntCond); |
| 88 | pthread_mutex_destroy(&QueuedTasksCntMutex); |
| 89 | #endif |
| 90 | } |
| 91 | |
| 92 | |
| 93 | void ThreadPool::CreateThreads() |
nothing calls this directly
no test coverage detected