Free worker ID 释放workerid
(conn ziface.IConnection)
| 219 | // Free worker ID |
| 220 | // 释放workerid |
| 221 | func freeWorker(conn ziface.IConnection) { |
| 222 | mh, _ := conn.GetMsgHandler().(*MsgHandle) |
| 223 | if mh == nil { |
| 224 | zlog.Ins().ErrorF("useWorker failed, mh is nil") |
| 225 | return |
| 226 | } |
| 227 | |
| 228 | if zconf.GlobalObject.WorkerMode == zconf.WorkerModeBind { |
| 229 | mh.freeWorkerMu.Lock() |
| 230 | defer mh.freeWorkerMu.Unlock() |
| 231 | |
| 232 | mh.freeWorkers[conn.GetWorkerID()] = struct{}{} |
| 233 | } |
| 234 | |
| 235 | if zconf.GlobalObject.WorkerMode == zconf.WorkerModeDynamicBind { |
| 236 | workerID := conn.GetWorkerID() |
| 237 | if workerID < mh.WorkerPoolSize { |
| 238 | // 说明这个是工作线程池里的workerID,回收这个workerID, workerID对应的worker不需要销毁 |
| 239 | mh.freeWorkerMu.Lock() |
| 240 | mh.freeWorkers[workerID] = struct{}{} |
| 241 | mh.freeWorkerMu.Unlock() |
| 242 | } else { |
| 243 | // 说明这个worker是一个临时的worker,需要销毁这个worker |
| 244 | mh.StopOneWorker(int(workerID)) |
| 245 | // 回收workerID, 放回额外workerID池里 |
| 246 | mh.extraFreeWorkerMu.Lock() |
| 247 | mh.extraFreeWorkers[workerID] = struct{}{} |
| 248 | mh.extraFreeWorkerMu.Unlock() |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | // Data processing interceptor that is necessary by default in Zinx |
| 254 | // (Zinx默认必经的数据处理拦截器) |
no test coverage detected