![]() |
Classes | |
class | protlib::FastQueue |
Namespaces | |
namespace | protlib |
Modules | |
Queue Manager | |
Files | |
file | fastqueue.c |
file | fastqueue.h |
Defines | |
#define | _GNU_SOURCE |
#define | qerr(errnr) fprintf(stderr,"queue.c: %s\n",queue_errmsg[errnr]) |
#define | pthread_mutexattr_settype pthread_mutexattr_settype_np |
#define | PTHREAD_MUTEX_NORMAL PTHREAD_MUTEX_NORMAL_NP |
#define | PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK_NP |
Typedefs | |
typedef int | clockid_t |
Enumerations | |
enum | { QERR_NONE, QERR_NOMEM, QERR_MUTEXINIT, QERR_MUTEXLOCK, QERR_MUTEXUNLOCK, QERR_MUTEXDESTROY, QERR_QEMPTY, QERR_QINVALID, QERR_QNOTEMPTY, QERR_CONDINIT, QERR_CONDWAIT, QERR_CONDSIGNAL, QERR_CONDDESTROY } |
Functions | |
int | eclock_gettime (struct timespec *tp) |
queue_t * | create_queue (const char *name) |
int | enqueue_element_signal (queue_t *queuehead, void *element) |
int | enqueue_element_expedited_signal (queue_t *queuehead, void *element, int exp) |
void * | dequeue_element_wait (queue_t *queuehead) |
void * | dequeue_element_timedwait (queue_t *queuehead, const struct timespec *tspec) |
int | destroy_queue (queue_t *queuehead) |
void * | dequeue_element_nonblocking (queue_t *queuehead) |
unsigned long | queue_nr_of_elements (queue_t *queuehead) |
int | queue_is_expedited_enabled (queue_t *queuehead) |
int | queue_enable_expedited (queue_t *queuehead, int exp) |
protlib::FastQueue::FastQueue (const char *qname=0, bool exp=false) | |
constructor | |
bool | protlib::FastQueue::enqueue (message *element, bool exp=false) |
enqueue message | |
message * | protlib::FastQueue::dequeue_timedwait (const long int msec) |
dequeue message, timed wait | |
protlib::FastQueue::~FastQueue () | |
destructor | |
bool | protlib::FastQueue::is_empty () const |
is queue empty | |
unsigned long | protlib::FastQueue::size () const |
get number of enqueued messages | |
bool | protlib::FastQueue::is_expedited_enabled () const |
is expedited data support enabled | |
bool | protlib::FastQueue::enable_expedited (bool exp) |
enable/disable expedited data | |
void | protlib::FastQueue::shutdown () |
shutdown queue, do not accept messages | |
unsigned long | protlib::FastQueue::cleanup () |
delete stored messages | |
message * | protlib::FastQueue::dequeue (bool blocking=true) |
dequeue message | |
message * | protlib::FastQueue::dequeue_timedwait (const struct timespec &tspec) |
dequeue message, timed wait | |
Variables | |
static struct timeval | tv |
const char *const | queue_errmsg [] |
pthread_t | producer_thread |
pthread_t | consumer_thread |
float | queuetime |
float | porttime |
queue_t * | consumer_cmdq |
struct timespec ts_start | ts_end |
int | status |
void * | producertask (void *argp) |
void * | consumertask (void *argp) |
#define | error_check(status, string) if (status==-1) perror(string); |
#define | MAXELEMENTS 10000 |
#define _GNU_SOURCE |
Definition at line 45 of file fastqueue.c.
Definition at line 42 of file testqueue.c.
#define MAXELEMENTS 10000 |
#define PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK_NP |
Definition at line 80 of file fastqueue.c.
Referenced by create_queue(), protlib::QueueManager::QueueManager(), protlib::Thread::Thread(), and protlib::TimerManager::TimerManager().
#define PTHREAD_MUTEX_NORMAL PTHREAD_MUTEX_NORMAL_NP |
Definition at line 79 of file fastqueue.c.
Referenced by create_queue(), protlib::QueueManager::QueueManager(), protlib::Thread::Thread(), and protlib::TimerManager::TimerManager().
#define pthread_mutexattr_settype pthread_mutexattr_settype_np |
Definition at line 78 of file fastqueue.c.
Referenced by create_queue(), protlib::QueueManager::QueueManager(), protlib::Thread::Thread(), and protlib::TimerManager::TimerManager().
#define qerr | ( | errnr | ) | fprintf(stderr,"queue.c: %s\n",queue_errmsg[errnr]) |
Definition at line 58 of file fastqueue.c.
Referenced by create_queue(), dequeue_element_nonblocking(), dequeue_element_timedwait(), dequeue_element_wait(), destroy_queue(), enqueue_element_expedited_signal(), queue_enable_expedited(), queue_is_expedited_enabled(), and queue_nr_of_elements().
typedef int clockid_t |
Definition at line 40 of file eclock_gettime.c.
anonymous enum |
QERR_NONE | |
QERR_NOMEM | |
QERR_MUTEXINIT | |
QERR_MUTEXLOCK | |
QERR_MUTEXUNLOCK | |
QERR_MUTEXDESTROY | |
QERR_QEMPTY | |
QERR_QINVALID | |
QERR_QNOTEMPTY | |
QERR_CONDINIT | |
QERR_CONDWAIT | |
QERR_CONDSIGNAL | |
QERR_CONDDESTROY |
Definition at line 84 of file fastqueue.c.
unsigned long protlib::FastQueue::cleanup | ( | ) | [inherited] |
delete stored messages
Put queue into shutdown mode and delete all stored messages..
Definition at line 200 of file fqueue.cpp.
References protlib::FastQueue::dequeue(), protlib::FastQueue::is_empty(), and protlib::FastQueue::shutdownflag.
Referenced by ariba::transport::tcpip::receiverThread(), and protlib::FastQueue::~FastQueue().
void* consumertask | ( | void * | argp | ) |
test queue
Definition at line 70 of file testqueue.c.
References dequeue_element_wait(), MAXELEMENTS, queuetime, and ts_end.
queue_t* create_queue | ( | const char * | name | ) |
Definition at line 120 of file fastqueue.c.
References queue_struct::cond, queue_struct::exp_enabled, queue_struct::exp_first_block, queue_struct::exp_last_block, queue_struct::exp_nr_of_elements, queue_struct::first_block, queue_struct::last_block, MAX_QUEUENAME_LENGTH, queue_struct::mutex, queue_struct::mutex_attr, queue_struct::name, queue_elblock_struct::next_block, queue_struct::nr_of_elements, PTHREAD_MUTEX_ERRORCHECK, PTHREAD_MUTEX_NORMAL, pthread_mutexattr_settype, qerr, QERR_CONDINIT, QERR_MUTEXINIT, QERR_NOMEM, queue_struct::queue_maxlength, queue_elblock_struct::read, and queue_elblock_struct::write.
Referenced by protlib::FastQueue::FastQueue().
message * protlib::FastQueue::dequeue | ( | bool | blocking = true |
) | [inline, inherited] |
dequeue message
Remove the first message from the queue.
Messages are removed in the same order they were added to the queue (FIFO). If the expedited messages feature is enabled, there's an exception to this rule: Expedited messages are always removed before all other messages. The FIFO condition still holds among expedited messages, however.
If blocking is set, wait infinitely for a message. If set to false, return immediately if the queue is empty. In this case, NULL is returned.
blocking | if true, block until a message arrives |
Definition at line 120 of file fqueue.h.
References dequeue_element_nonblocking(), dequeue_element_wait(), and protlib::FastQueue::queue.
Referenced by protlib::FastQueue::cleanup(), and protlib::TPoverTCP::sender_thread().
void* dequeue_element_nonblocking | ( | queue_t * | queuehead | ) |
Definition at line 500 of file fastqueue.c.
References queue_elblock_struct::element, ELEMENT_BLOCKSIZE, queue_struct::exp_first_block, queue_struct::exp_nr_of_elements, queue_struct::first_block, queue_struct::mutex, queue_elblock_struct::next_block, queue_struct::nr_of_elements, qerr, QERR_MUTEXLOCK, QERR_MUTEXUNLOCK, QERR_QEMPTY, QERR_QINVALID, queue_elblock_struct::read, and queue_elblock_struct::write.
Referenced by protlib::FastQueue::dequeue().
void* dequeue_element_timedwait | ( | queue_t * | queuehead, | |
const struct timespec * | tspec | |||
) |
Definition at line 358 of file fastqueue.c.
References queue_struct::cond, queue_elblock_struct::element, ELEMENT_BLOCKSIZE, queue_struct::exp_first_block, queue_struct::exp_nr_of_elements, queue_struct::first_block, queue_struct::mutex, queue_elblock_struct::next_block, queue_struct::nr_of_elements, qerr, QERR_CONDWAIT, QERR_MUTEXLOCK, QERR_MUTEXUNLOCK, QERR_QEMPTY, QERR_QINVALID, queue_elblock_struct::read, and queue_elblock_struct::write.
Referenced by protlib::FastQueue::dequeue_timedwait().
void* dequeue_element_wait | ( | queue_t * | queuehead | ) |
Definition at line 276 of file fastqueue.c.
References queue_struct::cond, queue_elblock_struct::element, ELEMENT_BLOCKSIZE, queue_struct::exp_first_block, queue_struct::exp_nr_of_elements, queue_struct::first_block, queue_struct::mutex, queue_elblock_struct::next_block, queue_struct::nr_of_elements, qerr, QERR_CONDWAIT, QERR_MUTEXLOCK, QERR_MUTEXUNLOCK, QERR_QEMPTY, QERR_QINVALID, queue_elblock_struct::read, and queue_elblock_struct::write.
Referenced by consumertask(), and protlib::FastQueue::dequeue().
message * protlib::FastQueue::dequeue_timedwait | ( | const struct timespec & | tspec | ) | [inline, inherited] |
dequeue message, timed wait
Wait for a message for a given time.
If no message arrives in the given time period, NULL is returned.
tspec | the time to wait |
Definition at line 139 of file fqueue.h.
References dequeue_element_timedwait(), and protlib::FastQueue::queue.
Referenced by protlib::TPoverTCP::main_loop(), protlib::TimerModule::process_queue(), and ariba::transport::tcpip::receiverThread().
message * protlib::FastQueue::dequeue_timedwait | ( | const long int | msec | ) | [inherited] |
dequeue message, timed wait
Wait for a message for a given time.
If no message arrives in the given time period, NULL is returned.
msec | the time to wait in milliseconds |
Definition at line 105 of file fqueue.cpp.
References dequeue_element_timedwait(), and protlib::FastQueue::queue.
int destroy_queue | ( | queue_t * | queuehead | ) |
Definition at line 461 of file fastqueue.c.
References queue_struct::cond, queue_struct::exp_last_block, queue_struct::last_block, queue_struct::mutex, queue_struct::mutex_attr, queue_struct::name, queue_struct::nr_of_elements, qerr, QERR_CONDDESTROY, QERR_MUTEXDESTROY, QERR_QINVALID, QERR_QNOTEMPTY, and queue_struct::queue_maxlength.
Referenced by protlib::FastQueue::~FastQueue().
int eclock_gettime | ( | struct timespec * | tp | ) |
bool protlib::FastQueue::enable_expedited | ( | bool | exp | ) | [inherited] |
enable/disable expedited data
Enable or disable expedited messages.
This also returns the previous value of this flag.
Definition at line 178 of file fqueue.cpp.
References protlib::FastQueue::queue, and queue_enable_expedited().
bool protlib::FastQueue::enqueue | ( | message * | element, | |
bool | exp = false | |||
) | [inherited] |
enqueue message
Add a message to the queue.
If exp is true and the queue allows expedited data, the message will pass all normal messages in the queue and thus will be delivered earlier. If there are other expedited messages in the queue already, it will be added after the already existing expedited messages.
This method may fail (and return false) if the queue is in shutdown mode, there is a problem aquiring locks, or some other threading problem.
In case the queue is deleted before this message has been removed, this message is deleted using the delete operator. Because of this, the same message may only appear once in a queue.
element | a pointer to the message to add | |
exp | true if this is expedited data |
Definition at line 84 of file fqueue.cpp.
References enqueue_element_expedited_signal(), protlib::log::ERROR_LOG, Log, protlib::log::LOG_ALERT, protlib::FastQueue::queue, protlib::FastQueue::queue_name, and protlib::FastQueue::shutdownflag.
Referenced by protlib::message::send(), protlib::message::send_back(), and protlib::message::send_to().
int enqueue_element_expedited_signal | ( | queue_t * | queuehead, | |
void * | element, | |||
int | exp | |||
) |
Definition at line 199 of file fastqueue.c.
References queue_struct::cond, queue_elblock_struct::element, ELEMENT_BLOCKSIZE, queue_struct::exp_enabled, queue_struct::exp_last_block, queue_struct::exp_nr_of_elements, queue_struct::last_block, queue_struct::mutex, queue_elblock_struct::next_block, queue_struct::nr_of_elements, qerr, QERR_CONDSIGNAL, QERR_MUTEXLOCK, QERR_MUTEXUNLOCK, QERR_NOMEM, QERR_QINVALID, queue_struct::queue_maxlength, queue_elblock_struct::read, and queue_elblock_struct::write.
Referenced by protlib::FastQueue::enqueue(), and enqueue_element_signal().
int enqueue_element_signal | ( | queue_t * | queuehead, | |
void * | element | |||
) |
Definition at line 194 of file fastqueue.c.
References enqueue_element_expedited_signal().
Referenced by producertask().
protlib::FastQueue::FastQueue | ( | const char * | qname = 0 , |
|
bool | exp = false | |||
) | [inherited] |
constructor
Constructor.
Initialize a FastQueue with a queue name and enable/disable expedited data.
qname | the queue's name, or NULL | |
exp | if true, expedited data support is enabled |
Definition at line 53 of file fqueue.cpp.
References create_queue(), protlib::log::ERROR_LOG, Log, protlib::log::LOG_ALERT, protlib::FastQueue::queue, queue_enable_expedited(), and protlib::FastQueue::queue_name.
bool protlib::FastQueue::is_empty | ( | ) | const [inherited] |
is queue empty
Test if the queue is empty.
Definition at line 138 of file fqueue.cpp.
References protlib::FastQueue::queue, and queue_nr_of_elements().
Referenced by protlib::FastQueue::cleanup().
bool protlib::FastQueue::is_expedited_enabled | ( | ) | const [inherited] |
is expedited data support enabled
Test if expedited message support is enabled.
Definition at line 163 of file fqueue.cpp.
References protlib::FastQueue::queue, and queue_is_expedited_enabled().
void* producertask | ( | void * | argp | ) |
int queue_enable_expedited | ( | queue_t * | queuehead, | |
int | exp | |||
) |
Set exp_enabled flag and return old value.
Definition at line 623 of file fastqueue.c.
References queue_struct::exp_enabled, queue_struct::mutex, qerr, QERR_MUTEXLOCK, QERR_MUTEXUNLOCK, and QERR_QINVALID.
Referenced by protlib::FastQueue::enable_expedited(), and protlib::FastQueue::FastQueue().
int queue_is_expedited_enabled | ( | queue_t * | queuehead | ) |
Get exp_enabled flag.
Definition at line 598 of file fastqueue.c.
References queue_struct::exp_enabled, queue_struct::mutex, qerr, QERR_MUTEXLOCK, QERR_MUTEXUNLOCK, and QERR_QINVALID.
Referenced by protlib::FastQueue::is_expedited_enabled().
unsigned long queue_nr_of_elements | ( | queue_t * | queuehead | ) |
Get number fo elements in queue.
Definition at line 573 of file fastqueue.c.
References queue_struct::mutex, queue_struct::nr_of_elements, qerr, QERR_MUTEXLOCK, QERR_MUTEXUNLOCK, and QERR_QINVALID.
Referenced by protlib::FastQueue::is_empty(), and protlib::FastQueue::size().
void protlib::FastQueue::shutdown | ( | ) | [inherited] |
shutdown queue, do not accept messages
Disable enqueueing of new messages.
A queue in shutdown mode does not accept messages any more.
Definition at line 192 of file fqueue.cpp.
References protlib::FastQueue::shutdownflag.
Referenced by protlib::TPoverTCP::main_loop().
unsigned long protlib::FastQueue::size | ( | ) | const [inherited] |
get number of enqueued messages
Return the number of messages in the queue.
Definition at line 152 of file fqueue.cpp.
References protlib::FastQueue::queue, and queue_nr_of_elements().
protlib::FastQueue::~FastQueue | ( | ) | [inherited] |
destructor
Destructor.
Destroys the queue. All messages which are still in the queue are deleted using the delete operator.
Definition at line 120 of file fqueue.cpp.
References protlib::FastQueue::cleanup(), destroy_queue(), DLog, protlib::log::ERROR_LOG, Log, protlib::log::LOG_ALERT, protlib::FastQueue::queue, and protlib::FastQueue::queue_name.
both queues must be created before monitor tasks are started
Definition at line 55 of file testqueue.c.
pthread_t consumer_thread |
Definition at line 48 of file testqueue.c.
float porttime |
Definition at line 51 of file testqueue.c.
pthread_t producer_thread |
Definition at line 48 of file testqueue.c.
const char* const queue_errmsg[] |
Initial value:
{ "all ok", "can't get enough memory", "initializing mutex", "locking mutex", "unlocking mutex", "destroying mutex", "queue empty", "invalid queueobject", "destroying queue - queue not empty", "initializing queue condition variable", "waiting on condition", "signalling condition", "destroying condition" }
Definition at line 101 of file fastqueue.c.
float queuetime |
int status |
Definition at line 57 of file testqueue.c.
Referenced by protlib::TPoverTCP::get_connection_to(), protlib::TPoverUDP::listener_thread(), protlib::TPoverTCP::master_listener_thread(), protlib::setuid::off(), and protlib::setuid::on().
struct timespec ts_start ts_end |
struct timeval tv [static] |