remove pthread.h ref in genetic.cpp. copy over actual sync changes that were missing from live plotter

This commit is contained in:
2025-09-07 14:56:33 -05:00
parent 17e6ac5f83
commit 905ca1e43a
2 changed files with 17 additions and 7 deletions

View File

@@ -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) {

View File

@@ -5,8 +5,8 @@
#include <variant>
#include <vector>
#include "sync.h"
#include "genetic.h"
#include "pthread.h"
#include "rand.h"
#define NUM_QUEUE_RETRIES 10