Dv::Thread::MailBox< M > Class Template Reference

A mailbox that supports thread-safe addition and retrieval of messages. More...

#include <mailbox.h>

Inheritance diagram for Dv::Thread::MailBox< M >:
Inheritance graph
[legend]
Collaboration diagram for Dv::Thread::MailBox< M >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 MailBox (const std::string &name, size_t max_capacity=0, unsigned int min_debug_level=0, Debugable *debug_master=0)
 Constructor.
void put (const M &m)
 Put a message in the mailbox.
const size_t max_capacity () const
get (size_t millisec_to_wait=2000)
 Get a message from a mailbox.
size_t size () const

Private Types

enum  { MAILBOX_NONEMPTY = 0 }

Private Attributes

size_t max_capacity_
std::deque< M > messages_

Detailed Description

template<typename M>
class Dv::Thread::MailBox< M >

A mailbox that supports thread-safe addition and retrieval of messages.


Member Enumeration Documentation

template<typename M>
anonymous enum [private]
Enumerator:
MAILBOX_NONEMPTY 

Constructor & Destructor Documentation

template<typename M>
Dv::Thread::MailBox< M >::MailBox ( const std::string &  name,
size_t  max_capacity = 0,
unsigned int  min_debug_level = 0,
Debugable debug_master = 0 
) [inline]

Constructor.

Parameters:
name of mailbox, used for tracing.
max_capacity an attempt to put more than max_capacity messages will cause MailBox::put to throw an exception. If 0, capacity is unlimited.

Member Function Documentation

template<typename M>
void Dv::Thread::MailBox< M >::put ( const M &  m  )  [inline]

Put a message in the mailbox.

Parameters:
m message to store in the mailbox. Note that a copy of the message will be made. Use Dv::shared_ptr if you want to put a pointer.
Exceptions:
std::runtime_error if max_capacity is reached
See also:
Dv::shared_ptr

Referenced by Dv::Thread::ActorPool< HandlerFactory >::request(), and Dv::Thread::Actor< Handler >::request().

template<typename M>
const size_t Dv::Thread::MailBox< M >::max_capacity (  )  const [inline]
Returns:
max capacity of this mailbox
template<typename M>
M Dv::Thread::MailBox< M >::get ( size_t  millisec_to_wait = 2000  )  [inline]

Get a message from a mailbox.

This function will block until a message is available.

Parameters:
millisec_to_wait time to wait for message if none are available; if the time has passed and no messages are available, a std::runtime_error is thrown.
Exceptions:
std::runtime_error if no messages are available after waiting millisec_to_wait millisecs

Referenced by Dv::Thread::Actor< Handler >::main().

template<typename M>
size_t Dv::Thread::MailBox< M >::size (  )  const [inline]
Returns:
number of pending messages.

Member Data Documentation

template<typename M>
size_t Dv::Thread::MailBox< M >::max_capacity_ [private]
template<typename M>
std::deque<M> Dv::Thread::MailBox< M >::messages_ [private]

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

dvthread-0.13.4 [11 December, 2009]