Skip to content

Commit

Permalink
Move next ID initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Aug 3, 2024
1 parent 25c7662 commit de3d8d4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/PosixSemaphore.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ public static function create(int $maxLocks, int $permissions = 0600): self
throw new \Error('Number of locks must be greater than 0, got ' . $maxLocks);
}

if (self::$nextId === 0) {
self::$nextId = \random_int(1, self::MAX_ID);
}

\set_error_handler(static function (int $errno, string $errstr): bool {
if (!\str_contains($errstr, 'No space left on device') && \str_contains($errstr, 'Failed for key')) {
return true;
Expand Down Expand Up @@ -77,6 +73,10 @@ public static function create(int $maxLocks, int $permissions = 0600): self

private static function getNextId(): int
{
if (self::$nextId === 0) {
return self::$nextId = \random_int(1, self::MAX_ID);
}

return self::$nextId = self::$nextId % self::MAX_ID + 1;
}

Expand Down

0 comments on commit de3d8d4

Please sign in to comment.