diff options
| author | Yukihiro Matsumoto <[email protected]> | 2012-05-08 01:18:30 +0900 |
|---|---|---|
| committer | Yukihiro Matsumoto <[email protected]> | 2012-05-08 01:18:30 +0900 |
| commit | cad39f25818ad6cab59706bf4ec24d827bdc0cab (patch) | |
| tree | 7d0830bef867a2783712951dce5bd7038ebedab3 /src | |
| parent | aae293a0026b72c433cc9a27c26512c639f3286d (diff) | |
| download | mruby-cad39f25818ad6cab59706bf4ec24d827bdc0cab.tar.gz mruby-cad39f25818ad6cab59706bf4ec24d827bdc0cab.zip | |
add 1usec to differentiate two times
Diffstat (limited to 'src')
| -rw-r--r-- | src/time.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/time.c b/src/time.c index a0e992d87..0d04b58e5 100644 --- a/src/time.c +++ b/src/time.c @@ -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; |
