mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
Destroy wait conditions before exiting
We already do this for locks. Also rename SitIdleEvent in WaitCond to be uniform with Lunix naming. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
1fdb436e78
commit
3a564ed5db
2 changed files with 14 additions and 17 deletions
|
@ -27,12 +27,13 @@
|
||||||
# include <pthread.h>
|
# include <pthread.h>
|
||||||
|
|
||||||
typedef pthread_mutex_t Lock;
|
typedef pthread_mutex_t Lock;
|
||||||
|
typedef pthread_cond_t WaitCondition;
|
||||||
|
|
||||||
# define lock_init(x) pthread_mutex_init(x, NULL)
|
# define lock_init(x) pthread_mutex_init(x, NULL)
|
||||||
# define lock_grab(x) pthread_mutex_lock(x)
|
# define lock_grab(x) pthread_mutex_lock(x)
|
||||||
# define lock_release(x) pthread_mutex_unlock(x)
|
# define lock_release(x) pthread_mutex_unlock(x)
|
||||||
# define lock_destroy(x) pthread_mutex_destroy(x)
|
# define lock_destroy(x) pthread_mutex_destroy(x)
|
||||||
|
# define cond_destroy(x) pthread_cond_destroy(x);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
@ -41,11 +42,13 @@ typedef pthread_mutex_t Lock;
|
||||||
#undef WIN32_LEAN_AND_MEAN
|
#undef WIN32_LEAN_AND_MEAN
|
||||||
|
|
||||||
typedef CRITICAL_SECTION Lock;
|
typedef CRITICAL_SECTION Lock;
|
||||||
|
typedef HANDLE WaitCondition;
|
||||||
|
|
||||||
# define lock_init(x) InitializeCriticalSection(x)
|
# define lock_init(x) InitializeCriticalSection(x)
|
||||||
# define lock_grab(x) EnterCriticalSection(x)
|
# define lock_grab(x) EnterCriticalSection(x)
|
||||||
# define lock_release(x) LeaveCriticalSection(x)
|
# define lock_release(x) LeaveCriticalSection(x)
|
||||||
# define lock_destroy(x) DeleteCriticalSection(x)
|
# define lock_destroy(x) DeleteCriticalSection(x)
|
||||||
|
# define cond_destroy(x) CloseHandle(*x);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -96,15 +96,8 @@ namespace {
|
||||||
int ActiveThreads;
|
int ActiveThreads;
|
||||||
volatile bool AllThreadsShouldExit, AllThreadsShouldSleep;
|
volatile bool AllThreadsShouldExit, AllThreadsShouldSleep;
|
||||||
Thread threads[MAX_THREADS];
|
Thread threads[MAX_THREADS];
|
||||||
|
|
||||||
Lock MPLock, WaitLock;
|
Lock MPLock, WaitLock;
|
||||||
|
WaitCondition WaitCond[MAX_THREADS];
|
||||||
#if !defined(_MSC_VER)
|
|
||||||
pthread_cond_t WaitCond[MAX_THREADS];
|
|
||||||
#else
|
|
||||||
HANDLE SitIdleEvent[MAX_THREADS];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -2243,7 +2236,7 @@ split_point_start: // At split points actual search starts from here
|
||||||
pthread_cond_wait(&WaitCond[threadID], &WaitLock);
|
pthread_cond_wait(&WaitCond[threadID], &WaitLock);
|
||||||
lock_release(&WaitLock);
|
lock_release(&WaitLock);
|
||||||
#else
|
#else
|
||||||
WaitForSingleObject(SitIdleEvent[threadID], INFINITE);
|
WaitForSingleObject(WaitCond[threadID], INFINITE);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2306,10 +2299,6 @@ split_point_start: // At split points actual search starts from here
|
||||||
volatile int i;
|
volatile int i;
|
||||||
bool ok;
|
bool ok;
|
||||||
|
|
||||||
#if !defined(_MSC_VER)
|
|
||||||
pthread_t pthread[1];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Initialize global locks
|
// Initialize global locks
|
||||||
lock_init(&MPLock);
|
lock_init(&MPLock);
|
||||||
lock_init(&WaitLock);
|
lock_init(&WaitLock);
|
||||||
|
@ -2318,7 +2307,7 @@ split_point_start: // At split points actual search starts from here
|
||||||
#if !defined(_MSC_VER)
|
#if !defined(_MSC_VER)
|
||||||
pthread_cond_init(&WaitCond[i], NULL);
|
pthread_cond_init(&WaitCond[i], NULL);
|
||||||
#else
|
#else
|
||||||
SitIdleEvent[i] = CreateEvent(0, FALSE, FALSE, 0);
|
WaitCond[i] = CreateEvent(0, FALSE, FALSE, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Initialize splitPoints[] locks
|
// Initialize splitPoints[] locks
|
||||||
|
@ -2343,6 +2332,7 @@ split_point_start: // At split points actual search starts from here
|
||||||
{
|
{
|
||||||
|
|
||||||
#if !defined(_MSC_VER)
|
#if !defined(_MSC_VER)
|
||||||
|
pthread_t pthread[1];
|
||||||
ok = (pthread_create(pthread, NULL, init_thread, (void*)(&i)) == 0);
|
ok = (pthread_create(pthread, NULL, init_thread, (void*)(&i)) == 0);
|
||||||
#else
|
#else
|
||||||
ok = (CreateThread(NULL, 0, init_thread, (LPVOID)(&i), 0, NULL) != NULL);
|
ok = (CreateThread(NULL, 0, init_thread, (LPVOID)(&i), 0, NULL) != NULL);
|
||||||
|
@ -2382,6 +2372,10 @@ split_point_start: // At split points actual search starts from here
|
||||||
|
|
||||||
lock_destroy(&WaitLock);
|
lock_destroy(&WaitLock);
|
||||||
lock_destroy(&MPLock);
|
lock_destroy(&MPLock);
|
||||||
|
|
||||||
|
// Now we can safely destroy the wait conditions
|
||||||
|
for (int i = 0; i < MAX_THREADS; i++)
|
||||||
|
cond_destroy(&WaitCond[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2579,7 +2573,7 @@ split_point_start: // At split points actual search starts from here
|
||||||
pthread_cond_signal(&WaitCond[threadID]);
|
pthread_cond_signal(&WaitCond[threadID]);
|
||||||
pthread_mutex_unlock(&WaitLock);
|
pthread_mutex_unlock(&WaitLock);
|
||||||
#else
|
#else
|
||||||
SetEvent(SitIdleEvent[threadID]);
|
SetEvent(WaitCond[threadID]);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue