stellar support monotonic time and real time
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "macro.h"
|
||||
#include "times.h"
|
||||
#include "stellar_priv.h"
|
||||
#include "id_generator.h"
|
||||
|
||||
@@ -62,13 +63,11 @@ uint64_t id_generator_alloc()
|
||||
#define MAX_ID_PER_THREAD (32768)
|
||||
#define MAX_ID_BASE_TIME (268435456L)
|
||||
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_REALTIME, &ts); // must be realtime
|
||||
uint64_t thr_idx = stellar_get_current_thread_index();
|
||||
|
||||
uint64_t global_id = 0;
|
||||
uint64_t id_per_thread = (global_id_generator.thread_volatile[thr_idx]++) % MAX_ID_PER_THREAD;
|
||||
uint64_t id_base_time = ts.tv_sec % MAX_ID_BASE_TIME;
|
||||
uint64_t id_base_time = stellar_get_real_time_sec() % MAX_ID_BASE_TIME;
|
||||
global_id = (global_id_generator.device_id << 51) |
|
||||
(thr_idx << 43) |
|
||||
(id_base_time << 15) |
|
||||
|
||||
Reference in New Issue
Block a user