pool allocation. not working. not sure why. will travel back in time...
This commit is contained in:
22
inc/sync.hpp
22
inc/sync.hpp
@@ -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<DWORD>(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) {
|
||||
|
||||
Reference in New Issue
Block a user