#include <msgq.h>
Public Types | |
typedef P | prio_t |
The datatype for msg priorities. | |
typedef P | prio_t |
Public Member Functions | |
msgQ () | |
Hardly any initialization required. | |
void | enq (const msg_t *msg, const prio_t &prio=prio_t(), const bool isFifo=true) |
Given a message (optionally with a priority and queuing policy), enqueue it for delivery. | |
const msg_t * | deq () |
Pop (and return) the next message to deliver. | |
size_t | size () const |
Number of messages in the queue. | |
size_t | max_size () const |
bool | empty () const |
Is the queue empty? | |
void | enumerate (msg_t **first, msg_t **last) const |
Just so that we can support CqsEnumerateQueue(). | |
msgQ () | |
size_t | size () const |
size_t | max_size () const |
bool | empty () const |
void | enumerate (msg_t **first, msg_t **last) const |
void | enq (const msg_t *msg, const prio_t &prio=prio_t(), const bool isFifo=true) |
const msg_t * | deq () |
Private Types | |
typedef std::deque< const msg_t * > | bkt_t |
Message bucket type. | |
typedef std::pair< prio_t, bkt_t * > | prioidx_t |
A key-val pair of a priority value and a handle to the bucket of msgs of that priority. | |
typedef std::unordered_map < prio_t, bkt_t > | bktmap_t |
A type for mapping between priority values and msg buckets. | |
Private Attributes | |
std::vector< const msg_t * > | randQ |
All the messages go in one bin when we're picking them out randomly. | |
size_t | qSize |
The size of this message queue. | |
bktmap_t | msgbuckets |
Collection of msg buckets, each holding msgs of a given priority (maps priorities to buckets). | |
std::priority_queue< prioidx_t, std::vector< prioidx_t > , std::greater< prioidx_t > > | prioQ |
A _min_ heap of distinct msg priorities along with handles to matching buckets. | |
std::deque< const msg_t * > | bkt |
Friends | |
std::ostream & | operator<< (std::ostream &out, const msgQ &q) |
An ostream operator overload, that currently just prints q size. | |
std::ostream & | operator<< (std::ostream &out, const msgQ &q) |
Templated on the type of the priority field. Defaults to int priority. All scheduling policies are encapsulated behind this queue interface.
All messages of a given priority p are stored in a single container. Since each message can be enqueued either to the front or back of this container, a dequeue is used. Each such dequeue is referred to as a bucket. The set of priority values of all the messages in the container is stored in a min-heap. A deq() operation simply peeks at the most important prio value, and finds the bucket associated with that value. It then dequeues the message at the front of this bucket. A mapping between the priority values and the corresponding buckets is maintained. enq() operations simply find the bucket corresponding to a prio value and place the msg into it.
Definition at line 37 of file msgq.h.
typedef P conv::msgQ< P >::prio_t |
typedef std::deque<const msg_t*> conv::msgQ< P >::bkt_t [private] |
typedef std::pair<prio_t, bkt_t*> conv::msgQ< P >::prioidx_t [private] |
typedef std::unordered_map<prio_t, bkt_t> conv::msgQ< P >::bktmap_t [private] |
typedef P conv::msgQ< P >::prio_t |
conv::msgQ< P >::msgQ | ( | ) | [inline] |
conv::msgQ< P >::msgQ | ( | ) | [inline] |
void conv::msgQ< P >::enq | ( | const msg_t * | msg, | |
const prio_t & | prio = prio_t() , |
|||
const bool | isFifo = true | |||
) | [inline] |
Given a message (optionally with a priority and queuing policy), enqueue it for delivery.
Definition at line 94 of file msgq.h.
References conv::msgQ< P >::bkt, conv::msgQ< P >::msgbuckets, conv::msgQ< P >::prioQ, conv::msgQ< P >::qSize, and conv::msgQ< P >::randQ.
const msg_t * conv::msgQ< P >::deq | ( | void | ) | [inline] |
Pop (and return) the next message to deliver.
For detecting races, and for a general check that applications dont depend on priorities or message ordering for correctness, charm can be built with a randomized scheduler queue.
In this case, this container's deq() operation will not actually respect priorities. Instead it simply returns a randomly selected msg.
Definition at line 140 of file msgq.h.
References conv::msgQ< P >::bkt, conv::msgQ< P >::empty(), msg, conv::msgQ< P >::msgbuckets, conv::msgQ< P >::prioQ, and conv::msgQ< P >::qSize.
size_t conv::msgQ< P >::size | ( | void | ) | const [inline] |
Number of messages in the queue.
Definition at line 53 of file msgq.h.
References conv::msgQ< P >::qSize.
Referenced by CqsEnumerateQueue().
size_t conv::msgQ< P >::max_size | ( | ) | const [inline] |
bool conv::msgQ< P >::empty | ( | ) | const [inline] |
Is the queue empty?
Definition at line 57 of file msgq.h.
References conv::msgQ< P >::qSize.
Referenced by conv::msgQ< P >::deq().
void conv::msgQ< P >::enumerate | ( | msg_t ** | first, | |
msg_t ** | last | |||
) | const [inline] |
Just so that we can support CqsEnumerateQueue().
Definition at line 196 of file msgq.h.
References conv::msgQ< P >::msgbuckets, and conv::msgQ< P >::randQ.
Referenced by CqsEnumerateQueue().
size_t conv::msgQ< P >::size | ( | void | ) | const [inline] |
size_t conv::msgQ< P >::max_size | ( | ) | const [inline] |
bool conv::msgQ< P >::empty | ( | ) | const [inline] |
void conv::msgQ< P >::enumerate | ( | msg_t ** | first, | |
msg_t ** | last | |||
) | const [inline] |
void conv::msgQ< P >::enq | ( | const msg_t * | msg, | |
const prio_t & | prio = prio_t() , |
|||
const bool | isFifo = true | |||
) | [inline] |
const msg_t* conv::msgQ< P >::deq | ( | void | ) | [inline] |
std::ostream& operator<< | ( | std::ostream & | out, | |
const msgQ< P > & | q | |||
) | [friend] |
std::ostream& operator<< | ( | std::ostream & | out, | |
const msgQ< P > & | q | |||
) | [friend] |
std::vector<const msg_t*> conv::msgQ< P >::randQ [private] |
All the messages go in one bin when we're picking them out randomly.
Definition at line 73 of file msgq.h.
Referenced by conv::msgQ< P >::enq(), and conv::msgQ< P >::enumerate().
size_t conv::msgQ< P >::qSize [private] |
The size of this message queue.
Definition at line 84 of file msgq.h.
Referenced by conv::msgQ< P >::deq(), conv::msgQ< P >::empty(), conv::msgQ< P >::enq(), and conv::msgQ< P >::size().
bktmap_t conv::msgQ< P >::msgbuckets [private] |
Collection of msg buckets, each holding msgs of a given priority (maps priorities to buckets).
Definition at line 86 of file msgq.h.
Referenced by conv::msgQ< P >::deq(), conv::msgQ< P >::enq(), and conv::msgQ< P >::enumerate().
std::priority_queue<prioidx_t, std::vector<prioidx_t>, std::greater<prioidx_t> > conv::msgQ< P >::prioQ [private] |
A _min_ heap of distinct msg priorities along with handles to matching buckets.
Definition at line 88 of file msgq.h.
Referenced by conv::msgQ< P >::deq(), and conv::msgQ< P >::enq().
std::deque<const msg_t*> conv::msgQ< P >::bkt [private] |
Definition at line 243 of file msgq.h.
Referenced by conv::msgQ< P >::deq(), conv::msgQ< P >::empty(), conv::msgQ< P >::enq(), conv::msgQ< P >::max_size(), and conv::msgQ< P >::size().