From 2da2aa8b4b5a7a82e1463f0ad71fb2dd5b333d67 Mon Sep 17 00:00:00 2001 From: AuroraTea <1352685369@qq.com> Date: Mon, 23 Jan 2023 17:35:48 +0800 Subject: [PATCH 1/2] fix: compatibility of C and C++ // fix: move .h to .c for cpp // static IdGenerator *_idGenerator = NULL; --- C/source/YitIdHelper.h | 7 +++++++ C/source/idgen/IdGenOptions.h | 8 ++++++++ C/source/idgen/IdGenerator.c | 2 ++ C/source/idgen/IdGenerator.h | 4 ---- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/C/source/YitIdHelper.h b/C/source/YitIdHelper.h index ef3f45b..723f2ab 100644 --- a/C/source/YitIdHelper.h +++ b/C/source/YitIdHelper.h @@ -7,6 +7,10 @@ #include "idgen/IdGenOptions.h" #include "idgen/common.h" +#ifdef __cplusplus +extern "C" +{ +#endif TAP_DLLEXPORT extern void TAP_STDCALL SetIdGenerator(IdGeneratorOptions options); @@ -17,3 +21,6 @@ extern void TAP_STDCALL SetWorkerId(uint32_t workerId); TAP_DLLEXPORT extern int64_t TAP_STDCALL NextId(); +#ifdef __cplusplus +} +#endif diff --git a/C/source/idgen/IdGenOptions.h b/C/source/idgen/IdGenOptions.h index deedafc..5d8cb74 100644 --- a/C/source/idgen/IdGenOptions.h +++ b/C/source/idgen/IdGenOptions.h @@ -34,5 +34,13 @@ typedef struct IdGenOptions { } IdGeneratorOptions; +#ifdef __cplusplus +extern "C" +{ +#endif + extern IdGeneratorOptions BuildIdGenOptions(uint32_t workerId); +#ifdef __cplusplus +} +#endif diff --git a/C/source/idgen/IdGenerator.c b/C/source/idgen/IdGenerator.c index d1938ca..cb4f518 100644 --- a/C/source/idgen/IdGenerator.c +++ b/C/source/idgen/IdGenerator.c @@ -9,6 +9,8 @@ #include #include "IdGenerator.h" +static IdGenerator *_idGenerator = NULL; + static inline uint64_t WorkerM1Id() { return WorkerM1NextId(_idGenerator->Worker); diff --git a/C/source/idgen/IdGenerator.h b/C/source/idgen/IdGenerator.h index f9841b7..15b2805 100644 --- a/C/source/idgen/IdGenerator.h +++ b/C/source/idgen/IdGenerator.h @@ -21,10 +21,6 @@ typedef struct IdGenerator { } IdGenerator; - -static IdGenerator *_idGenerator = NULL; - extern IdGenerator *GetIdGenInstance(); extern void SetOptions(IdGeneratorOptions options); - From b69eae7d4f9c32a118bb2c680cefcfba60758f42 Mon Sep 17 00:00:00 2001 From: AuroraTea <1352685369@qq.com> Date: Mon, 23 Jan 2023 17:37:54 +0800 Subject: [PATCH 2/2] chore: move `.gitignore ` to previous level path --- C/{source => }/.gitignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename C/{source => }/.gitignore (100%) diff --git a/C/source/.gitignore b/C/.gitignore similarity index 100% rename from C/source/.gitignore rename to C/.gitignore