Skip to content

Commit 0a1baef

Browse files
committed
rt: Remove timer
1 parent a9d28b2 commit 0a1baef

File tree

5 files changed

+26
-127
lines changed

5 files changed

+26
-127
lines changed

mk/rt.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ endif
6363
endif
6464

6565
RUNTIME_CXXS_$(1)_$(2) := \
66-
rt/sync/timer.cpp \
6766
rt/sync/lock_and_signal.cpp \
6867
rt/sync/rust_thread.cpp \
6968
rt/rust_builtin.cpp \

src/rt/rust_builtin.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
/* Foreign builtins. */
1212

1313
#include "rust_util.h"
14-
#include "sync/timer.h"
1514
#include "sync/rust_thread.h"
1615
#include "sync/lock_and_signal.h"
1716
#include "memory_region.h"
@@ -25,6 +24,7 @@
2524

2625
#ifdef __APPLE__
2726
#include <crt_externs.h>
27+
#include <mach/mach_time.h>
2828
#endif
2929

3030
#if !defined(__WIN32__)
@@ -242,10 +242,33 @@ get_time(int64_t *sec, int32_t *nsec) {
242242
}
243243
#endif
244244

245+
const uint64_t ns_per_s = 1000000000LL;
246+
245247
extern "C" CDECL void
246248
precise_time_ns(uint64_t *ns) {
247-
timer t;
248-
*ns = t.time_ns();
249+
250+
#ifdef __APPLE__
251+
uint64_t time = mach_absolute_time();
252+
mach_timebase_info_data_t info = {0, 0};
253+
if (info.denom == 0) {
254+
mach_timebase_info(&info);
255+
}
256+
uint64_t time_nano = time * (info.numer / info.denom);
257+
*ns = time_nano;
258+
#elif __WIN32__
259+
uint64_t ticks_per_s;
260+
QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_s);
261+
if (ticks_per_s == 0LL) {
262+
ticks_per_s = 1LL;
263+
}
264+
uint64_t ticks;
265+
QueryPerformanceCounter((LARGE_INTEGER *)&ticks);
266+
*ns = ((ticks * ns_per_s) / ticks_per_s);
267+
#else
268+
timespec ts;
269+
clock_gettime(CLOCK_MONOTONIC, &ts);
270+
*ns = (ts.tv_sec * ns_per_s + ts.tv_nsec);
271+
#endif
249272
}
250273

251274
struct rust_tm {

src/rt/rust_test_helpers.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// Helper functions used only in tests
1212

1313
#include "rust_util.h"
14-
#include "sync/timer.h"
1514
#include "sync/rust_thread.h"
1615
#include "sync/lock_and_signal.h"
1716
#include "rust_abi.h"

src/rt/sync/timer.cpp

Lines changed: 0 additions & 85 deletions
This file was deleted.

src/rt/sync/timer.h

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)