Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cm-util.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@

#include "cm-util.h"

time_t _program_start_secs = 0;
10 changes: 4 additions & 6 deletions cm-util.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#pragma once

#include <sys/time.h>
#include <time.h>
#include <string.h>

extern time_t _program_start_secs;

#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)

Expand All @@ -18,9 +16,9 @@ do { ACCESS_ONCE(x) = (val); } while (0)

static inline int
get_time_in_milliseconds() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec-_program_start_secs) * 1000 + tv.tv_usec / 1000;
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (int)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
}

// normalize double to range 0-1
Expand Down