libgrape-lite
A C++ library for parallel graph processing
Public Member Functions | Private Attributes | List of all members
grape::NonblockingQueue< T > Class Template Reference

A concurrent queue guarded by a spinlock and can be accessed by multi-producers and multi-consumers simultaneously. More...

#include <concurrent_queue.h>

Public Member Functions

void Put (const T &item)
 Put an entity into this queue. More...
 
void Put (T &&item)
 Put an entity into this queue. More...
 
bool Get (T &item)
 Get an entity from this queue. More...
 
void Clear ()
 

Private Attributes

std::deque< T > queue_
 
SpinLock lock_
 

Detailed Description

template<typename T>
class grape::NonblockingQueue< T >

A concurrent queue guarded by a spinlock and can be accessed by multi-producers and multi-consumers simultaneously.

Template Parameters
TType of entities in the queue.

Member Function Documentation

◆ Get()

template<typename T >
bool grape::NonblockingQueue< T >::Get ( T &  item)
inline

Get an entity from this queue.

This function won't be blocked.

Parameters
itemReference of an entity to hold the got data.
Returns
If got data, return true. Otherwise, return false.

◆ Put() [1/2]

template<typename T >
void grape::NonblockingQueue< T >::Put ( const T &  item)
inline

Put an entity into this queue.

This function won't be blocked.

Parameters
itemThe entity to be put.

◆ Put() [2/2]

template<typename T >
void grape::NonblockingQueue< T >::Put ( T &&  item)
inline

Put an entity into this queue.

This function won't be blocked.

Parameters
itemThe entity to be put.