-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
153 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* This file is part of Swoole. | ||
* | ||
* @link https://www.swoole.com | ||
* @contact [email protected] | ||
* @license https://github.com/swoole/library/blob/master/LICENSE | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Swoole\Coroutine; | ||
|
||
use Swoole\Coroutine; | ||
use Swoole\Exception; | ||
use Swoole\Timer; | ||
|
||
class Barrier | ||
{ | ||
private $cid = -1; | ||
|
||
private $timer = -1; | ||
|
||
private static $cancel_list = []; | ||
|
||
public function __destruct() | ||
{ | ||
if ($this->timer != -1) { | ||
Timer::clear($this->timer); | ||
if (static::$cancel_list[$this->cid]) { | ||
unset(static::$cancel_list[$this->cid]); | ||
return; | ||
} | ||
} | ||
if ($this->cid != -1) { | ||
Coroutine::resume($this->cid); | ||
} | ||
} | ||
|
||
public static function make() | ||
{ | ||
return new static(); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public static function wait(Barrier &$barrier, float $timeout = -1) | ||
{ | ||
if ($barrier->cid != -1) { | ||
throw new Exception('The barrier is waiting, cannot wait again.'); | ||
} | ||
$cid = Coroutine::getCid(); | ||
$barrier->cid = $cid; | ||
if ($timeout > 0 && ($timeout_ms = intval($timeout * 1000)) > 0) { | ||
$barrier->timer = Timer::after($timeout_ms, function () use ($cid) { | ||
self::$cancel_list[$cid] = true; | ||
Coroutine::resume($cid); | ||
}); | ||
} | ||
$barrier = null; | ||
Coroutine::yield(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
output/swoole_library/src/core/Exception/ArrayKeyNotExists.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/** | ||
* This file is part of Swoole. | ||
* | ||
* @link https://www.swoole.com | ||
* @contact [email protected] | ||
* @license https://github.com/swoole/library/blob/master/LICENSE | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Swoole\Exception; | ||
|
||
class ArrayKeyNotExists extends \RuntimeException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters