|
MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
|
无锁队列类模板 更多...
#include <lock_free_queue.hpp>
Public 成员函数 | |
| lock_free_queue () | |
| 默认构造函数 | |
| ~lock_free_queue () | |
| 析构函数 | |
| void | push (T new_value) |
| 入队操作 | |
| unique_ptr< T > | pop () |
| 出队操作 | |
| unique_ptr< T > | try_pop () |
| 尝试出队操作 | |
| bool | empty () const noexcept |
| 检查队列是否为空 | |
| size_t | size () const noexcept |
| 获取队列中元素的近似数量 | |
| void | clear () |
| 清空队列 | |
无锁队列类模板
| T | 元素类型 |
基于原子操作和引用计数实现的多生产者多消费者无锁队列。 使用Michael-Scott算法实现,支持并发push和pop操作。
在文件 lock_free_queue.hpp 第 33 行定义.
|
inline |
|
inline |
|
inline |
清空队列
循环调用pop()直到队列为空,删除所有元素。
在文件 lock_free_queue.hpp 第 355 行定义.
|
inlinenoexcept |
检查队列是否为空
在文件 lock_free_queue.hpp 第 324 行定义.
引用了 _MSTL , 以及 memory_order_acquire.
|
inline |
出队操作
从队列头部弹出元素,支持多线程并发出队。 使用CAS操作保证线程安全。
在文件 lock_free_queue.hpp 第 261 行定义.
引用了 _MSTL, atomic< T >::exchange(), atomic< T >::load(), make_unique(), memory_order_relaxed , 以及 next().
被这些函数引用 clear() , 以及 ~lock_free_queue().
|
inline |
入队操作
| new_value | 要入队的新值 |
将新值压入队列尾部,支持多线程并发入队。 使用CAS操作保证线程安全。
在文件 lock_free_queue.hpp 第 223 行定义.
引用了 _MSTL, atomic< T >::compare_exchange_strong(), atomic< T >::load() , 以及 memory_order_relaxed.
|
inlinenoexcept |
获取队列中元素的近似数量
在文件 lock_free_queue.hpp 第 338 行定义.
引用了 _MSTL , 以及 memory_order_relaxed.
|
inline |
尝试出队操作
尝试从队列头部弹出元素,最多重试3次。 如果队列为空或多次CAS失败,则返回空指针。
在文件 lock_free_queue.hpp 第 290 行定义.
引用了 _MSTL, atomic< T >::exchange(), atomic< T >::load(), make_unique(), memory_order_relaxed , 以及 next().