diff --git a/C/source/.gitignore b/C/source/.gitignore index fff19f3..7ceceb7 100644 --- a/C/source/.gitignore +++ b/C/source/.gitignore @@ -1,7 +1,7 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. -build/* +build # User-specific files *.suo @@ -256,6 +256,7 @@ paket-files/ *.sln.iml target/ cmake-build-* +source.code-* # macOS .DS_Store diff --git a/C/source/CMakeLists.txt b/C/source/CMakeLists.txt index 38d8db8..215898a 100644 --- a/C/source/CMakeLists.txt +++ b/C/source/CMakeLists.txt @@ -8,17 +8,16 @@ set(CMAKE_C_STANDARD 11) aux_source_directory(. DIR_SRCS) add_subdirectory(idgen) - #编译动态库 -#set(LIB_SRC YitIdHelper.h YitIdHelper.c) -#add_library(YitIdGenLib SHARED ${LIB_SRC}) -#target_link_libraries(YitIdGenLib idgen) -#set_target_properties(YitIdGenLib PROPERTIES +# set(LIB_SRC YitIdHelper.h YitIdHelper.c) +# add_library(YitIdGenLib SHARED ${LIB_SRC}) +# target_link_libraries(YitIdGenLib idgen) +# set_target_properties(YitIdGenLib PROPERTIES # LINKER_LANGUAGE C # OUTPUT_NAME "yitidgenc" # PREFIX "") -##编译执行文件 +# 编译执行文件 set(LIB_SRC YitIdHelper.h YitIdHelper.c) add_library(YitIdHelper ${LIB_SRC}) add_executable(YitIdGen main.c) diff --git a/C/source/idgen/IdGenerator.c b/C/source/idgen/IdGenerator.c index b498371..00f94d4 100644 --- a/C/source/idgen/IdGenerator.c +++ b/C/source/idgen/IdGenerator.c @@ -109,7 +109,7 @@ extern void SetOptions(IdGeneratorOptions options) { _idGenerator->NextId = WorkerM2Id; } else { _idGenerator->NextId = WorkerM1Id; - sleep(1); + usleep(500*1000); // 暂停500ms } } diff --git a/C/source/idgen/SnowWorkerM1.c b/C/source/idgen/SnowWorkerM1.c index 82f9855..5534f9b 100644 --- a/C/source/idgen/SnowWorkerM1.c +++ b/C/source/idgen/SnowWorkerM1.c @@ -162,6 +162,7 @@ extern int64_t GetCurrentMicroTime() { extern int64_t GetNextTimeTick(SnowFlakeWorker *worker) { uint64_t tempTimeTicker = GetCurrentTimeTick(worker); while (tempTimeTicker <= worker->_LastTimeTick) { + usleep(1000); // 暂停1ms tempTimeTicker = GetCurrentTimeTick(worker); } return tempTimeTicker;