From cad39f25818ad6cab59706bf4ec24d827bdc0cab Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 8 May 2012 01:18:30 +0900 Subject: add 1usec to differentiate two times --- src/time.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src') 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; -- cgit v1.2.3