log4cplus
2.1.0
|
Single consumer, multiple producers queue. More...
#include <queue.h>
Public Types | |
enum | Flags { EVENT = 0x0001 , QUEUE = 0x0002 , EXIT = 0x0004 , DRAIN = 0x0008 , ERROR_BIT = 0x0010 , ERROR_AFTER = 0x0020 } |
Possible state flags. More... | |
typedef unsigned | flags_type |
Type of the state flags field. More... | |
typedef std::deque< spi::InternalLoggingEvent > | queue_storage_type |
Queue storage type. More... | |
Public Member Functions | |
Queue (unsigned len=100) | |
virtual | ~Queue () |
flags_type | put_event (spi::InternalLoggingEvent const &ev) |
Puts event ev into queue, sets QUEUE flag and sets internal event object into signaled state. More... | |
flags_type | signal_exit (bool drain=true) |
Sets EXIT flag and DRAIN flag and sets internal event object into signaled state. More... | |
flags_type | get_events (queue_storage_type *buf) |
The get_events() function is used by queue's consumer. More... | |
Public Member Functions inherited from log4cplus::helpers::SharedObject | |
void | addReference () const LOG4CPLUS_NOEXCEPT |
void | removeReference () const |
Protected Attributes | |
queue_storage_type | queue |
Queue storage. More... | |
Mutex | mutex |
Mutex protecting queue and flags. More... | |
ManualResetEvent | ev_consumer |
Event on which consumer can wait if it finds queue empty. More... | |
Semaphore | sem |
Semaphore that limits the queue length. More... | |
flags_type | flags |
State flags. More... | |
Additional Inherited Members | |
Public Attributes inherited from log4cplus::helpers::SharedObject | |
thread::Mutex | access_mutex |
Protected Member Functions inherited from log4cplus::helpers::SharedObject | |
SharedObject () | |
SharedObject (const SharedObject &) | |
SharedObject (SharedObject &&) | |
virtual | ~SharedObject () |
SharedObject & | operator= (const SharedObject &) LOG4CPLUS_NOEXCEPT |
SharedObject & | operator= (SharedObject &&) LOG4CPLUS_NOEXCEPT |
typedef unsigned log4cplus::thread::Queue::flags_type |
typedef std::deque<spi::InternalLoggingEvent> log4cplus::thread::Queue::queue_storage_type |
Possible state flags.
Enumerator | |
---|---|
EVENT | EVENT flag is set in return value of get_event() call if the |
QUEUE | QUEUE flag is set by producers when they put item into the queue. |
EXIT | EXIT flag is set by signal_exit() call, signaling that the queue worker thread should end itself. |
DRAIN | When DRAIN flag is set together with EXIT flag, the queue worker thread will first drain the queue before exiting. |
ERROR_BIT | ERROR_BIT signals error. |
ERROR_AFTER | ERROR_AFTER signals error that has occurred after queue has already been touched. |
|
explicit |
|
virtual |
flags_type log4cplus::thread::Queue::get_events | ( | queue_storage_type * | buf | ) |
The get_events() function is used by queue's consumer.
It fills buf
argument and sets EVENT flag in return value. If EXIT flag is already set in flags member upon entering the function then depending on DRAIN flag it either fills buf
argument or does not fill the argument, if the queue is non-empty. The function blocks by waiting for internal event object to be signaled if the queue is empty, unless EXIT flag is set. The calling thread is unblocked when items are added into the queue or when exit is signaled using the signal_exit() function.
Upon error, return value has one of the error flags set.
buf | Pointer to storage of spi::InternalLoggingEvent instances to be filled from queue. |
flags_type log4cplus::thread::Queue::put_event | ( | spi::InternalLoggingEvent const & | ev | ) |
Puts event ev
into queue, sets QUEUE flag and sets internal event object into signaled state.
If the EXIT flags is already set upon entering the function, nothing is inserted into the queue. The function can block on internal semaphore if the queue has reached maximal allowed length. Calling thread is unblocked either by consumer thread removing item from queue or by any other thread calling signal_exit().
ev | spi::InternalLoggingEvent to be put into the queue. |
flags_type log4cplus::thread::Queue::signal_exit | ( | bool | drain = true | ) |
Sets EXIT flag and DRAIN flag and sets internal event object into signaled state.
drain | If true, DRAIN flag will be set, otherwise unset. |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |