Skip to content

Commit

Permalink
[perf] notify all snd thd when destory threadpoll
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed Oct 26, 2024
1 parent 4d570f2 commit 3d0f45f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/UtilsCtrl/ThreadPool/Queue/UAtomicQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ class UAtomicQueue : public UQueueObject {
return queue_.empty();
}


/**
* 唤醒所有等待的
* @return
*/
CVoid notifyAll() {
cv_.notify_all();
}

CGRAPH_NO_ALLOWED_COPY(UAtomicQueue)

private:
Expand Down
2 changes: 1 addition & 1 deletion src/UtilsCtrl/ThreadPool/Thread/UThreadSecondary.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class UThreadSecondary : public UThreadBase {
CVoid waitRunTask(CMSec ms) {
auto task = this->pool_task_queue_->popWithTimeout(ms);
if (nullptr != task) {
(*task)();
runTask(*task);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/UtilsCtrl/ThreadPool/UThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ CStatus UThreadPool::destroy() {
CGRAPH_DELETE_PTR(pt)
}
primary_threads_.clear();

task_queue_.notifyAll();
// secondary 线程是智能指针,不需要delete
for (auto &st : secondary_threads_) {
status += st->destroy();
Expand Down
2 changes: 1 addition & 1 deletion src/UtilsCtrl/ThreadPool/UThreadPoolDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static const CMSec CGRAPH_PRIMARY_THREAD_EMPTY_INTERVAL = 1000;
static const CSec CGRAPH_SECONDARY_THREAD_TTL = 10; // 辅助线程ttl,单位为s
static const CBool CGRAPH_MONITOR_ENABLE = false; // 是否开启监控程序
static const CSec CGRAPH_MONITOR_SPAN = 5; // 监控线程执行间隔,单位为s
static const CMSec CGRAPH_QUEUE_EMPTY_INTERVAL = 3; // 队列为空时,等待的时间。仅针对辅助线程,单位为ms
static const CMSec CGRAPH_QUEUE_EMPTY_INTERVAL = 300; // 队列为空时,等待的时间。仅针对辅助线程,单位为ms
static const CBool CGRAPH_BIND_CPU_ENABLE = false; // 是否开启绑定cpu模式(仅针对主线程)
static const CInt CGRAPH_PRIMARY_THREAD_POLICY = CGRAPH_THREAD_SCHED_OTHER; // 主线程调度策略
static const CInt CGRAPH_SECONDARY_THREAD_POLICY = CGRAPH_THREAD_SCHED_OTHER; // 辅助线程调度策略
Expand Down

0 comments on commit 3d0f45f

Please sign in to comment.