Fast Queue

Collaboration diagram for Fast Queue:

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_tcreate_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_tconsumer_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 Documentation

#define _GNU_SOURCE

Definition at line 45 of file fastqueue.c.

#define error_check ( status,
string   )     if (status==-1) perror(string);

Definition at line 42 of file testqueue.c.

#define MAXELEMENTS   10000

Definition at line 45 of file testqueue.c.

Referenced by consumertask(), and producertask().

#define PTHREAD_MUTEX_ERRORCHECK   PTHREAD_MUTEX_ERRORCHECK_NP

#define PTHREAD_MUTEX_NORMAL   PTHREAD_MUTEX_NORMAL_NP

#define pthread_mutexattr_settype   pthread_mutexattr_settype_np

#define qerr ( errnr   )     fprintf(stderr,"queue.c: %s\n",queue_errmsg[errnr])


Typedef Documentation

typedef int clockid_t

Definition at line 40 of file eclock_gettime.c.


Enumeration Type Documentation

anonymous enum

Enumerator:
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.


Function Documentation

unsigned long protlib::FastQueue::cleanup (  )  [inherited]

delete stored messages

Put queue into shutdown mode and delete all stored messages..

Returns:
the number of messages that were in the queue

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  ) 

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.

Parameters:
blocking if true, block until a message arrives
Returns:
the message, or NULL

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  ) 

void* dequeue_element_timedwait ( queue_t queuehead,
const struct timespec *  tspec 
)

void* dequeue_element_wait ( queue_t queuehead  ) 

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.

Parameters:
tspec the time to wait
Returns:
the message, or NULL

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.

Parameters:
msec the time to wait in milliseconds
Returns:
the message, or NULL

Definition at line 105 of file fqueue.cpp.

References dequeue_element_timedwait(), and protlib::FastQueue::queue.

int destroy_queue ( queue_t queuehead  ) 

int eclock_gettime ( struct timespec *  tp  ) 

Definition at line 50 of file eclock_gettime.c.

References tv.

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.

Returns:
true, if expedited messages were previously enabled, false otherwise

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.

Parameters:
element a pointer to the message to add
exp true if this is expedited data
Returns:
true if the element was enqueued successfully

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 
)

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.

Parameters:
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.

Returns:
true 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.

Returns:
true 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  ) 

Definition at line 59 of file testqueue.c.

References enqueue_element_signal(), and MAXELEMENTS.

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  ) 

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.

Returns:
the number of enqueued messages

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.


Variable Documentation

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

Definition at line 51 of file testqueue.c.

Referenced by consumertask().

int status

struct timespec ts_start ts_end

queue for consumertask

Definition at line 56 of file testqueue.c.

Referenced by consumertask().

struct timeval tv [static]

Definition at line 39 of file eclock_gettime.c.

Referenced by eclock_gettime().


Generated on Fri Aug 14 23:38:35 2009 for Ariba by  doxygen 1.5.8