Refactor the session manager using session transformation 2D array & Update test case
This commit is contained in:
@@ -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) |
|
||||
|
||||
Reference in New Issue
Block a user