mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
add 1usec to differentiate two times
This commit is contained in:
+14
-2
@@ -180,8 +180,20 @@ current_time(mrb_state *mrb)
|
||||
|
||||
tm = mrb_malloc(mrb, sizeof(*tm));
|
||||
#ifdef NO_GETTIMEOFDAY
|
||||
tm->sec = time(NULL);
|
||||
tm->usec = 0;
|
||||
{
|
||||
static time_t last_sec = 0, last_usec = 0;
|
||||
|
||||
tm->sec = time(NULL);
|
||||
if (tm->sec != last_sec) {
|
||||
last_sec = tm->sec;
|
||||
last_usec = 0;
|
||||
}
|
||||
else {
|
||||
/* add 1 usec to differentiate two times */
|
||||
last_usec += 1;
|
||||
}
|
||||
tm->usec = last_usec;
|
||||
}
|
||||
#else
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
Reference in New Issue
Block a user