add openswoole support

This commit is contained in:
crazywhalecc
2022-05-14 23:51:17 +08:00
parent a757330788
commit ee6035c59a
4 changed files with 6 additions and 11 deletions

View File

@@ -86,7 +86,7 @@ class ZMConfig
self::$config[$head_name] = self::loadConfig($head_name); self::$config[$head_name] = self::loadConfig($head_name);
} }
// global.remote_terminal // global.remote_terminal
// 根据切分来寻找子配置 Console::debug('根据切分来寻找子配置: ' . $name);
$obj = self::$config[$head_name]; $obj = self::$config[$head_name];
foreach ($separated as $key) { foreach ($separated as $key) {
if (isset($obj[$key])) { if (isset($obj[$key])) {

View File

@@ -6,8 +6,6 @@ declare(strict_types=1);
namespace ZM\Store\Lock; namespace ZM\Store\Lock;
use Swoole\Coroutine;
use Swoole\Coroutine\System;
use Swoole\Table; use Swoole\Table;
class SpinLock class SpinLock
@@ -28,11 +26,7 @@ class SpinLock
public static function lock(string $key) public static function lock(string $key)
{ {
while (($r = self::$kv_lock->incr($key, 'lock_num')) > 1) { // 此资源已经被锁上了 while (($r = self::$kv_lock->incr($key, 'lock_num')) > 1) { // 此资源已经被锁上了
if (Coroutine::getCid() != -1) { usleep(self::$delay * 1000);
System::sleep(self::$delay / 1000);
} else {
usleep(self::$delay * 1000);
}
} }
} }

View File

@@ -6,6 +6,7 @@ namespace ZM\Utils;
use Exception; use Exception;
use Swoole\Coroutine; use Swoole\Coroutine;
use Swoole\Timer;
use ZM\Store\LightCacheInside; use ZM\Store\LightCacheInside;
use ZM\Store\Lock\SpinLock; use ZM\Store\Lock\SpinLock;
use ZM\Store\ZMAtomic; use ZM\Store\ZMAtomic;
@@ -19,7 +20,7 @@ class CoMessage
public static function yieldByWS(array $hang, array $compare, int $timeout = 600) public static function yieldByWS(array $hang, array $compare, int $timeout = 600)
{ {
$cid = Coroutine::getuid(); $cid = Coroutine::getuid();
$api_id = ZMAtomic::get('wait_msg_id')->add(1); $api_id = ZMAtomic::get('wait_msg_id')->add();
$hang['compare'] = $compare; $hang['compare'] = $compare;
$hang['coroutine'] = $cid; $hang['coroutine'] = $cid;
$hang['worker_id'] = server()->worker_id; $hang['worker_id'] = server()->worker_id;
@@ -42,7 +43,7 @@ class CoMessage
unset($sess[$api_id]); unset($sess[$api_id]);
LightCacheInside::set('wait_api', 'wait_api', $sess); LightCacheInside::set('wait_api', 'wait_api', $sess);
SpinLock::unlock('wait_api'); SpinLock::unlock('wait_api');
swoole_timer_clear($id); Timer::clear($id);
if ($result === null) { if ($result === null) {
return false; return false;
} }

View File

@@ -46,7 +46,7 @@ function get_class_path(string $class_name): ?string
*/ */
function _zm_env_check() 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"); exit(zm_internal_errcode('E00001') . "Can not find swoole extension.\n");
} }
if (version_compare(SWOOLE_VERSION, '4.5.0') === -1) { if (version_compare(SWOOLE_VERSION, '4.5.0') === -1) {