UCommon
|
Somewhat generic queue processing class to establish a producer consumer queue. More...
#include <thread.h>
Inherits ost::Mutex, ost::Thread, and ost::Semaphore.
Public Member Functions | |
void | post (const void *data, unsigned len) |
Put some unspecified data into this queue. More... | |
void | setTimer (timeout_t timeout) |
Set the queue timeout. More... | |
ThreadQueue (const char *id, int pri, size_t stack=0) | |
Create instance of our queue and give it a process priority. More... | |
virtual | ~ThreadQueue () |
Destroy the queue. | |
![]() | |
void | enter (void) |
void | enterMutex (void) |
void | leave (void) |
void | leaveMutex (void) |
bool | test (void) |
bool | tryEnterMutex (void) |
![]() | |
void | detach (void) |
void | exit (void) |
virtual void | final (void) |
void | finalize (void) |
pthread_t | getId (void) const |
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) | |
![]() | |
void | post (void) |
Semaphore (unsigned size=0) | |
bool | wait (timeout_t timeout) |
void | wait (void) |
Protected Types | |
typedef struct ost::ThreadQueue::_data | data_t |
![]() | |
typedef autoexclusive < RecursiveMutex > | autolock |
![]() | |
enum | { R_UNUSED } |
![]() | |
typedef autoshared< Semaphore > | autosync |
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. More... | |
virtual void | startQueue (void) |
Start of dequeing. More... | |
virtual void | stopQueue (void) |
End of dequeing, we expect the queue is empty for now. More... | |
![]() | |
virtual void | _lock (void) |
virtual void | _unlock (void) |
void | lock (void) |
Acquire or increase locking. | |
bool | lock (timeout_t timeout) |
Timed lock request. | |
RecursiveMutex () | |
Create rexlock. | |
void | release (void) |
Release or decrease locking. | |
![]() | |
bool | is_active (void) const |
Check if running. | |
void | join (void) |
Join thread with parent. More... | |
JoinableThread (size_t size=0) | |
Create a joinable thread with a known context stack size. More... | |
virtual | ~JoinableThread () |
Delete child thread. More... | |
void | background (void) |
Start execution of child context as background thread. More... | |
void | start (int priority=0) |
Start execution of child context. More... | |
![]() | |
void | map (void) |
Map thread for get method. More... | |
Thread (size_t stack=0) | |
Create a thread object that will have a preset stack size. More... | |
virtual void | exit (void) |
Exit the thread context. More... | |
bool | isRunning (void) const |
operator bool () const | |
bool | operator! () const |
void | setPriority (void) |
Set thread priority without disrupting scheduling if possible. More... | |
virtual | ~Thread () |
Destroy thread object, thread-specific data, and execution context. | |
![]() | |
virtual void | _share (void) |
Access interface to share lock the object. | |
virtual void | _unshare (void) |
Semaphore & | operator= (const Semaphore &) |
Semaphore (const Semaphore &) | |
void | operator++ (void) |
Convenience operator to wait on a counting semaphore. | |
void | operator-- (void) |
Convenience operator to release a counting semaphore. | |
void | release (void) |
Release the semaphore after waiting for it. | |
Semaphore (unsigned count=0) | |
Construct a semaphore with an initial count of threads to permit. More... | |
Semaphore (unsigned count, unsigned avail) | |
Alternate onstructor with ability to preset available slots. More... | |
void | set (unsigned count) |
Alter semaphore limit at runtime. More... | |
void | wait (void) |
Wait until the semphore usage count is less than the thread limit. More... | |
bool | wait (timeout_t timeout) |
Wait until the semphore usage count is less than the thread limit. More... | |
virtual void | exclusive (void) |
Convert object to an exclusive lock. More... | |
virtual void | share (void) |
Share the lock with other referencers. More... | |
Protected Attributes | |
data_t * | first |
data_t * | last |
String | name |
bool | started |
timeout_t | timeout |
![]() | |
pthread_t | locker |
unsigned | lockers |
unsigned | waiting |
![]() | |
volatile bool | joining |
volatile bool | running |
![]() | |
void * | cancellor |
int | priority |
enum ucommon::Thread:: { ... } | reserved |
stacksize_t | stack |
pthread_t | tid |
![]() | |
unsigned | count |
unsigned | used |
unsigned | waits |
Additional Inherited Members | |
![]() | |
enum | Throw { throwNothing, throwObject, throwException } |
How to raise error. | |
typedef enum ost::Thread::Throw | Throw |
How to raise error. | |
![]() | |
static Thread * | get (void) |
static Throw | getException (void) |
Get exception mode of the current thread. More... | |
static void | setException (Throw mode) |
Set exception mode of the current thread. More... | |
static void | sleep (timeout_t msec=ucommon::Timer::inf) |
static void | yield (void) |
![]() | |
static size_t | cache (void) |
Get cache line size. | |
static void | concurrency (int level) |
Set concurrency level of process. More... | |
static bool | equal (pthread_t thread1, pthread_t thread2) |
Determine if two thread identifiers refer to the same thread. More... | |
static Thread * | get (void) |
Get mapped thread object. More... | |
static void | init (void) |
Used to initialize threading library. More... | |
static void | policy (int polid) |
Used to specify scheduling policy for threads above priority "0". More... | |
static void | release (void) |
static pthread_t | self (void) |
Get current thread id. More... | |
static void | sleep (timeout_t timeout) |
Sleep current thread for a specified time period. More... | |
static void | yield (void) |
Yield execution context of the current thread. More... | |
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.
ost::ThreadQueue::ThreadQueue | ( | const char * | id, |
int | pri, | ||
size_t | stack = 0 |
||
) |
Create instance of our queue and give it a process priority.
id | queue ID. |
pri | process priority. |
stack | stack size. |
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.
data | pointer to data. |
len | size of 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.
data | item 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
timeout | timeout in milliseconds. |
|
protectedvirtual |
Start of dequeing.
Maybe we need to connect a database or something, so we have a virtual...
|
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.