log4cplus  2.1.0
Public Types | Public Member Functions | Protected Attributes | List of all members
log4cplus::thread::Queue Class Reference

Single consumer, multiple producers queue. More...

#include <queue.h>

Inheritance diagram for log4cplus::thread::Queue:
[legend]
Collaboration diagram for log4cplus::thread::Queue:
[legend]

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::InternalLoggingEventqueue_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 ()
 
SharedObjectoperator= (const SharedObject &) LOG4CPLUS_NOEXCEPT
 
SharedObjectoperator= (SharedObject &&) LOG4CPLUS_NOEXCEPT
 

Detailed Description

Single consumer, multiple producers queue.

Definition at line 46 of file queue.h.

Member Typedef Documentation

◆ flags_type

Type of the state flags field.

Definition at line 51 of file queue.h.

◆ queue_storage_type

Queue storage type.

Definition at line 54 of file queue.h.

Member Enumeration Documentation

◆ Flags

Possible state flags.

Enumerator
EVENT 

EVENT flag is set in return value of get_event() call if the ev argument is filled with event from the queue.

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.

Definition at line 102 of file queue.h.

Constructor & Destructor Documentation

◆ Queue()

log4cplus::thread::Queue::Queue ( unsigned  len = 100)
explicit

◆ ~Queue()

virtual log4cplus::thread::Queue::~Queue ( )
virtual

Member Function Documentation

◆ get_events()

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.

Parameters
bufPointer to storage of spi::InternalLoggingEvent instances to be filled from queue.
Returns
Flags.

◆ put_event()

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().

Parameters
evspi::InternalLoggingEvent to be put into the queue.
Returns
Flags.

◆ signal_exit()

flags_type log4cplus::thread::Queue::signal_exit ( bool  drain = true)

Sets EXIT flag and DRAIN flag and sets internal event object into signaled state.

Parameters
drainIf true, DRAIN flag will be set, otherwise unset.
Returns
Flags, ERROR_BIT can be set upon error.

Member Data Documentation

◆ ev_consumer

ManualResetEvent log4cplus::thread::Queue::ev_consumer
protected

Event on which consumer can wait if it finds queue empty.

Definition at line 136 of file queue.h.

◆ flags

flags_type log4cplus::thread::Queue::flags
protected

State flags.

Definition at line 142 of file queue.h.

◆ mutex

Mutex log4cplus::thread::Queue::mutex
protected

Mutex protecting queue and flags.

Definition at line 133 of file queue.h.

◆ queue

queue_storage_type log4cplus::thread::Queue::queue
protected

Queue storage.

Definition at line 130 of file queue.h.

◆ sem

Semaphore log4cplus::thread::Queue::sem
protected

Semaphore that limits the queue length.

Definition at line 139 of file queue.h.


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