|
|
@@ -17,8 +17,8 @@ static uint64_t CalcId(snowflake *flake); |
|
|
|
static uint64_t CalcTurnBackId(snowflake *flake); |
|
|
|
|
|
|
|
int ncpu; |
|
|
|
int spin = 2048; |
|
|
|
int pid = 0; |
|
|
|
uint16_t spin = 2048; |
|
|
|
uint32_t pid = 0; |
|
|
|
|
|
|
|
void Config(snowflake *flake) |
|
|
|
{ |
|
|
@@ -188,34 +188,20 @@ uint64_t inline GetId(snowflake *flake) |
|
|
|
|
|
|
|
uint64_t NextId(snowflake *flake) |
|
|
|
{ |
|
|
|
if (flake->Lock != 0) |
|
|
|
{ |
|
|
|
spin_lock(&flake->_Lock, pid); |
|
|
|
uint64_t id = GetId(flake); |
|
|
|
spin_unlock(&flake->_Lock, pid); |
|
|
|
return id; |
|
|
|
} |
|
|
|
return GetId(flake); |
|
|
|
spin_lock(&flake->_Lock, pid); |
|
|
|
uint64_t id = GetId(flake); |
|
|
|
spin_unlock(&flake->_Lock, pid); |
|
|
|
return id; |
|
|
|
} |
|
|
|
|
|
|
|
uint64_t *NextNumId(snowflake *flake, uint32_t num) |
|
|
|
{ |
|
|
|
uint64_t *arr = (uint64_t *)malloc(sizeof(uint64_t) * num); |
|
|
|
if (flake->Lock != 0) |
|
|
|
spin_lock(&flake->_Lock, pid); |
|
|
|
for (uint32_t i = 0; i < num; i++) |
|
|
|
{ |
|
|
|
spin_lock(&flake->_Lock, pid); |
|
|
|
for (uint32_t i = 0; i < num; i++) |
|
|
|
{ |
|
|
|
arr[i] = GetId(flake); |
|
|
|
} |
|
|
|
spin_unlock(&flake->_Lock, pid); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
for (uint32_t i = 0; i < num; i++) |
|
|
|
{ |
|
|
|
arr[i] = GetId(flake); |
|
|
|
} |
|
|
|
arr[i] = GetId(flake); |
|
|
|
} |
|
|
|
spin_unlock(&flake->_Lock, pid); |
|
|
|
return arr; |
|
|
|
} |