Skip to content

Commit 1ab00da

Browse files
committed
---
yaml --- r: 2277 b: refs/heads/master c: 5d3e553 h: refs/heads/master i: 2275: c878108 v: v3
1 parent 3b9903c commit 1ab00da

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: c52fb52fbcb57ef8eb9f2e5782339b9e72cc81f8
2+
refs/heads/master: 5d3e5531412952c556fabb541536bcae34b0ce09

trunk/src/lib/Time.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
native "rust" mod rustrt {
2+
fn get_time(&mutable u32 sec, &mutable u32 usec);
3+
}
4+
5+
type timeval = rec(u32 sec, u32 usec);
6+
7+
fn get_time() -> timeval {
8+
let timeval res = rec(sec=0u32, usec=0u32);
9+
rustrt.get_time(res.sec, res.usec);
10+
ret res;
11+
}
12+

trunk/src/lib/std.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ mod ExtFmt;
7676
mod Box;
7777
mod GetOpts;
7878
mod Term;
79+
mod Time;
7980

8081
// Local Variables:
8182
// mode: rust;

trunk/src/rt/rust_builtin.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

22
#include "rust_internal.h"
33

4+
#if !defined(__WIN32__)
5+
#include <sys/time.h>
6+
#endif
7+
48
/* Native builtins. */
59

610
extern "C" CDECL rust_str*
@@ -508,6 +512,31 @@ rust_ptr_eq(rust_task *task, type_desc *t, rust_box *a, rust_box *b) {
508512
return a == b;
509513
}
510514

515+
#if defined(__WIN32__)
516+
extern "C" CDECL void
517+
get_time(rust_task *task, uint32_t *sec, uint32_t *usec) {
518+
SYSTEMTIME systemTime;
519+
FILETIME fileTime;
520+
GetSystemTime(&systemTime);
521+
if (!SystemTimeToFileTime(&systemTime, &fileTime)) {
522+
task->fail(1);
523+
return;
524+
}
525+
526+
// FIXME: This is probably completely wrong.
527+
*sec = fileTime.dwHighDateTime;
528+
*usec = fileTime.dwLowDateTime;
529+
}
530+
#else
531+
extern "C" CDECL void
532+
get_time(rust_task *task, uint32_t *sec, uint32_t *usec) {
533+
struct timeval tv;
534+
gettimeofday(&tv, NULL);
535+
*sec = tv.tv_sec;
536+
*usec = tv.tv_usec;
537+
}
538+
#endif
539+
511540
//
512541
// Local Variables:
513542
// mode: C++

trunk/src/rt/rustrt.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ debug_tag
88
debug_trap
99
debug_tydesc
1010
do_gc
11+
get_time
1112
last_os_error
1213
rand_free
1314
rand_new

0 commit comments

Comments
 (0)