From 2f3924ee433c995c89fbdad02886b1f0853746ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=B8=8C=E5=A4=B7?= <63851587@qq.com> Date: Wed, 7 Apr 2021 23:50:24 +0800 Subject: [PATCH] =?UTF-8?q?!5=20=E6=9B=B4=E4=B8=A5=E6=A0=BC=E7=9A=84?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=8F=82=E6=95=B0=E9=85=8D=E7=BD=AE=E5=92=8C?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP/php_snowdrift.h | 1 - PHP/snowdrift.c | 9 ++------- PHP/src/snowflake/snowflake.c | 5 ++++- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/PHP/php_snowdrift.h b/PHP/php_snowdrift.h index 22b5d06..82efc5a 100644 --- a/PHP/php_snowdrift.h +++ b/PHP/php_snowdrift.h @@ -54,7 +54,6 @@ ZEND_BEGIN_MODULE_GLOBALS(snowdrift) uint8_t Method; uint64_t BaseTime; uint8_t WorkerId; -uint8_t WorkerIdNum; uint8_t WorkerIdBitLength; uint8_t SeqBitLength; uint32_t MaxSeqNumber; diff --git a/PHP/snowdrift.c b/PHP/snowdrift.c index 656b8a5..628c56a 100644 --- a/PHP/snowdrift.c +++ b/PHP/snowdrift.c @@ -43,11 +43,10 @@ PHP_INI_BEGIN() STD_PHP_INI_ENTRY("snowdrift.Method", "1", PHP_INI_SYSTEM, OnUpdateLongGEZero, Method, zend_snowdrift_globals, snowdrift_globals) STD_PHP_INI_ENTRY("snowdrift.BaseTime", "1582136402000", PHP_INI_SYSTEM, OnUpdateLongGEZero, BaseTime, zend_snowdrift_globals, snowdrift_globals) STD_PHP_INI_ENTRY("snowdrift.WorkerId", "1", PHP_INI_SYSTEM, OnUpdateLongGEZero, WorkerId, zend_snowdrift_globals, snowdrift_globals) -STD_PHP_INI_ENTRY("snowdrift.WorkerIdNum", "63", PHP_INI_SYSTEM, OnUpdateLongGEZero, WorkerIdNum, zend_snowdrift_globals, snowdrift_globals) STD_PHP_INI_ENTRY("snowdrift.WorkerIdBitLength", "6", PHP_INI_SYSTEM, OnUpdateLongGEZero, WorkerIdBitLength, zend_snowdrift_globals, snowdrift_globals) STD_PHP_INI_ENTRY("snowdrift.SeqBitLength", "6", PHP_INI_SYSTEM, OnUpdateLongGEZero, SeqBitLength, zend_snowdrift_globals, snowdrift_globals) STD_PHP_INI_ENTRY("snowdrift.MaxSeqNumber", "0", PHP_INI_SYSTEM, OnUpdateLongGEZero, MaxSeqNumber, zend_snowdrift_globals, snowdrift_globals) -STD_PHP_INI_ENTRY("snowdrift.MinSeqNumber", "0", PHP_INI_SYSTEM, OnUpdateLongGEZero, MinSeqNumber, zend_snowdrift_globals, snowdrift_globals) +STD_PHP_INI_ENTRY("snowdrift.MinSeqNumber", "5", PHP_INI_SYSTEM, OnUpdateLongGEZero, MinSeqNumber, zend_snowdrift_globals, snowdrift_globals) STD_PHP_INI_ENTRY("snowdrift.TopOverCostCount", "2000", PHP_INI_SYSTEM, OnUpdateLongGEZero, TopOverCostCount, zend_snowdrift_globals, snowdrift_globals) PHP_INI_END() @@ -56,16 +55,12 @@ PHP_INI_END() static int snowdrift_init() { wid_num = (-1L << SD_G(WorkerIdBitLength)) ^ -1L; - if (SD_G(WorkerIdNum) < wid_num) - { - wid_num = SD_G(WorkerIdNum); - } shmctx.size = wid_num * sizeof(snowflake); if (shm_alloc(&shmctx) == -1) { return FAILURE; } - if (SD_G(MaxSeqNumber) < SD_G(MinSeqNumber)) + if (SD_G(MaxSeqNumber) != 0 && SD_G(MaxSeqNumber) < SD_G(MinSeqNumber)) { return FAILURE; } diff --git a/PHP/src/snowflake/snowflake.c b/PHP/src/snowflake/snowflake.c index 5a298fb..feebd45 100644 --- a/PHP/src/snowflake/snowflake.c +++ b/PHP/src/snowflake/snowflake.c @@ -43,7 +43,10 @@ void Config(snowflake *flake) flake->BaseTime = flake->BaseTime != 0 ? flake->BaseTime : 1577808000000; flake->_TimestampShift = (uint8_t)(flake->WorkerIdBitLength + flake->SeqBitLength); flake->_CurrentSeqNumber = flake->MinSeqNumber; - return; + if (flake->MaxSeqNumber <= flake->MinSeqNumber) + { + flake->MinSeqNumber = 0; + } } void inline EndOverCostAction(uint64_t useTimeTick, snowflake *flake)