Skip to content

Commit

Permalink
Lock Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
codercms committed Aug 30, 2020
1 parent ed8150e commit 4571103
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function unlock(): void
$queue = $this->queue;
$this->queue = [];

foreach ($queue as $key => $cid) {
foreach ($queue as $cid => $val) {
Coroutine::resume($cid);
}
}
Expand All @@ -72,7 +72,9 @@ private function blockWithTimeout(float $timeout): bool

$this->block();

if (!$timedOut) {
if ($timedOut) {
unset($this->queue[$cid]);
} else {
Timer::clear($tid);
}

Expand All @@ -81,7 +83,7 @@ private function blockWithTimeout(float $timeout): bool

private function block(): void
{
$this->queue[] = Coroutine::getCid();
$this->queue[Coroutine::getCid()] = null;
Coroutine::yield();
}
}

0 comments on commit 4571103

Please sign in to comment.