1
0
mirror of synced 2025-11-06 03:20:55 +08:00

!5 更严格的默认参数配置和校验

This commit is contained in:
微希夷
2021-04-07 23:50:24 +08:00
committed by yitter
parent d2022b0cf9
commit 2f3924ee43
3 changed files with 6 additions and 9 deletions

View File

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

View File

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

View File

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