stellar support monotonic time and real time

This commit is contained in:
luwenpeng
2024-05-16 10:13:43 +08:00
parent 1ef82a0c6a
commit fdc65067b2
30 changed files with 201 additions and 124 deletions

View File

@@ -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) |