Vault  4.1
Public Member Functions | Static Public Member Functions
VMessageQueue Class Reference

VMessageQueue is a thread-safe FIFO queue of messages. More...

#include <vmessagequeue.h>

List of all members.

Public Member Functions

 VMessageQueue ()
 Constructs the queue.
virtual ~VMessageQueue ()
 Virtual destructor.
virtual void postMessage (VMessagePtr message)
 Posts a message to the back of the queue.
VMessagePtr blockUntilNextMessage ()
 Returns the message at the front of the queue, blocking if the queue is empty.
VMessagePtr getNextMessage ()
 Returns the message at the front of the queue, or NULL if the queue is empty.
void wakeUp ()
 Wakes up the thread in case it is necessary to let the thread cycle even though there are no messages and it is blocked.
VSizeType getQueueSize () const
 Returns the number of messages currently in the queue.
Vs64 getQueueDataSize () const
 Returns the number of message bytes currently in the queue.
void releaseAllMessages ()
 Releases all messages in the queue.

Static Public Member Functions

static void setQueueingLagLoggingThreshold (const VDuration &threshold)
 The following methods set and get the configuration for emitting a log message if there is a lag between posting to a queue and the output thread getting a message.
static VDuration getQueueingLagLoggingThreshold ()
static void setQueueingLagLoggingLevel (int logLevel)
static int getQueueingLagLoggingLevel ()

Detailed Description

VMessageQueue is a thread-safe FIFO queue of messages.

Multiple threads may post messages to the queue (push to the back of the queue) using postMessage() and pull messages off the queue (pop from the front of the queue) using blockUntilNextMessage() or getNextMessage(). As its name implies, blockUntilNextMessage() blocks until a message is available, so it is useful as a way for a message processing thread to spin, processing each message on the queue, but blocking if there is nothing for it to do. By constrast, getNextMessage() simply returns the next message, or NULL, so the caller must decide how to manage de-queueing messages without chewing up the CPU needlessly (for UI apps this may mean a notification scheme so that the app's UI thread only looks at the queue when something gets posted to it).

Definition at line 36 of file vmessagequeue.h.


Member Function Documentation

void VMessageQueue::postMessage ( VMessagePtr  message) [virtual]

Posts a message to the back of the queue.

May be safely called from any thread.

Parameters:
messagethe message object to be posted; the queue becomes owner of the object while it is in the queue

Definition at line 32 of file vmessagequeue.cpp.

References VInstant::setNow(), VSemaphore::signal(), and VMutexLocker::unlock().

VMessagePtr VMessageQueue::blockUntilNextMessage ( )

Returns the message at the front of the queue, blocking if the queue is empty.

May be safely called from any thread.

Returns:
the message at the front of the queue; the caller becomes owner of the object

Definition at line 46 of file vmessagequeue.cpp.

References getNextMessage(), VDuration::SECOND(), and VSemaphore::wait().

VMessagePtr VMessageQueue::getNextMessage ( )

Returns the message at the front of the queue, or NULL if the queue is empty.

Returns:
the message at the front of the queue, or NULL; the caller becomes owner of the object

Definition at line 60 of file vmessagequeue.cpp.

References VString::chars(), VDuration::getDurationString(), VCompactingDeque< _Tp, _Alloc >::pop_front(), and VDuration::ZERO().

void VMessageQueue::wakeUp ( )

Wakes up the thread in case it is necessary to let the thread cycle even though there are no messages and it is blocked.

This is used during the shutdown process to allow the blocking thread to notice that it has been asked to terminate.

Definition at line 86 of file vmessagequeue.cpp.

References VSemaphore::signal().

VSizeType VMessageQueue::getQueueSize ( ) const

Returns the number of messages currently in the queue.

Returns:
obvious

Definition at line 90 of file vmessagequeue.cpp.

Vs64 VMessageQueue::getQueueDataSize ( ) const

Returns the number of message bytes currently in the queue.

Returns:
obvious

Definition at line 95 of file vmessagequeue.cpp.

static void VMessageQueue::setQueueingLagLoggingThreshold ( const VDuration threshold) [inline, static]

The following methods set and get the configuration for emitting a log message if there is a lag between posting to a queue and the output thread getting a message.

A threshold of 0 means the output thread will log on every message. You can set the log leve at which the output will be emitted.

Definition at line 98 of file vmessagequeue.h.


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

Copyright ©1997-2014 Trygve Isaacson. All rights reserved. This documentation was generated with Doxygen.