2020-11-03 21:02:24 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace ZM\Store;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use Swoole\Atomic;
|
|
|
|
|
use ZM\Config\ZMConfig;
|
|
|
|
|
|
|
|
|
|
class ZMAtomic
|
|
|
|
|
{
|
|
|
|
|
/** @var Atomic[] */
|
|
|
|
|
public static $atomics;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param $name
|
|
|
|
|
* @return Atomic|null
|
|
|
|
|
*/
|
2021-03-18 14:56:35 +08:00
|
|
|
public static function get($name): ?Atomic {
|
2020-11-03 21:02:24 +08:00
|
|
|
return self::$atomics[$name] ?? null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化atomic计数器
|
|
|
|
|
*/
|
|
|
|
|
public static function init() {
|
2021-07-04 15:45:30 +08:00
|
|
|
foreach ((ZMConfig::get("global", "init_atomics") ?? []) as $k => $v) {
|
2020-11-03 21:02:24 +08:00
|
|
|
self::$atomics[$k] = new Atomic($v);
|
|
|
|
|
}
|
|
|
|
|
self::$atomics["stop_signal"] = new Atomic(0);
|
2021-03-06 17:22:42 +08:00
|
|
|
self::$atomics["_int_is_reload"] = new Atomic(0);
|
2020-11-03 21:02:24 +08:00
|
|
|
self::$atomics["wait_msg_id"] = new Atomic(0);
|
2020-12-14 01:24:34 +08:00
|
|
|
self::$atomics["_event_id"] = new Atomic(0);
|
2021-03-15 02:54:16 +08:00
|
|
|
self::$atomics["server_is_stopped"] = new Atomic(0);
|
2021-09-10 11:24:32 +08:00
|
|
|
if (!defined("ZM_WORKER_NUM")) define("ZM_WORKER_NUM", 1);
|
2021-03-24 23:34:46 +08:00
|
|
|
for($i = 0; $i < ZM_WORKER_NUM; ++$i) {
|
|
|
|
|
self::$atomics["_#worker_".$i] = new Atomic(0);
|
|
|
|
|
}
|
2020-11-03 21:02:24 +08:00
|
|
|
for ($i = 0; $i < 10; ++$i) {
|
|
|
|
|
self::$atomics["_tmp_" . $i] = new Atomic(0);
|
|
|
|
|
}
|
2021-06-16 00:17:30 +08:00
|
|
|
self::$atomics["ss"] = new Atomic(1);
|
2020-11-03 21:02:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|