1
0
mirror of synced 2025-12-13 00:28:26 +08:00

auto commit

This commit is contained in:
yitter
2021-03-28 15:41:39 +08:00
parent 24ca0db2c5
commit 27b527993e
5 changed files with 24 additions and 18 deletions

View File

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

View File

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

View File

@@ -4,8 +4,8 @@
*/
#pragma once
#include "IdGenOptions.h"
#include "common.h"
#include "idgen/IdGenOptions.h"
#include "idgen/common.h"
TAP_DLLEXPORT

View File

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

View File

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