Skip to content

Commit 0a6c4ab

Browse files
committed
* fix get_current_ts with actuall millisecond resolution than seconds.
1 parent c0fa103 commit 0a6c4ab

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"snowid_checkpoint.h": "c",
2222
"unistd.h": "c",
2323
"__locale": "c",
24-
"if_dl.h": "c"
24+
"if_dl.h": "c",
25+
"ctime": "c"
2526
}
2627
}

snowid_util.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <stdio.h>
3131
#include <stdlib.h>
3232
#include <string.h>
33-
#include <time.h>
33+
#include <sys/time.h>
3434
#include <sys/socket.h>
3535
#include <sys/types.h>
3636

@@ -101,19 +101,17 @@ bool get_hw_addr_as_binary(uint64_t *workerid, char *interface)
101101

102102
bool get_current_ts(uint64_t *result)
103103
{
104-
time_t t;
104+
struct timeval now;
105105

106106
if (result == NULL) {
107107
return false;
108108
}
109109

110-
t = time(NULL);
111-
112-
if (t == (time_t)-1) {
110+
if (gettimeofday(&now, NULL) == -1) {
113111
return false;
114112
}
115113

116-
*result = (uint64_t)t;
114+
*result = (uint64_t)((now.tv_sec * 1000) + (now.tv_usec / 1000));
117115

118116
return true;
119117
}

0 commit comments

Comments
 (0)