1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

Destroy all locks before to exit

And use platform-independent functions
where possible.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2010-02-28 12:23:53 +01:00
parent 8286e6ded2
commit 0f50f10327

View file

@ -94,11 +94,10 @@ namespace {
Thread threads[MAX_THREADS];
SplitPoint SplitPointStack[MAX_THREADS][ACTIVE_SPLIT_POINTS_MAX];
Lock MPLock;
Lock MPLock, WaitLock;
#if !defined(_MSC_VER)
pthread_cond_t WaitCond;
pthread_mutex_t WaitLock;
#else
HANDLE SitIdleEvent[MAX_THREADS];
#endif
@ -2665,10 +2664,10 @@ namespace {
threads[threadID].state = THREAD_SLEEPING;
#if !defined(_MSC_VER)
pthread_mutex_lock(&WaitLock);
lock_grab(&WaitLock);
if (AllThreadsShouldSleep || threadID >= ActiveThreads)
pthread_cond_wait(&WaitCond, &WaitLock);
pthread_mutex_unlock(&WaitLock);
lock_release(&WaitLock);
#else
WaitForSingleObject(SitIdleEvent[threadID], INFINITE);
#endif
@ -2723,6 +2722,14 @@ namespace {
// Initialize global locks
lock_init(&MPLock, NULL);
lock_init(&WaitLock, NULL);
#if !defined(_MSC_VER)
pthread_cond_init(&WaitCond, NULL);
#else
for (i = 0; i < MAX_THREADS; i++)
SitIdleEvent[i] = CreateEvent(0, FALSE, FALSE, 0);
#endif
// Initialize SplitPointStack locks
for (i = 0; i < MAX_THREADS; i++)
@ -2732,14 +2739,6 @@ namespace {
lock_init(&(SplitPointStack[i][j].lock), NULL);
}
#if !defined(_MSC_VER)
pthread_mutex_init(&WaitLock, NULL);
pthread_cond_init(&WaitCond, NULL);
#else
for (i = 0; i < MAX_THREADS; i++)
SitIdleEvent[i] = CreateEvent(0, FALSE, FALSE, 0);
#endif
// Will be set just before program exits to properly end the threads
AllThreadsShouldExit = false;
@ -2794,6 +2793,9 @@ namespace {
for (int i = 0; i < MAX_THREADS; i++)
for (int j = 0; j < ACTIVE_SPLIT_POINTS_MAX; j++)
lock_destroy(&(SplitPointStack[i][j].lock));
lock_destroy(&WaitLock);
lock_destroy(&MPLock);
}