stanley-king 3 年之前
父节点
当前提交
2f06b61435
共有 2 个文件被更改,包括 36 次插入9 次删除
  1. 36 0
      helper/queue/iqueue.php
  2. 0 9
      rdispatcher/coall.php

+ 36 - 0
helper/queue/iqueue.php

@@ -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()

+ 0 - 9
rdispatcher/coall.php

@@ -149,15 +149,6 @@ for ($i = 0; $i < $process_count;$i++)
             }
             }
 
 
             $looper->stop();
             $looper->stop();
-            do {
-                $res = Swoole\Coroutine::stats();
-                $num = $res['coroutine_num'];
-                if($num > 1) {
-                    Swoole\Coroutine::sleep(0.1);
-                }
-                Log::record("coroutine_num = {$num}",Log::DEBUG);
-            } while($num > 1);
-
             CoRedisPool::instance()->stop();
             CoRedisPool::instance()->stop();
             CoMysqliPool::instance()->stop();
             CoMysqliPool::instance()->stop();
         });
         });