GNU CommonC++
Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
ost::ThreadQueue Class Referenceabstract

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

#include <buffer.h>

Inheritance diagram for ost::ThreadQueue:
ost::Mutex ost::Thread ost::Semaphore

Classes

struct  _data
 

Public Member Functions

 ThreadQueue (const char *id, int pri, size_t stack=0)
 Create instance of our queue and give it a process priority.
 
virtual ~ThreadQueue ()
 Destroy the queue.
 
void setTimer (timeout_t timeout)
 Set the queue timeout.
 
void post (const void *data, unsigned len)
 Put some unspecified data into this queue.
 
- Public Member Functions inherited from ost::Mutex
 Mutex (const char *name=NULL)
 The mutex is always initialized as a recursive entity.
 
virtual ~Mutex ()
 Destroying the mutex removes any system resources associated with it.
 
void nameMutex (const char *name)
 Enable setting of mutex name for deadlock debug.
 
void enterMutex (void)
 Entering a Mutex locks the mutex for the current thread.
 
void enter (void)
 Future abi will use enter/leave/test members.
 
void leave (void)
 Future abi will use enter/leave/test members.
 
bool test (void)
 Future abi will use enter/leave/test members.
 
bool tryEnterMutex (void)
 Tries to lock the mutex for the current thread.
 
void leaveMutex (void)
 Leaving a mutex frees that mutex for use by another thread.
 
- Public Member Functions inherited from ost::Thread
 Thread (bool isMain)
 This is actually a special constructor that is used to create a thread "object" for the current execution context when that context is not created via an instance of a derived Thread object itself.
 
 Thread (int pri=0, size_t stack=0)
 When a thread object is contructed, a new thread of execution context is created.
 
 Thread (const Thread &th)
 A thread of execution can also be specified by cloning an existing thread.
 
virtual ~Thread ()
 The thread destructor should clear up any resources that have been allocated by the thread.
 
int start (Semaphore *start=0)
 When a new thread is created, it does not begin immediate execution.
 
int detach (Semaphore *start=0)
 Start a new thread as "detached".
 
ThreadgetParent (void)
 Gets the pointer to the Thread class which created the current thread object.
 
void suspend (void)
 Suspends execution of the selected thread.
 
void resume (void)
 Resumes execution of the selected thread.
 
Cancel getCancel (void)
 Used to retrieve the cancellation mode in effect for the selected thread.
 
bool isRunning (void) const
 Verifies if the thread is still running or has already been terminated but not yet deleted.
 
bool isDetached (void) const
 Check if this thread is detached.
 
void join (void)
 Blocking call which unlocks when thread terminates.
 
bool isThread (void) const
 Tests to see if the current execution context is the same as the specified thread object.
 
cctid_t getId (void) const
 Get system thread numeric identifier.
 
const char * getName (void) const
 Get the name string for this thread, to use in debug messages.
 
- Public Member Functions inherited from ost::Semaphore
 Semaphore (unsigned resource=0)
 The initial value of the semaphore can be specified.
 
virtual ~Semaphore ()
 Destroying a semaphore also removes any system resources associated with it.
 
bool wait (timeout_t timeout=0)
 Wait is used to keep a thread held until the semaphore counter is greater than 0.
 
void post (void)
 Posting to a semaphore increments its current value and releases the first thread waiting for the semaphore if it is currently at 0.
 
void force_unlock_after_cancellation ()
 Call it after a deferred cancellation to avoid deadlocks.
 

Protected Types

typedef struct ost::ThreadQueue::_data data_t
 

Protected Member Functions

virtual void final ()
 
virtual void startQueue (void)
 Start of dequeing.
 
virtual void stopQueue (void)
 End of dequeing, we expect the queue is empty for now.
 
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.
 
- Protected Member Functions inherited from ost::Thread
void setName (const char *text)
 Set the name of the current thread.
 
virtual void run (void)=0
 All threads execute by deriving the Run method of Thread.
 
virtual void final (void)
 A thread that is self terminating, either by invoking exit() or leaving it's run(), will have this method called.
 
virtual void initial (void)
 The initial method is called by a newly created thread when it starts execution.
 
virtual void * getExtended (void)
 Since getParent() and getThread() only refer to an object of the Thread "base" type, this virtual method can be replaced in a derived class with something that returns data specific to the derived class that can still be accessed through the pointer returned by getParent() and getThread().
 
virtual void notify (Thread *)
 When a thread terminates, it now sends a notification message to the parent thread which created it.
 
void exit (void)
 Used to properly exit from a Thread derived run() or initial() method.
 
void sync (void)
 Used to wait for a join or cancel, in place of explicit exit.
 
bool testCancel (void)
 test a cancellation point for deferred thread cancellation.
 
void setCancel (Cancel mode)
 Sets thread cancellation mode.
 
void setSuspend (Suspend mode)
 Sets the thread's ability to be suspended from execution.
 
void terminate (void)
 Used by another thread to terminate the current thread.
 
void clrParent (void)
 clear parent thread relationship.
 

Protected Attributes

timeout_t timeout
 
bool started
 
data_tfirst
 
data_tlast
 
String name
 

Additional Inherited Members

- Public Types inherited from ost::Thread
enum  Throw { throwNothing , throwObject , throwException }
 How to raise error. More...
 
enum  Cancel {
  cancelInitial =0 , cancelDeferred =1 , cancelImmediate , cancelDisabled ,
  cancelManual , cancelDefault =cancelDeferred
}
 How work cancellation. More...
 
enum  Suspend { suspendEnable , suspendDisable }
 How work suspend. More...
 
typedef enum ost::Thread::Throw Throw
 How to raise error.
 
typedef enum ost::Thread::Cancel Cancel
 How work cancellation.
 
typedef enum ost::Thread::Suspend Suspend
 How work suspend.
 
- Static Public Member Functions inherited from ost::Mutex
static void setDebug (bool mode)
 Enable or disable deadlock debugging.
 
- Static Public Member Functions inherited from ost::Thread
static Threadget (void)
 
static void setStack (size_t size=0)
 Set base stack limit before manual stack sizes have effect.
 
static void sleep (timeout_t msec)
 A thread-safe sleep call.
 
static void yield (void)
 Yields the current thread's CPU time slice to allow another thread to begin immediate execution.
 
static Throw getException (void)
 Get exception mode of the current thread.
 
static void setException (Throw mode)
 Set exception mode of the current thread.
 
static Cancel enterCancel (void)
 This is used to help build wrapper functions in libraries around system calls that should behave as cancellation points but don't.
 
static void exitCancel (Cancel cancel)
 This is used to restore a cancel block.
 

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

Member Typedef Documentation

◆ data_t

Constructor & Destructor Documentation

◆ ThreadQueue()

ost::ThreadQueue::ThreadQueue ( const 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.

◆ ~ThreadQueue()

virtual ost::ThreadQueue::~ThreadQueue ( )
virtual

Destroy the queue.

Member Function Documentation

◆ final()

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

Reimplemented from ost::Thread.

◆ onTimer()

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

A derivable method to call when the timout is expired.

◆ post()

void ost::ThreadQueue::post ( const 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.

◆ runQueue()

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.

◆ setTimer()

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.

◆ startQueue()

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

Start of dequeing.

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

◆ stopQueue()

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.

Member Data Documentation

◆ first

data_t* ost::ThreadQueue::first
protected

◆ last

data_t * ost::ThreadQueue::last
protected

◆ name

String ost::ThreadQueue::name
protected

◆ started

bool ost::ThreadQueue::started
protected

◆ timeout

timeout_t ost::ThreadQueue::timeout
protected

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