Refactor the session manager using session transformation 2D array & Update test case

This commit is contained in:
luwenpeng
2024-03-14 10:56:09 +08:00
parent 639614622b
commit ce00122557
47 changed files with 3403 additions and 3563 deletions

View File

@@ -1,3 +1,4 @@
#include <time.h>
#include <string.h>
#include "id_generator.h"
@@ -55,14 +56,18 @@ int id_generator_init(uint8_t device_base, uint8_t device_offset)
* | 1bit | 12bit device_id | 8bit thread_id | 28bit timestamp in sec | 15bit sequence per thread |
* +------+------------------+----------------+------------------------+---------------------------+
*/
uint64_t id_generator_alloc(uint64_t now_sec, uint64_t thread_index)
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 thread_index = stellar_get_current_thread_index();
uint64_t global_id = 0;
uint64_t id_per_thread = (global_id_generator.thread_volatile[thread_index]++) % MAX_ID_PER_THREAD;
uint64_t id_base_time = now_sec % MAX_ID_BASE_TIME;
uint64_t id_base_time = ts.tv_sec % MAX_ID_BASE_TIME;
global_id = (global_id_generator.device_id << 51) |
(thread_index << 43) |
(id_base_time << 15) |