CGraph
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
UAtomicRingBufferQueue< T, capacity > Class Template Reference

包含一个基于std::vector的环形队列,基于mutex_实现原子的waitPopWithTimeout/push head_/tail_初始化为0,tail_及tail_之后一直到head_之前的位置记为空 举例:head_为0、tail_为3、capaci_为64的情况下,[3,63]范围内的位置都记为空 More...

#include <UAtomicRingBufferQueue.h>

Inheritance diagram for UAtomicRingBufferQueue< T, capacity >:
Inheritance graph
[legend]
Collaboration diagram for UAtomicRingBufferQueue< T, capacity >:
Collaboration graph
[legend]

Public Member Functions

 UAtomicRingBufferQueue ()
 
 ~UAtomicRingBufferQueue () override
 
UAtomicRingBufferQueuesetCapacity (CUInt size)
 
CUInt getCapacity () const
 
template<class TImpl = T>
CVoid push (const TImpl &value, URingBufferPushStrategy strategy)
 
template<class TImpl = T>
CVoid push (std::unique_ptr< TImpl > &value, URingBufferPushStrategy strategy)
 
template<class TImpl = T>
CStatus waitPopWithTimeout (TImpl &value, CMSec timeout)
 
template<class TImpl = T>
CStatus waitPopWithTimeout (std::unique_ptr< TImpl > &value, CMSec timeout)
 
CStatus clear ()
 
- Public Member Functions inherited from CObject
 CObject ()=default
 
virtual CStatus init ()
 
virtual CStatus destroy ()
 
virtual ~CObject ()=default
 

Protected Member Functions

CBool isFull ()
 
CBool isEmpty ()
 
- Protected Member Functions inherited from UThreadObject
CStatus run () override
 
- Protected Member Functions inherited from UtilsObject
CStatus run () override
 

Private Attributes

CUInt head_
 
CUInt tail_
 
CUInt capacity_
 
std::condition_variable push_cv_
 
std::condition_variable pop_cv_
 
std::vector< std::unique_ptr< T > > ring_buffer_queue_
 

Additional Inherited Members

- Protected Attributes inherited from UQueueObject
std::mutex mutex_
 
std::condition_variable cv_
 

Detailed Description

template<typename T, CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
class UAtomicRingBufferQueue< T, capacity >

包含一个基于std::vector的环形队列,基于mutex_实现原子的waitPopWithTimeout/push head_/tail_初始化为0,tail_及tail_之后一直到head_之前的位置记为空 举例:head_为0、tail_为3、capaci_为64的情况下,[3,63]范围内的位置都记为空

Template Parameters
T
capacity

Constructor & Destructor Documentation

◆ UAtomicRingBufferQueue()

template<typename T , CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
UAtomicRingBufferQueue< T, capacity >::UAtomicRingBufferQueue ( )
inlineexplicit

◆ ~UAtomicRingBufferQueue()

template<typename T , CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
UAtomicRingBufferQueue< T, capacity >::~UAtomicRingBufferQueue ( )
inlineoverride
Here is the call graph for this function:

Member Function Documentation

◆ clear()

template<typename T , CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
CStatus UAtomicRingBufferQueue< T, capacity >::clear ( )
inline

清空所有的数据

Returns

◆ getCapacity()

template<typename T , CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
CUInt UAtomicRingBufferQueue< T, capacity >::getCapacity ( ) const
inline

获取容量信息

Returns

◆ isEmpty()

template<typename T , CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
CBool UAtomicRingBufferQueue< T, capacity >::isEmpty ( )
inlineprotected

当前队列是否为空

Returns

◆ isFull()

template<typename T , CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
CBool UAtomicRingBufferQueue< T, capacity >::isFull ( )
inlineprotected

当前队列是否为满

Returns

◆ push() [1/2]

template<typename T , CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
template<class TImpl = T>
CVoid UAtomicRingBufferQueue< T, capacity >::push ( const TImpl &  value,
URingBufferPushStrategy  strategy 
)
inline

写入信息

Template Parameters
TImpl
Parameters
value
strategy
Returns
Here is the call graph for this function:

◆ push() [2/2]

template<typename T , CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
template<class TImpl = T>
CVoid UAtomicRingBufferQueue< T, capacity >::push ( std::unique_ptr< TImpl > &  value,
URingBufferPushStrategy  strategy 
)
inline

写入智能指针类型的信息

Template Parameters
TImpl
Parameters
value
strategy
Returns
Here is the call graph for this function:

◆ setCapacity()

template<typename T , CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
UAtomicRingBufferQueue* UAtomicRingBufferQueue< T, capacity >::setCapacity ( CUInt  size)
inline

设置容量信息

Parameters
size
Returns
@notice 谨慎使用,push信息之后,不推荐使用

◆ waitPopWithTimeout() [1/2]

template<typename T , CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
template<class TImpl = T>
CStatus UAtomicRingBufferQueue< T, capacity >::waitPopWithTimeout ( std::unique_ptr< TImpl > &  value,
CMSec  timeout 
)
inline

等待弹出信息。ps:当入参为智能指针的情况

Template Parameters
TImpl
Parameters
value
timeout
Returns

当传入的内容,是智能指针的时候, 这里就直接通过 move转移过去好了,跟直接传值的方式,保持区别

Here is the call graph for this function:

◆ waitPopWithTimeout() [2/2]

template<typename T , CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
template<class TImpl = T>
CStatus UAtomicRingBufferQueue< T, capacity >::waitPopWithTimeout ( TImpl &  value,
CMSec  timeout 
)
inline

等待弹出信息

Parameters
value
timeout
Returns
Here is the call graph for this function:

Member Data Documentation

◆ capacity_

template<typename T , CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
CUInt UAtomicRingBufferQueue< T, capacity >::capacity_
private

◆ head_

template<typename T , CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
CUInt UAtomicRingBufferQueue< T, capacity >::head_
private

◆ pop_cv_

template<typename T , CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
std::condition_variable UAtomicRingBufferQueue< T, capacity >::pop_cv_
private

◆ push_cv_

template<typename T , CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
std::condition_variable UAtomicRingBufferQueue< T, capacity >::push_cv_
private

◆ ring_buffer_queue_

template<typename T , CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
std::vector<std::unique_ptr<T> > UAtomicRingBufferQueue< T, capacity >::ring_buffer_queue_
private

◆ tail_

template<typename T , CUInt capacity = CGRAPH_DEFAULT_RINGBUFFER_SIZE>
CUInt UAtomicRingBufferQueue< T, capacity >::tail_
private

The documentation for this class was generated from the following file: