ucommon
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes
ost::ThreadQueue Class Reference

Somewhat generic queue processing class to establish a producer consumer queue. More...

#include <thread.h>

Inherits ost::Mutex, ost::Thread, and ost::Semaphore.

Collaboration diagram for ost::ThreadQueue:
Collaboration graph
[legend]

Public Member Functions

void post (void *data, unsigned len)
 Put some unspecified data into this queue.
void setTimer (timeout_t timeout)
 Set the queue timeout.
 ThreadQueue (char *id, int pri, size_t stack=0)
 Create instance of our queue and give it a process priority.
virtual ~ThreadQueue ()
 Destroy the queue.
- Public Member Functions inherited from ost::Mutex
void enter (void)
void enterMutex (void)
void leave (void)
void leaveMutex (void)
bool test (void)
bool tryEnterMutex (void)
- Public Member Functions inherited from ost::Thread
void detach (void)
void exit (void)
virtual void final (void)
void finalize (void)
pthread_t getId (void)
 Get the thread id.
virtual void initial (void)
bool isRunning (void)
bool isThread (void)
void join (void)
void map (void)
virtual void notify (Thread *thread)
virtual void run (void)=0
void start (void)
void sync (void)
void terminate (void)
 Thread (int pri=0, size_t stack=0)
- Public Member Functions inherited from ost::Semaphore
void post (void)
 Semaphore (unsigned size)
bool wait (timeout_t timeout=0)

Protected Types

typedef struct
ost::ThreadQueue::_data 
data_t

Protected Member Functions

virtual void final ()
virtual void onTimer (void)
 A derivable method to call when the timout is expired.
virtual void runQueue (void *data)=0
 Virtual callback method to handle processing of a queued data items.
virtual void startQueue (void)
 Start of dequeing.
virtual void stopQueue (void)
 End of dequeing, we expect the queue is empty for now.

Protected Attributes

data_t * first
data_t * last
String name
bool started
timeout_t timeout

Additional Inherited Members

- Public Types inherited from ost::Thread
enum  Throw { throwNothing, throwObject, throwException }
 How to raise error.
typedef enum ost::Thread::Throw Throw
 How to raise error.
- Static Public Member Functions inherited from ost::Thread
static Thread * get (void)
static Throw getException (void)
 Get exception mode of the current thread.
static void setException (Throw mode)
 Set exception mode of the current thread.
static void sleep (timeout_t msec=ucommon::Timer::inf)
static void yield (void)
- Static Protected Member Functions inherited from ucommon::RecursiveMutex
static void lock (RecursiveMutex &rex)
 Convenience method to lock a recursive lock.
static void release (RecursiveMutex &rex)
 Convenience method to unlock a recursive lock.

Detailed Description

Somewhat generic queue processing class to establish a producer consumer queue.

This may be used to buffer cdr records, or for other purposes where an in-memory queue is needed for rapid posting. This class is derived from Mutex and maintains a linked list. A thread is used to dequeue data and pass it to a callback method that is used in place of "run" for each item present on the queue. The conditional is used to signal the run thread when new data is posted.

This class was changed by Angelo Naselli to have a timeout on the queue

in memory data queue interface.

Author
David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m

Definition at line 779 of file thread.h.

Constructor & Destructor Documentation

ost::ThreadQueue::ThreadQueue ( char *  id,
int  pri,
size_t  stack = 0 
)

Create instance of our queue and give it a process priority.

Parameters
idqueue ID.
priprocess priority.
stackstack size.

Member Function Documentation

void ost::ThreadQueue::post ( void *  data,
unsigned  len 
)

Put some unspecified data into this queue.

A new qd structure is created and sized to contain a copy of the actual content.

Parameters
datapointer to data.
lensize of data.
virtual void ost::ThreadQueue::runQueue ( void *  data)
protectedpure virtual

Virtual callback method to handle processing of a queued data items.

After the item is processed, it is deleted from memory. We can call multiple instances of runQueue in order if multiple items are waiting.

Parameters
dataitem being dequed.
void ost::ThreadQueue::setTimer ( timeout_t  timeout)

Set the queue timeout.

When the timer expires, the onTimer() method is called for the thread

Parameters
timeouttimeout in milliseconds.
virtual void ost::ThreadQueue::startQueue ( void  )
protectedvirtual

Start of dequeing.

Maybe we need to connect a database or something, so we have a virtual...

virtual void ost::ThreadQueue::stopQueue ( void  )
protectedvirtual

End of dequeing, we expect the queue is empty for now.

Maybe we need to disconnect a database or something, so we have another virtual.


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