auto commit
This commit is contained in:
@@ -18,11 +18,10 @@ add_subdirectory(idgen)
|
||||
# PREFIX "")
|
||||
|
||||
##编译执行文件
|
||||
#set(LIB_SRC idgen/YitIdHelper.h idgen/YitIdHelper.c)
|
||||
#add_library(YitIdHelper ${LIB_SRC})
|
||||
|
||||
set(LIB_SRC YitIdHelper.h YitIdHelper.c)
|
||||
add_library(YitIdHelper ${LIB_SRC})
|
||||
add_executable(YitIdGen main.c)
|
||||
#target_link_libraries(YitIdGen YitIdHelper)
|
||||
target_link_libraries(YitIdGen YitIdHelper)
|
||||
target_link_libraries(YitIdGen idgen)
|
||||
|
||||
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "YitIdHelper.h"
|
||||
#include "IdGenerator.h"
|
||||
#include "idgen/IdGenerator.h"
|
||||
|
||||
extern void SetIdGenerator(IdGeneratorOptions options) {
|
||||
SetOptions(options);
|
||||
}
|
||||
|
||||
extern void SetWorkerId(uint32_t workerId) {
|
||||
// IdGeneratorOptions options = BuildIdGenOptions(workerId);
|
||||
IdGeneratorOptions options = BuildIdGenOptions(workerId);
|
||||
// SetOptions(options);
|
||||
SetIdGenerator(options);
|
||||
}
|
||||
@@ -4,8 +4,8 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "IdGenOptions.h"
|
||||
#include "common.h"
|
||||
#include "idgen/IdGenOptions.h"
|
||||
#include "idgen/common.h"
|
||||
|
||||
|
||||
TAP_DLLEXPORT
|
||||
@@ -113,6 +113,13 @@ static inline uint64_t CalcTurnBackId(SnowFlakeWorker *worker) {
|
||||
extern SnowFlakeWorker *NewSnowFlakeWorker() {
|
||||
SnowFlakeWorker *worker = (SnowFlakeWorker *) malloc(sizeof(SnowFlakeWorker));
|
||||
worker->_IsOverCost = false;
|
||||
worker->_LastTimeTick = 0;
|
||||
worker->_TurnBackTimeTick = 0;
|
||||
worker->_TurnBackIndex = 0;
|
||||
worker->_OverCostCountInOneTerm = 0;
|
||||
worker->_GenCountInOneTerm = 0;
|
||||
worker->_TermIndex = 0;
|
||||
|
||||
return worker;
|
||||
}
|
||||
|
||||
@@ -124,15 +131,15 @@ extern uint64_t WorkerM1NextId(SnowFlakeWorker *worker) {
|
||||
}
|
||||
|
||||
extern uint64_t GetCurrentTimeTick(SnowFlakeWorker *worker) {
|
||||
static struct timeval tv;
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return (uint64_t)(tv.tv_sec * 1000 + tv.tv_usec / 1000 - worker->BaseTime);
|
||||
return ((uint64_t) tv.tv_sec * 1000 + tv.tv_usec / 1000 - worker->BaseTime);
|
||||
}
|
||||
|
||||
extern uint64_t GetCurrentTime() {
|
||||
static struct timeval tv;
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return (uint64_t)(tv.tv_sec * 1000 + tv.tv_usec / 1000);
|
||||
return ((uint64_t) (tv.tv_sec)) * 1000 + tv.tv_usec / 1000;
|
||||
|
||||
//static struct timeb t1;
|
||||
// ftime(&t1);
|
||||
@@ -140,9 +147,9 @@ extern uint64_t GetCurrentTime() {
|
||||
}
|
||||
|
||||
extern uint64_t GetCurrentMicroTime() {
|
||||
static struct timeval tv;
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return (uint64_t)(tv.tv_sec * 1000000 + tv.tv_usec);
|
||||
return ((uint64_t) tv.tv_sec * 1000000 + tv.tv_usec);
|
||||
}
|
||||
|
||||
extern uint64_t GetNextTimeTick(SnowFlakeWorker *worker) {
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
#include <stdbool.h>
|
||||
#include "idgen/SnowWorkerM1.h"
|
||||
#include "idgen/IdGenerator.h"
|
||||
#include "idgen/YitIdHelper.h"
|
||||
#include "YitIdHelper.h"
|
||||
|
||||
|
||||
const int GenIdCount = 50000;
|
||||
const bool multiThread = true;
|
||||
const bool multiThread = false;
|
||||
const int threadCount = 50;
|
||||
const int method = 1;
|
||||
|
||||
@@ -24,7 +24,7 @@ void RunMultiThread() {
|
||||
//int64_t start = GetCurrentMicroTime();
|
||||
for (int i = 0; i < GenIdCount / threadCount; i++) {
|
||||
int64_t id = NextId();
|
||||
printf("生成ID: %ld\n", id);
|
||||
printf("生成ID: %D\n", id);
|
||||
}
|
||||
|
||||
int64_t end = GetCurrentMicroTime();
|
||||
|
||||
Reference in New Issue
Block a user