Skip to content

Commit

Permalink
Rename property to avoid JIT bug
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Oct 22, 2023
1 parent 0fe2d31 commit 40292c1
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/EventLoop/Driver/UvDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function isSupported(): bool
/** @var array<string, resource> */
private array $events = [];
/** @var array<int, array<array-key, DriverCallback>> */
private array $callbacks = [];
private array $uvCallbacks = [];
/** @var array<int, resource> */
private array $streams = [];
private readonly \Closure $ioCallback;
Expand All @@ -38,7 +38,7 @@ public function __construct()
$this->handle = \uv_loop_new();

$this->ioCallback = function ($event, $status, $events, $resource): void {
$callbacks = $this->callbacks[(int) $event];
$callbacks = $this->uvCallbacks[(int) $event];

// Invoke the callback on errors, as this matches behavior with other loop back-ends.
// Re-enable callback as libuv disables the callback on non-zero status.
Expand Down Expand Up @@ -66,15 +66,15 @@ public function __construct()
};

$this->timerCallback = function ($event): void {
$callback = $this->callbacks[(int) $event][0];
$callback = $this->uvCallbacks[(int) $event][0];

\assert($callback instanceof TimerCallback);

$this->enqueueCallback($callback);
};

$this->signalCallback = function ($event): void {
$callback = $this->callbacks[(int) $event][0];
$callback = $this->uvCallbacks[(int) $event][0];

$this->enqueueCallback($callback);
};
Expand All @@ -94,16 +94,16 @@ public function cancel(string $callbackId): void
$event = $this->events[$callbackId];
$eventId = (int) $event;

if (isset($this->callbacks[$eventId][0])) { // All except IO callbacks.
unset($this->callbacks[$eventId]);
} elseif (isset($this->callbacks[$eventId][$callbackId])) {
$callback = $this->callbacks[$eventId][$callbackId];
unset($this->callbacks[$eventId][$callbackId]);
if (isset($this->uvCallbacks[$eventId][0])) { // All except IO callbacks.
unset($this->uvCallbacks[$eventId]);
} elseif (isset($this->uvCallbacks[$eventId][$callbackId])) {
$callback = $this->uvCallbacks[$eventId][$callbackId];
unset($this->uvCallbacks[$eventId][$callbackId]);

\assert($callback instanceof StreamCallback);

if (empty($this->callbacks[$eventId])) {
unset($this->callbacks[$eventId], $this->streams[(int) $callback->stream]);
if (empty($this->uvCallbacks[$eventId])) {
unset($this->uvCallbacks[$eventId], $this->streams[(int) $callback->stream]);
}
}

Expand Down Expand Up @@ -161,10 +161,10 @@ protected function activate(array $callbacks): void

$eventId = (int) $event;
$this->events[$id] = $event;
$this->callbacks[$eventId][$id] = $callback;
$this->uvCallbacks[$eventId][$id] = $callback;

$flags = 0;
foreach ($this->callbacks[$eventId] as $w) {
foreach ($this->uvCallbacks[$eventId] as $w) {
\assert($w instanceof StreamCallback);

$flags |= $w->enabled ? ($this->getStreamCallbackFlags($w)) : 0;
Expand All @@ -177,7 +177,7 @@ protected function activate(array $callbacks): void
$event = $this->events[$id] = \uv_timer_init($this->handle);
}

$this->callbacks[(int) $event] = [$callback];
$this->uvCallbacks[(int) $event] = [$callback];

\uv_timer_start(
$event,
Expand All @@ -193,7 +193,7 @@ protected function activate(array $callbacks): void
$event = $this->events[$id] = \uv_signal_init($this->handle);
}

$this->callbacks[(int) $event] = [$callback];
$this->uvCallbacks[(int) $event] = [$callback];

/** @psalm-suppress TooManyArguments */
\uv_signal_start($event, $this->signalCallback, $callback->signal);
Expand Down Expand Up @@ -224,7 +224,7 @@ protected function deactivate(DriverCallback $callback): void

if ($callback instanceof StreamCallback) {
$flags = 0;
foreach ($this->callbacks[(int) $event] as $w) {
foreach ($this->uvCallbacks[(int) $event] as $w) {
\assert($w instanceof StreamCallback);

$flags |= $w->invokable ? ($this->getStreamCallbackFlags($w)) : 0;
Expand Down

0 comments on commit 40292c1

Please sign in to comment.