draft complete. debugging
This commit is contained in:
62
inc/sync.h
62
inc/sync.h
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "windows.h"
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace sync {
|
||||
@@ -28,6 +28,7 @@ static LARGE_INTEGER freq = _init_freq();
|
||||
|
||||
Thread make_thread(ThreadFunc t, ThreadArg a);
|
||||
void join(Thread t);
|
||||
void sleep(TimeSpan ts);
|
||||
|
||||
Mutex make_mutex();
|
||||
void lock(Mutex &m);
|
||||
@@ -52,11 +53,14 @@ TimeSpan from_min(double minutes);
|
||||
TimeSpan from_hours(double hours);
|
||||
TimeSpan now();
|
||||
TimeSpan operator-(const TimeSpan &a, const TimeSpan &b);
|
||||
TimeSpan operator+(const TimeSpan &a, const TimeSpan &b);
|
||||
TimeSpan operator*(const TimeSpan &a, const TimeSpan &b);
|
||||
TimeSpan operator/(const TimeSpan &a, const TimeSpan &b);
|
||||
|
||||
double to_ms(TimeSpan &sp);
|
||||
double to_s(TimeSpan &sp);
|
||||
double to_min(TimeSpan &sp);
|
||||
double to_hours(TimeSpan &sp);
|
||||
double to_ms(TimeSpan &ts);
|
||||
double to_s(TimeSpan &ts);
|
||||
double to_min(TimeSpan &ts);
|
||||
double to_hours(TimeSpan &ts);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -69,6 +73,10 @@ void join(Thread t) {
|
||||
WaitForSingleObject(t, INFINITE);
|
||||
}
|
||||
|
||||
void sleep(TimeSpan ts) {
|
||||
Sleep(static_cast<DWORD>(to_ms(ts)));
|
||||
}
|
||||
|
||||
Mutex make_mutex() {
|
||||
Mutex m;
|
||||
InitializeCriticalSection(&m);
|
||||
@@ -135,25 +143,25 @@ void dispose(Semaphore &s) {
|
||||
|
||||
TimeSpan from_ms(double milliseconds) {
|
||||
TimeSpan ts;
|
||||
ts.QuadPart = static_cast<int64_t>(milliseconds/1000.0)*freq.QuadPart;
|
||||
ts.QuadPart = static_cast<LONGLONG>(milliseconds/1000.0)*freq.QuadPart;
|
||||
return ts;
|
||||
}
|
||||
|
||||
TimeSpan from_s(double seconds) {
|
||||
TimeSpan ts;
|
||||
ts.QuadPart = static_cast<int64_t>(seconds)*freq.QuadPart;
|
||||
ts.QuadPart = static_cast<LONGLONG>(seconds)*freq.QuadPart;
|
||||
return ts;
|
||||
}
|
||||
|
||||
TimeSpan from_min(double minutes) {
|
||||
TimeSpan ts;
|
||||
ts.QuadPart = static_cast<int64_t>(minutes*60.0)*freq.QuadPart;
|
||||
ts.QuadPart = static_cast<LONGLONG>(minutes*60.0)*freq.QuadPart;
|
||||
return ts;
|
||||
}
|
||||
|
||||
TimeSpan from_hours(double hours) {
|
||||
TimeSpan ts;
|
||||
ts.QuadPart = static_cast<int64_t>(hours*60.0*60.0)*freq.QuadPart;
|
||||
ts.QuadPart = static_cast<LONGLONG>(hours*60.0*60.0)*freq.QuadPart;
|
||||
return ts;
|
||||
}
|
||||
|
||||
@@ -163,26 +171,44 @@ TimeSpan now() {
|
||||
return ts;
|
||||
}
|
||||
|
||||
TimeSpan operator-(const TimeSpan &a, TimeSpan &b) {
|
||||
TimeSpan operator-(const TimeSpan &a, const TimeSpan &b) {
|
||||
TimeSpan ts;
|
||||
ts.QuadPart = a.QuadPart - b.QuadPart;
|
||||
return ts;
|
||||
}
|
||||
|
||||
double to_ms(TimeSpan &sp) {
|
||||
return static_cast<double>(sp.QuadPart*1000)/static_cast<double>(freq.QuadPart);
|
||||
TimeSpan operator+(const TimeSpan &a, const TimeSpan &b) {
|
||||
TimeSpan ts;
|
||||
ts.QuadPart = a.QuadPart + b.QuadPart;
|
||||
return ts;
|
||||
}
|
||||
|
||||
double to_s(TimeSpan &sp) {
|
||||
return static_cast<double>(sp.QuadPart)/static_cast<double>(freq.QuadPart);
|
||||
TimeSpan operator*(const TimeSpan &a, const TimeSpan &b) {
|
||||
TimeSpan ts;
|
||||
ts.QuadPart = a.QuadPart * b.QuadPart;
|
||||
return ts;
|
||||
}
|
||||
|
||||
double to_min(TimeSpan &sp) {
|
||||
return static_cast<double>(sp.QuadPart)/static_cast<double>(freq.QuadPart*60);
|
||||
TimeSpan operator/(const TimeSpan &a, const TimeSpan &b) {
|
||||
TimeSpan ts;
|
||||
ts.QuadPart = a.QuadPart / b.QuadPart;
|
||||
return ts;
|
||||
}
|
||||
|
||||
double to_hours(TimeSpan &sp) {
|
||||
return static_cast<double>(sp.QuadPart)/static_cast<double>(freq.QuadPart*60*60);
|
||||
double to_ms(TimeSpan &ts) {
|
||||
return static_cast<double>(ts.QuadPart*1000)/static_cast<double>(freq.QuadPart);
|
||||
}
|
||||
|
||||
double to_s(TimeSpan &ts) {
|
||||
return static_cast<double>(ts.QuadPart)/static_cast<double>(freq.QuadPart);
|
||||
}
|
||||
|
||||
double to_min(TimeSpan &ts) {
|
||||
return static_cast<double>(ts.QuadPart)/static_cast<double>(freq.QuadPart*60);
|
||||
}
|
||||
|
||||
double to_hours(TimeSpan &ts) {
|
||||
return static_cast<double>(ts.QuadPart)/static_cast<double>(freq.QuadPart*60*60);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user