Skip to content

Commit

Permalink
revert Thread class to v4.1.4 tag commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Mar 7, 2023
1 parent 14d7165 commit 138347c
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions Spawn/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,14 @@ public function __destruct()
$this->close();

if (!$this->hasLoop && self::$uv instanceof \UVLoop) {
$loop = self::$uv;
@\uv_stop(self::$uv);
@\uv_run(self::$uv);
self::$uv = null;
@\uv_stop($loop);
@\uv_run($loop);
}

if (!\is_null($this->threads)) {
$this->successCallbacks = [];
$this->errorCallbacks = [];
$this->threads = null;
}
$this->successCallbacks = [];
$this->errorCallbacks = [];
$this->threads = null;
}

public function close()
Expand All @@ -88,12 +85,11 @@ public function close()
* @param \UVLoop|null $uv
* @param boolean $yielding
*/
public function __construct(object $loop = null, bool $yielding = false)
public function __construct($loop = null, ?\UVLoop $uv = null, bool $yielding = false)
{
if (!\IS_THREADED_UV)
throw new \InvalidArgumentException('This `Thread` class requires PHP `ZTS` and the libuv `ext-uv` extension!');

$uv = null;
$lock = \mutex_lock();
$this->isYield = $yielding;
$this->hasLoop = \is_object($loop) && \method_exists($loop, 'executeTask') && \method_exists($loop, 'run');
Expand All @@ -106,7 +102,7 @@ public function __construct(object $loop = null, bool $yielding = false)
}

$uvLoop = $uv instanceof \UVLoop ? $uv : self::$uv;
self::$uv = $uvLoop instanceof \UVLoop ? $uvLoop : \uv_loop_new();
self::$uv = $uvLoop instanceof \UVLoop ? $uvLoop : \uv_default_loop();
$this->success = $this->isYield ? [$this, 'yieldAsFinished'] : [$this, 'triggerSuccess'];
$this->failed = $this->isYield ? [$this, 'yieldAsFailed'] : [$this, 'triggerError'];
\mutex_unlock($lock);
Expand Down Expand Up @@ -217,21 +213,21 @@ protected function handlers($tid): void
{
if ($this->isRunning($tid)) {
} elseif ($this->isSuccessful($tid)) {
$this->remove($tid);
if ($this->hasLoop) // @codeCoverageIgnoreStart
$this->loop->executeTask($this->success, $tid);
elseif ($this->isYield)
$this->yieldAsFinished($tid); // @codeCoverageIgnoreEnd
else
$this->triggerSuccess($tid);
} elseif ($this->isTerminated($tid) || $this->isCancelled($tid)) {
$this->remove($tid);
} elseif ($this->isTerminated($tid) || $this->isCancelled($tid)) {
if ($this->hasLoop) // @codeCoverageIgnoreStart
$this->loop->executeTask($this->failed, $tid);
elseif ($this->isYield)
$this->yieldAsFailed($tid); // @codeCoverageIgnoreEnd
else
$this->triggerError($tid);
$this->remove($tid);
}
}

Expand Down

0 comments on commit 138347c

Please sign in to comment.