From ee6035c59aa67f976bea5d2f191e120e8f2593f6 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 14 May 2022 23:51:17 +0800 Subject: [PATCH] add openswoole support --- src/ZM/Config/ZMConfig.php | 2 +- src/ZM/Store/Lock/SpinLock.php | 8 +------- src/ZM/Utils/CoMessage.php | 5 +++-- src/ZM/global_functions.php | 2 +- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/ZM/Config/ZMConfig.php b/src/ZM/Config/ZMConfig.php index 8a555860..64d0c425 100644 --- a/src/ZM/Config/ZMConfig.php +++ b/src/ZM/Config/ZMConfig.php @@ -86,7 +86,7 @@ class ZMConfig self::$config[$head_name] = self::loadConfig($head_name); } // global.remote_terminal - // 根据切分来寻找子配置 + Console::debug('根据切分来寻找子配置: ' . $name); $obj = self::$config[$head_name]; foreach ($separated as $key) { if (isset($obj[$key])) { diff --git a/src/ZM/Store/Lock/SpinLock.php b/src/ZM/Store/Lock/SpinLock.php index 5c6664fd..4990507f 100644 --- a/src/ZM/Store/Lock/SpinLock.php +++ b/src/ZM/Store/Lock/SpinLock.php @@ -6,8 +6,6 @@ declare(strict_types=1); namespace ZM\Store\Lock; -use Swoole\Coroutine; -use Swoole\Coroutine\System; use Swoole\Table; class SpinLock @@ -28,11 +26,7 @@ class SpinLock public static function lock(string $key) { while (($r = self::$kv_lock->incr($key, 'lock_num')) > 1) { // 此资源已经被锁上了 - if (Coroutine::getCid() != -1) { - System::sleep(self::$delay / 1000); - } else { - usleep(self::$delay * 1000); - } + usleep(self::$delay * 1000); } } diff --git a/src/ZM/Utils/CoMessage.php b/src/ZM/Utils/CoMessage.php index 1199f6ba..42560000 100644 --- a/src/ZM/Utils/CoMessage.php +++ b/src/ZM/Utils/CoMessage.php @@ -6,6 +6,7 @@ namespace ZM\Utils; use Exception; use Swoole\Coroutine; +use Swoole\Timer; use ZM\Store\LightCacheInside; use ZM\Store\Lock\SpinLock; use ZM\Store\ZMAtomic; @@ -19,7 +20,7 @@ class CoMessage public static function yieldByWS(array $hang, array $compare, int $timeout = 600) { $cid = Coroutine::getuid(); - $api_id = ZMAtomic::get('wait_msg_id')->add(1); + $api_id = ZMAtomic::get('wait_msg_id')->add(); $hang['compare'] = $compare; $hang['coroutine'] = $cid; $hang['worker_id'] = server()->worker_id; @@ -42,7 +43,7 @@ class CoMessage unset($sess[$api_id]); LightCacheInside::set('wait_api', 'wait_api', $sess); SpinLock::unlock('wait_api'); - swoole_timer_clear($id); + Timer::clear($id); if ($result === null) { return false; } diff --git a/src/ZM/global_functions.php b/src/ZM/global_functions.php index ae5504a7..ae23087f 100644 --- a/src/ZM/global_functions.php +++ b/src/ZM/global_functions.php @@ -46,7 +46,7 @@ function get_class_path(string $class_name): ?string */ function _zm_env_check() { - if (!extension_loaded('swoole')) { + if (!extension_loaded('swoole') && !extension_loaded('openswoole')) { exit(zm_internal_errcode('E00001') . "Can not find swoole extension.\n"); } if (version_compare(SWOOLE_VERSION, '4.5.0') === -1) {