提交 55b96d75 编写于 作者: 独孤过's avatar 独孤过

update v2.3.0

上级 de1b4faa
......@@ -40,6 +40,7 @@ static void execute(ThreadPool& _threadPool)
static void terminate(ThreadPool&& _threadPool)
{
_threadPool.clearTask();
auto threadPool(std::forward<ThreadPool>(_threadPool));
(void)threadPool;
}
......
......@@ -88,6 +88,8 @@ private:
std::memory_order_relaxed);
}
bool valid(QueueType& _queue) const noexcept;
public:
// 若_capacity小于等于零,则无限制,否则其为上限值
DoubleQueue(SizeType _capacity = 0) : \
......@@ -151,6 +153,16 @@ void DoubleQueue<_Element>::move(DoubleQueue& _left, \
set(_left._capacity, exchange(_right._capacity, 0));
}
template <typename _Element>
bool DoubleQueue<_Element>::valid(QueueType& _queue) const noexcept
{
auto capacity = this->capacity();
if (capacity <= 0) return true;
auto size = this->size();
return size < capacity && _queue.size() <= capacity - size;
}
template <typename _Element>
DoubleQueue<_Element>::DoubleQueue(const DoubleQueue& _another)
{
......@@ -224,11 +236,7 @@ auto DoubleQueue<_Element>::push(QueueType& _queue) \
-> std::optional<SizeType>
{
std::lock_guard lock(_entryMutex);
if (auto capacity = this->capacity(), \
size = this->size(); \
capacity > 0 && (size >= capacity \
|| _queue.size() >= capacity - size))
return std::nullopt;
if (not valid(_queue)) return std::nullopt;
auto size = _queue.size();
_entryQueue.splice(_entryQueue.cend(), _queue);
......@@ -240,11 +248,7 @@ auto DoubleQueue<_Element>::push(QueueType&& _queue) \
-> std::optional<SizeType>
{
std::lock_guard lock(_entryMutex);
if (auto capacity = this->capacity(), \
size = this->size(); \
capacity > 0 && (size >= capacity \
|| _queue.size() >= capacity - size))
return std::nullopt;
if (not valid(_queue)) return std::nullopt;
auto size = _queue.size();
_entryQueue.splice(_entryQueue.cend(), \
......
......@@ -138,6 +138,8 @@ bool Thread::getTask(DataType& _data)
if (!_data->_taskQueue->pop(task))
return false;
if (!task) task = [] {};
_data->setState(State::RUNNABLE);
_data->setTask(std::move(task));
return true;
......
......@@ -3,7 +3,7 @@
* 语言标准:C++17
*
* 创建日期:2017年09月22日
* 更新日期:2023年09月11
* 更新日期:2023年10月15
*
* 摘要
* 1. 线程类Thread定义于此文件,实现于Thread.cpp。
......
......@@ -457,7 +457,7 @@ void ThreadPool::execute(DataType _data)
_data->_condition.wait(predicate);
}
// 清空线程
// 清空线程
_data->_threadTable.clear();
}
......
......@@ -49,7 +49,7 @@
* 2.确保移动构造函数和析构函数的异常安全性。
* v2.3.0
* 1.确保移动赋值运算符函数的异常安全性。
* 2.在销毁线程池时,当任务队列为空,并且所有线程闲置,守护线程才可以退出,否则守护线程阻塞直至满足退出条件。
* 2.在销毁线程池时,当任务队列为空,并且所有线程闲置,守护线程才退出,否则守护线程阻塞,直至满足退出条件。
*/
#pragma once
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册