diff --git a/inc/sync.h b/inc/sync.h index 593993d..aa4b9b1 100644 --- a/inc/sync.h +++ b/inc/sync.h @@ -15,9 +15,15 @@ typedef LARGE_INTEGER TimeSpan; typedef DWORD (WINAPI *ThreadFunc)(_In_ LPVOID lpParameter); typedef LPVOID ThreadArg; -const TimeSpan infinite_ts = LLONG_MAX; -static const LARGE_INTEGER freq; -QueryPerformanceFrequency(&freq); +const TimeSpan infinite_ts = { .QuadPart = LLONG_MAX }; + +LARGE_INTEGER _init_freq() { + LARGE_INTEGER freq; + QueryPerformanceFrequency(&freq); + return freq; +} + +static LARGE_INTEGER freq = _init_freq(); #endif Thread make_thread(ThreadFunc t, ThreadArg a); @@ -60,7 +66,7 @@ Thread make_thread(ThreadFunc f, ThreadArg a) { } void join(Thread t) { - WaitForSingleObject(t, infinite_ts); + WaitForSingleObject(t, INFINITE); } Mutex make_mutex() { @@ -92,7 +98,11 @@ ConditionVar make_condition_var() { } void wait(ConditionVar &c, Mutex &m, TimeSpan ts) { - SleepConditionVariableCS(&c, &m, ts); + if (ts.QuadPart == infinite_ts.QuadPart) { + SleepConditionVariableCS(&c, &m, INFINITE); + } else { + SleepConditionVariableCS(&c, &m, static_cast(to_ms(ts))); + } } void wake_one(ConditionVar &c) { @@ -112,7 +122,7 @@ Semaphore make_semaphore(int initial, int max) { } void wait(Semaphore &s) { - WaitForSingleObject(s, infinite_ts); + WaitForSingleObject(s, INFINITE); } void post(Semaphore &s) { diff --git a/src/genetic.cpp b/src/genetic.cpp index f89472c..63d7870 100644 --- a/src/genetic.cpp +++ b/src/genetic.cpp @@ -5,8 +5,8 @@ #include #include +#include "sync.h" #include "genetic.h" -#include "pthread.h" #include "rand.h" #define NUM_QUEUE_RETRIES 10