remove pthread.h ref in genetic.cpp. copy over actual sync changes that were missing from live plotter
This commit is contained in:
22
inc/sync.h
22
inc/sync.h
@@ -15,9 +15,15 @@ typedef LARGE_INTEGER TimeSpan;
|
|||||||
typedef DWORD (WINAPI *ThreadFunc)(_In_ LPVOID lpParameter);
|
typedef DWORD (WINAPI *ThreadFunc)(_In_ LPVOID lpParameter);
|
||||||
typedef LPVOID ThreadArg;
|
typedef LPVOID ThreadArg;
|
||||||
|
|
||||||
const TimeSpan infinite_ts = LLONG_MAX;
|
const TimeSpan infinite_ts = { .QuadPart = LLONG_MAX };
|
||||||
static const LARGE_INTEGER freq;
|
|
||||||
QueryPerformanceFrequency(&freq);
|
LARGE_INTEGER _init_freq() {
|
||||||
|
LARGE_INTEGER freq;
|
||||||
|
QueryPerformanceFrequency(&freq);
|
||||||
|
return freq;
|
||||||
|
}
|
||||||
|
|
||||||
|
static LARGE_INTEGER freq = _init_freq();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Thread make_thread(ThreadFunc t, ThreadArg a);
|
Thread make_thread(ThreadFunc t, ThreadArg a);
|
||||||
@@ -60,7 +66,7 @@ Thread make_thread(ThreadFunc f, ThreadArg a) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void join(Thread t) {
|
void join(Thread t) {
|
||||||
WaitForSingleObject(t, infinite_ts);
|
WaitForSingleObject(t, INFINITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mutex make_mutex() {
|
Mutex make_mutex() {
|
||||||
@@ -92,7 +98,11 @@ ConditionVar make_condition_var() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void wait(ConditionVar &c, Mutex &m, TimeSpan ts) {
|
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) {
|
void wake_one(ConditionVar &c) {
|
||||||
@@ -112,7 +122,7 @@ Semaphore make_semaphore(int initial, int max) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void wait(Semaphore &s) {
|
void wait(Semaphore &s) {
|
||||||
WaitForSingleObject(s, infinite_ts);
|
WaitForSingleObject(s, INFINITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void post(Semaphore &s) {
|
void post(Semaphore &s) {
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "sync.h"
|
||||||
#include "genetic.h"
|
#include "genetic.h"
|
||||||
#include "pthread.h"
|
|
||||||
#include "rand.h"
|
#include "rand.h"
|
||||||
|
|
||||||
#define NUM_QUEUE_RETRIES 10
|
#define NUM_QUEUE_RETRIES 10
|
||||||
|
|||||||
Reference in New Issue
Block a user