Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/UtilsCtrl/ThreadPool/Queue/UQueueDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef CGRAPH_UQUEUEDEFINE_H
#define CGRAPH_UQUEUEDEFINE_H

#include "../UThreadPoolDefine.h"

CGRAPH_NAMESPACE_BEGIN

/** 当环形队列满的时候,写入信息时候的策略 */
Expand Down
13 changes: 6 additions & 7 deletions src/UtilsCtrl/ThreadPool/Queue/UWorkStealingQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ class UWorkStealingQueue : public UQueueObject {
deque_.emplace_back(std::forward<T>(value));
mutex_.unlock();
break;
} else {
CGRAPH_YIELD();
}
CGRAPH_YIELD();
}
}

Expand All @@ -40,7 +39,7 @@ class UWorkStealingQueue : public UQueueObject {
* 有条件的写入数据信息
* @param value
* @param enable
* @param state
* @param lockable
* @return
*/
CVoid push(T&& value, CBool enable, CBool lockable) {
Expand Down Expand Up @@ -82,9 +81,8 @@ class UWorkStealingQueue : public UQueueObject {
}
mutex_.unlock();
break;
} else {
CGRAPH_YIELD();
}
CGRAPH_YIELD();
}
}

Expand Down Expand Up @@ -133,7 +131,7 @@ class UWorkStealingQueue : public UQueueObject {

/**
* 窃取节点,从尾部进行
* @param task
* @param value
* @return
*/
CBool trySteal(T& value) {
Expand All @@ -154,6 +152,7 @@ class UWorkStealingQueue : public UQueueObject {
/**
* 批量窃取节点,从尾部进行
* @param values
* @param maxStealBatchSize
* @return
*/
CBool trySteal(std::vector<T>& values, int maxStealBatchSize) {
Expand All @@ -175,7 +174,7 @@ class UWorkStealingQueue : public UQueueObject {
CGRAPH_NO_ALLOWED_COPY(UWorkStealingQueue)

private:
std::deque<T> deque_; // 存放任务的双向队列
std::deque<T> deque_ {}; // 存放任务的双向队列
};

CGRAPH_NAMESPACE_END
Expand Down
8 changes: 4 additions & 4 deletions src/UtilsCtrl/ThreadPool/UThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ CStatus UThreadPool::releaseSecondaryThread(CInt size) {
!(*iter)->done_ ? secondary_threads_.erase(iter++) : iter++;
}

CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION((size > (CInt)secondary_threads_.size()), \
CGRAPH_RETURN_ERROR_STATUS_BY_CONDITION((size > static_cast<CInt>(secondary_threads_.size())), \
"cannot release [" + std::to_string(size) + "] secondary thread," \
+ "only [" + std::to_string(secondary_threads_.size()) + "] left.")

// 再标记几个需要删除的信息
for (auto iter = secondary_threads_.begin();
iter != secondary_threads_.end() && size-- > 0; ) {
(*iter)->done_ = false;
iter++;
++iter;
}
CGRAPH_FUNCTION_END
}
Expand All @@ -222,8 +222,8 @@ CIndex UThreadPool::dispatch(CIndex origIndex) {
CStatus UThreadPool::createSecondaryThread(CInt size) {
CGRAPH_FUNCTION_BEGIN

int leftSize = (int)(config_.max_thread_size_ - config_.default_thread_size_ - secondary_threads_.size());
int realSize = std::min(size, leftSize); // 使用 realSize 来确保所有的线程数量之和,不会超过设定max值
const int leftSize = static_cast<int>(config_.max_thread_size_ - config_.default_thread_size_ - secondary_threads_.size());
const int realSize = std::min(size, leftSize); // 使用 realSize 来确保所有的线程数量之和,不会超过设定max值

CGRAPH_LOCK_GUARD lock(st_mutex_);
for (int i = 0; i < realSize; i++) {
Expand Down
Loading