|
@@ -244,6 +244,8 @@ abstract class ILooper
|
|
Swoole\Coroutine::sleep(0.1);
|
|
Swoole\Coroutine::sleep(0.1);
|
|
} while($this->_pause == 1);
|
|
} while($this->_pause == 1);
|
|
Log::record("runloop cid={$this->_cid}",Log::DEBUG);
|
|
Log::record("runloop cid={$this->_cid}",Log::DEBUG);
|
|
|
|
+
|
|
|
|
+ $this->wait();
|
|
}
|
|
}
|
|
|
|
|
|
public function resume()
|
|
public function resume()
|
|
@@ -260,6 +262,40 @@ abstract class ILooper
|
|
{
|
|
{
|
|
Log::record(__FUNCTION__,Log::DEBUG);
|
|
Log::record(__FUNCTION__,Log::DEBUG);
|
|
$this->_stop = true;
|
|
$this->_stop = true;
|
|
|
|
+ $this->wait();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function wait()
|
|
|
|
+ {
|
|
|
|
+ do {
|
|
|
|
+ $res = Swoole\Coroutine::stats();
|
|
|
|
+ $num = $res['coroutine_num'];
|
|
|
|
+ if($num > 10) {
|
|
|
|
+ Swoole\Coroutine::sleep(1);
|
|
|
|
+ }
|
|
|
|
+ Log::record("wait coroutine quit num = {$num}",Log::DEBUG);
|
|
|
|
+ } while($num > 10);
|
|
|
|
+
|
|
|
|
+ do
|
|
|
|
+ {
|
|
|
|
+ $count = 0;
|
|
|
|
+ $pcid = $this->_cid;
|
|
|
|
+ $coros = Swoole\Coroutine::list();
|
|
|
|
+ foreach ($coros as $cid)
|
|
|
|
+ {
|
|
|
|
+ $p = getPcid($cid);
|
|
|
|
+ if($p == $pcid) {
|
|
|
|
+ $count += 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if($count > 0) {
|
|
|
|
+ Swoole\Coroutine::sleep(1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Log::record("wait sub coroutine quit num = {$count}",Log::DEBUG);
|
|
|
|
+ }
|
|
|
|
+ while($count > 0);
|
|
}
|
|
}
|
|
|
|
|
|
public function run()
|
|
public function run()
|