bmv2
Designing your own switch target with bmv2
Public Member Functions | List of all members
bm::QueueingLogic< T, FMap > Class Template Reference

Public Member Functions

 QueueingLogic (size_t nb_workers, size_t capacity, FMap map_to_worker)
 
void push_front (size_t queue_id, const T &item)
 
void push_front (size_t queue_id, T &&item)
 Moves item to the front of the logical queue with id queue_id. More...
 
void pop_back (size_t worker_id, size_t *queue_id, T *pItem)
 
size_t size (size_t queue_id) const
 Get the occupancy of the logical queue with id queue_id. More...
 
void set_capacity (size_t queue_id, size_t c)
 
void set_capacity_for_all (size_t c)
 Set the capacity of all logical queues to c elements. More...
 
 QueueingLogic (const QueueingLogic &)=delete
 Deleted copy constructor. More...
 
QueueingLogicoperator= (const QueueingLogic &)=delete
 Deleted copy assignment operator. More...
 
 QueueingLogic (QueueingLogic &&)=delete
 Deleted move constructor. More...
 
QueueingLogic && operator= (QueueingLogic &&)=delete
 Deleted move assignment operator. More...
 

Detailed Description

template<typename T, typename FMap>
class bm::QueueingLogic< T, FMap >

One of the most basic queueing block possible. Supports an arbitrary number of logical queues (identified by arbitrary integer ids). Lets you choose (at runtime) the number of worker threads that will be reading from these queues. I write "logical queues" because the implementation actually uses as many physical queues as there are worker threads. However, each logical queue still has its own maximum capacity. As of now, the behavior is blocking for both read (pop_back()) and write (push_front()), but we may offer additional options if there is interest expressed in the future.

Template parameter T is the type (has to be movable) of the objects that will be stored in the queues. Template parameter FMap is a callable object that has to be able to map every logical queue id to a worker id. The following is a good example of functor that meets the requirements:

struct WorkerMapper {
WorkerMapper(size_t nb_workers)
: nb_workers(nb_workers) { }
size_t operator()(size_t queue_id) const {
return queue_id % nb_workers;
}
size_t nb_workers;
};

Constructor & Destructor Documentation

◆ QueueingLogic() [1/3]

template<typename T , typename FMap >
bm::QueueingLogic< T, FMap >::QueueingLogic ( size_t  nb_workers,
size_t  capacity,
FMap  map_to_worker 
)
inline

nb_workers is the number of threads that will be consuming from the queues; they will be identified by an id in the range [0, nb_workers). capacity is the number of objects that each logical queue can hold. Because we need to be able to map each queue id to a worker id, the user has to provide a callable object of type FMap, map_to_worker, that can do this mapping. See the QueueingLogic class description for more information about the FMap template parameter.

◆ QueueingLogic() [2/3]

template<typename T , typename FMap >
bm::QueueingLogic< T, FMap >::QueueingLogic ( const QueueingLogic< T, FMap > &  )
delete

Deleted copy constructor.

◆ QueueingLogic() [3/3]

template<typename T , typename FMap >
bm::QueueingLogic< T, FMap >::QueueingLogic ( QueueingLogic< T, FMap > &&  )
delete

Deleted move constructor.

Member Function Documentation

◆ operator=() [1/2]

template<typename T , typename FMap >
QueueingLogic& bm::QueueingLogic< T, FMap >::operator= ( const QueueingLogic< T, FMap > &  )
delete

Deleted copy assignment operator.

◆ operator=() [2/2]

template<typename T , typename FMap >
QueueingLogic&& bm::QueueingLogic< T, FMap >::operator= ( QueueingLogic< T, FMap > &&  )
delete

Deleted move assignment operator.

◆ pop_back()

template<typename T , typename FMap >
void bm::QueueingLogic< T, FMap >::pop_back ( size_t  worker_id,
size_t *  queue_id,
T *  pItem 
)
inline

Retrieves the oldest element for the worker thread indentified by worker_id and moves it to pItem. The id of the logical queue which contained this element is copied to queue_id. As a remainder, the map_to_worker argument provided when constructing the class is used to map every queue id to the corresponding worker id. Therefore, if an element E was pushed to queue queue_id, you need to use the worker id map_to_worker(queue_id) to retrieve it with this function.

◆ push_front() [1/2]

template<typename T , typename FMap >
void bm::QueueingLogic< T, FMap >::push_front ( size_t  queue_id,
const T &  item 
)
inline

Makes a copy of item and pushes it to the front of the logical queue with id queue_id.

◆ push_front() [2/2]

template<typename T , typename FMap >
void bm::QueueingLogic< T, FMap >::push_front ( size_t  queue_id,
T &&  item 
)
inline

Moves item to the front of the logical queue with id queue_id.

◆ set_capacity()

template<typename T , typename FMap >
void bm::QueueingLogic< T, FMap >::set_capacity ( size_t  queue_id,
size_t  c 
)
inline

Set the capacity of the logical queue with id queue_id to c elements.

◆ set_capacity_for_all()

template<typename T , typename FMap >
void bm::QueueingLogic< T, FMap >::set_capacity_for_all ( size_t  c)
inline

Set the capacity of all logical queues to c elements.

◆ size()

template<typename T , typename FMap >
size_t bm::QueueingLogic< T, FMap >::size ( size_t  queue_id) const
inline

Get the occupancy of the logical queue with id queue_id.


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