time
This commit is contained in:
@@ -611,6 +611,17 @@ typedef struct ThreadContext {
|
||||
LaneCtx lane_ctx;
|
||||
} ThreadContext;
|
||||
|
||||
typedef struct HumanTime {
|
||||
i16 year;
|
||||
u8 month;
|
||||
u8 month_i;
|
||||
u8 date;
|
||||
u8 hour;
|
||||
u8 min;
|
||||
u8 sec;
|
||||
u8 zone;
|
||||
} HumanTime;
|
||||
|
||||
///// HARDCODED GLOBALS
|
||||
global const u64 MAX_u64 = 0xffffffffffffffffull;
|
||||
global const i64 MAX_i64 = 9223372036854775807LL;
|
||||
@@ -627,6 +638,19 @@ global const u8 MAX_u8 = 0xff;
|
||||
#ifndef SQRT_3
|
||||
# define SQRT_3 (1.7320508076)
|
||||
#endif
|
||||
#ifndef ONE_MILLION
|
||||
# define ONE_MILLION (1000000)
|
||||
#endif
|
||||
#ifndef ONE_THOUSAND
|
||||
# define ONE_THOUSAND (1000)
|
||||
#endif
|
||||
#ifndef MICROSECONDS_PER_SECOND
|
||||
# define MICROSECONDS_PER_SECOND ONE_MILLION
|
||||
#endif
|
||||
#ifndef NANOSECONDS_PER_MICROSECOND
|
||||
# define NANOSECONDS_PER_MICROSECOND ONE_THOUSAND
|
||||
#endif
|
||||
|
||||
|
||||
///// CUSTOM ENTRY POINT
|
||||
/* TODO?
|
||||
@@ -732,8 +756,10 @@ fn void* osMemoryReserve(u64 size);
|
||||
fn void osMemoryCommit(void* memory, u64 size);
|
||||
fn void osMemoryDecommit(void* memory, u64 size);
|
||||
fn void osMemoryRelease(void* memory, u64 size);
|
||||
|
||||
fn u64 osTimeMicrosecondsNow();
|
||||
fn void osSleepMicroseconds(u32 t);
|
||||
fn HumanTime osHumanTimeFromMicroseconds(u64 micros);
|
||||
|
||||
// Files
|
||||
fn bool osFileExists(String filename);
|
||||
@@ -808,7 +834,9 @@ typedef struct StringArena {
|
||||
Mutex mutex;
|
||||
} StringArena;
|
||||
|
||||
#define stringChunkListAlloc(a, s) allocStringChunkList(a, s)
|
||||
fn StringChunkList allocStringChunkList(StringArena* a, String string);
|
||||
#define stringChunkListRelease(a, l) releaseStringChunkList(a, l)
|
||||
fn void releaseStringChunkList(StringArena* a, StringChunkList* list);
|
||||
fn String stringChunkToString(Arena* a, StringChunkList list);
|
||||
fn String stringChunkToStringWithPadding(Arena* a, StringChunkList list, u32 extra);
|
||||
|
||||
@@ -27,14 +27,6 @@ fn void osBarrierWait(Barrier barrier) {
|
||||
}
|
||||
|
||||
// Time
|
||||
fn u64 osTimeMicrosecondsNow() {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return ((u64)ts.tv_sec * 1000000) + ((u64)ts.tv_nsec / 1000000);
|
||||
}
|
||||
|
||||
#define MICROSECONDS_PER_SECOND 1000000
|
||||
#define NANOSECONDS_PER_MICROSECOND 1000
|
||||
fn void osSleepMicroseconds(u32 t) {
|
||||
struct timespec ts = { t / MICROSECONDS_PER_SECOND, (t % MICROSECONDS_PER_SECOND)*NANOSECONDS_PER_MICROSECOND };
|
||||
nanosleep(&ts, NULL);
|
||||
|
||||
@@ -27,12 +27,6 @@ fn void osBarrierWait(Barrier barrier) {
|
||||
}
|
||||
|
||||
// Time
|
||||
fn u64 osTimeMicrosecondsNow() {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
|
||||
return ((u64)ts.tv_sec * 1000000) + ((u64)ts.tv_nsec / 1000000);
|
||||
}
|
||||
|
||||
fn void osSleepMicroseconds(u32 t) {
|
||||
usleep(t);
|
||||
}
|
||||
|
||||
@@ -273,3 +273,24 @@ fn bool osFileWriteOpenFile(Resulti64 handle, String data) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Time
|
||||
fn u64 osTimeMicrosecondsNow() {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
return ((u64)ts.tv_sec * MICROSECONDS_PER_SECOND) + ((u64)ts.tv_nsec / NANOSECONDS_PER_MICROSECOND);
|
||||
}
|
||||
|
||||
fn HumanTime osHumanTimeFromMicroseconds(u64 micros) {
|
||||
HumanTime result = {0};
|
||||
time_t secs = (time_t)(micros / 1000000ULL);
|
||||
struct tm t;
|
||||
localtime_r(&secs, &t);
|
||||
result.year = 1900 + t.tm_year;
|
||||
result.month = t.tm_mon + 1;
|
||||
result.month_i = t.tm_mon;
|
||||
result.date = t.tm_mday;
|
||||
result.hour = t.tm_hour;
|
||||
result.min = t.tm_min;
|
||||
result.sec = t.tm_sec;
|
||||
return result;
|
||||
}
|
||||
|
||||
+15
@@ -353,3 +353,18 @@ bool osThreadJoin(Thread handle, u64 endt_us) {
|
||||
}
|
||||
return (wait_result == WAIT_OBJECT_0);
|
||||
}
|
||||
|
||||
fn HumanTime osHumanTimeFromMicroseconds(u64 micros) {
|
||||
HumanTime result = {0};
|
||||
time_t secs = (time_t)(micros / MICROSECONDS_PER_SECOND);
|
||||
struct tm t;
|
||||
localtime_s(&t, &secs);
|
||||
result.year = 1900 + t.tm_year;
|
||||
result.month = t.tm_mon + 1;
|
||||
result.month_i = t.tm_mon;
|
||||
result.date = t.tm_mday
|
||||
result.hour = t.tm_hour;
|
||||
result.min = t.tm_min;
|
||||
result.sec = t.tm_sec;
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user