From 0d18d6d014a4ab8c8e2c8baee1904463ff772607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=B8=8C=E5=A4=B7?= <63851587@qq.com> Date: Mon, 28 Jun 2021 03:49:49 +0000 Subject: [PATCH] =?UTF-8?q?!13=20=E4=BB=A3=E7=A0=81=E5=B0=8F=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20*=20use=20C89=20style=20and=20fix=20perror=20invali?= =?UTF-8?q?d=20*=20Merge=20branch=20'master'=20of=20https://gitee.com/yitt?= =?UTF-8?q?er/idgenerator=20*=20=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=EF=BC=8C=E6=B3=A8=E9=87=8A=E6=8E=89=E4=B8=8D=E7=94=A8=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=20*=20=E5=A2=9E=E5=8A=A0=E7=89=88=E6=9D=83?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=20*=20Merge=20branch=20'master'=20of=20https?= =?UTF-8?q?://gitee.com/yitter/idgenerator=20*=20Merge=20branch=20'master'?= =?UTF-8?q?=20of=20https://gitee.com/yitter/idgenerator=20*=201.php=20exte?= =?UTF-8?q?nsion=20add=20more=20check=20*=20update=20readme=20*=20fix=20mi?= =?UTF-8?q?n=5Fseqnumber=20default=20value=20*=20Merge=20branch=20'master'?= =?UTF-8?q?=20of=20https://gitee.com/yitter/idgenerator=20*=20fmt=20v=20co?= =?UTF-8?q?de=20*=20update=20php&vlang=20readme=20file=20*=20Merge=20branc?= =?UTF-8?q?h=20'master'=20of=20https://gitee.com/yitter/idgenerator=20*=20?= =?UTF-8?q?Merge=20branch=20'master'=20of=20https://gitee.com/yitter/idgen?= =?UTF-8?q?erator=20*=20=E6=9B=B4=E4=B8=A5=E6=A0=BC=E7=9A=84=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E9=85=8D=E7=BD=AE=20*=20fix=20worker=20max=20num=20*?= =?UTF-8?q?=20changed=20property=20num=20named=20wid=5Fnum=20*=20Merge=20b?= =?UTF-8?q?ranch=20'master'=20of=20https://gitee.com/yitter/idgenerator=20?= =?UTF-8?q?*=20=E4=BF=AE=E5=A4=8DMaxSeqNumber=E5=88=A4=E6=96=AD=20*=20Merg?= =?UTF-8?q?e=20branch=20'master'=20of=20https://gitee.com/yitter/idgenerat?= =?UTF-8?q?or=20*=20fix=20init=20return=20*=20Merge=20branch=20'master'=20?= =?UTF-8?q?of=20https://gitee.com/yitter/idgenerator=20*=20add=20README.md?= =?UTF-8?q?=20*=20always=20lock=20*=20fix=20shared=20memory=20addr=20*=20u?= =?UTF-8?q?se=20share=20memory=20*=20fix=20malloc=20*=20add=20make=20file?= =?UTF-8?q?=20*=20add=20php=20ext=20*=20Merge=20branch=20'master'=20of=20h?= =?UTF-8?q?ttps://gitee.com/yitter/idgenerator=20*=20Merge=20branch=20'mas?= =?UTF-8?q?ter'=20of=20https://gitee.com/yitter/idgenerator=20*=20Merge=20?= =?UTF-8?q?branch=20'master'=20of=20https://gitee.com/yitter/idgenerator?= =?UTF-8?q?=20*=20Merge=20branch=20'master'=20of=20https://gitee.com/yitte?= =?UTF-8?q?r/idgenerator=20*=20Merge=20branch=20'master'=20of=20https://gi?= =?UTF-8?q?tee.com/yitter/idgenerator=20*=20use=20lock=20and=20bit=20opera?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP/snowdrift.c | 6 ++++-- PHP/src/snowflake/snowflake.c | 6 ++++-- PHP/src/test.c | 10 ++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/PHP/snowdrift.c b/PHP/snowdrift.c index f3fa147..ad836e4 100644 --- a/PHP/snowdrift.c +++ b/PHP/snowdrift.c @@ -67,7 +67,8 @@ static int snowdrift_init() } bzero(shmctx.addr, wid_num * sizeof(snowflake)); sf = (snowflake *)shmctx.addr; - for (int i = 0; i < wid_num; i++) + int i; + for (i = 0; i < wid_num; i++) { snowflake *tmp = (sf + i); tmp->Method = SD_G(Method); @@ -116,7 +117,8 @@ PHP_METHOD(snowdrift, NextNumId) } snowflake *flake = (sf + wid); array_init(return_value); - for (int i = 0; i < num; i++) + int i; + for (i = 0; i < num; i++) { add_next_index_long(return_value, NextId(flake)); } diff --git a/PHP/src/snowflake/snowflake.c b/PHP/src/snowflake/snowflake.c index f7e0aa1..ff875ea 100644 --- a/PHP/src/snowflake/snowflake.c +++ b/PHP/src/snowflake/snowflake.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "snowflake.h" #include "spinlock.h" @@ -45,7 +46,7 @@ void Config(snowflake *flake) else if (flake->BaseTime < 631123200000 || flake->BaseTime > GetCurrentTime()) { perror("BaseTime error."); - return 0; + exit(1); } // 2.WorkerIdBitLength @@ -278,7 +279,8 @@ uint64_t *NextNumId(snowflake *flake, uint32_t num) { uint64_t *arr = (uint64_t *)malloc(sizeof(uint64_t) * num); spin_lock(&flake->_Lock, pid); - for (uint32_t i = 0; i < num; i++) + uint32_t i; + for (i = 0; i < num; i++) { arr[i] = GetId(flake); } diff --git a/PHP/src/test.c b/PHP/src/test.c index fd5856a..52540f7 100644 --- a/PHP/src/test.c +++ b/PHP/src/test.c @@ -40,7 +40,8 @@ uint64_t containsDuplicate() void run() { - for (int i = 0; i < TOTAL / THREAD; i++) + int i; + for (i = 0; i < TOTAL / THREAD; i++) { arr[__sync_fetch_and_add(&index, 1)] = NextId(flake); } @@ -56,7 +57,8 @@ int main() { // clock_gettime(CLOCK_REALTIME, &t_start); - // for (int i = 0; i < THREAD; i++) + int i; + // for (i = 0; i < THREAD; i++) // { // if (pthread_create(&tid[i], NULL, (void *)run, NULL) != 0) // { @@ -65,7 +67,7 @@ int main() // } // } - // for (int i = 0; i < THREAD; i++) + // for (i = 0; i < THREAD; i++) // { // pthread_join(tid[i], NULL); //等待线程结束 // } @@ -91,7 +93,7 @@ int main() // index = 0; gettimeofday(&t_start, NULL); - for (int i = 0; i < TOTAL; i++) + for (i = 0; i < TOTAL; i++) { NextId(flake); }