acquireWorkerSlot 尝试获取工作槽
()
| 331 | |
| 332 | // acquireWorkerSlot 尝试获取工作槽 |
| 333 | func acquireWorkerSlot() bool { |
| 334 | // 获取最大任务数 |
| 335 | maxTasks := int32(defaultMaxBackgroundTasks) |
| 336 | if config.AppConfig != nil { |
| 337 | maxTasks = int32(config.AppConfig.AsyncMaxBackgroundTasks) |
| 338 | } |
| 339 | |
| 340 | // 检查总任务数 |
| 341 | if atomic.LoadInt32(&backgroundTasksCount) >= maxTasks { |
| 342 | return false |
| 343 | } |
| 344 | |
| 345 | // 尝试获取工作槽 |
| 346 | select { |
| 347 | case backgroundWorkerPool <- struct{}{}: |
| 348 | atomic.AddInt32(&backgroundTasksCount, 1) |
| 349 | return true |
| 350 | default: |
| 351 | return false |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | // releaseWorkerSlot 释放工作槽 |
| 356 | func releaseWorkerSlot() { |
no outgoing calls
no test coverage detected