Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

DatagramQueue Class Reference

A thread-safe, FIFO queue of NetDatagrams. More...

#include <datagramQueue.h>

List of all members.

Public Member Functions

 DatagramQueue ()
 ~DatagramQueue ()
void shutdown ()
 Marks the queue as shutting down, which will eventually cause all threads blocking on extract() to return false.

bool insert (const NetDatagram &data)
 Inserts the indicated datagram onto the end of the queue, and returns.

bool extract (NetDatagram &result)
 Extracts a datagram from the head of the queue, if one is available.

void set_max_queue_size (int max_size)
 Sets the maximum size the queue is allowed to grow to.

int get_max_queue_size () const
 Returns the maximum size the queue is allowed to grow to.

int get_current_queue_size () const
 Returns the current number of things in the queue.


Private Types

typedef pdeque< NetDatagramQueueType

Private Attributes

PRLock * _cvlock
PRCondVar * _cv
QueueType _queue
bool _shutdown
int _max_queue_size


Detailed Description

A thread-safe, FIFO queue of NetDatagrams.

This is used by ConnectionWriter for queuing up datagrams for its various threads to write to sockets.

Definition at line 44 of file datagramQueue.h.


Member Typedef Documentation

typedef pdeque<NetDatagram> DatagramQueue::QueueType [private]
 

Definition at line 66 of file datagramQueue.h.


Constructor & Destructor Documentation

DatagramQueue::DatagramQueue  ) 
 

Definition at line 33 of file datagramQueue.cxx.

DatagramQueue::~DatagramQueue  ) 
 

Definition at line 48 of file datagramQueue.cxx.


Member Function Documentation

bool DatagramQueue::extract NetDatagram result  ) 
 

Extracts a datagram from the head of the queue, if one is available.

If a datagram is available, this will immediately return; otherwise, it will block until a datagram becomes available. Multiple threads may simultaneously block on extract(); when a datagram is subsequently inserted into the queue, one of the threads will return from extract() with the datagram.

The return value is true if the datagram is successfully extracted, or false if the queue was destroyed while waiting. (In the case of a false return, the thread should not attempt to operate on the queue again.)

Definition at line 154 of file datagramQueue.cxx.

References _cvlock, and _max_queue_size.

int DatagramQueue::get_current_queue_size  )  const
 

Returns the current number of things in the queue.

Definition at line 236 of file datagramQueue.cxx.

int DatagramQueue::get_max_queue_size  )  const
 

Returns the maximum size the queue is allowed to grow to.

See set_max_queue_size().

Definition at line 223 of file datagramQueue.cxx.

bool DatagramQueue::insert const NetDatagram data  ) 
 

Inserts the indicated datagram onto the end of the queue, and returns.

If the queue is empty and any threads are waiting on the queue, this will wake one of them up. Returns true if successful, false if the queue was full.

Definition at line 103 of file datagramQueue.cxx.

References _cv, _cvlock, _queue, _shutdown, NetDatagram::clear(), and nassertr.

Referenced by ConnectionWriter::send().

void DatagramQueue::set_max_queue_size int  max_size  ) 
 

Sets the maximum size the queue is allowed to grow to.

This is primarily for a sanity check; this is a limit beyond which we can assume something bad has happened.

It's also a crude check against unfortunate seg faults due to the queue filling up and quietly consuming all available memory.

Definition at line 206 of file datagramQueue.cxx.

void DatagramQueue::shutdown  ) 
 

Marks the queue as shutting down, which will eventually cause all threads blocking on extract() to return false.

The normal way to delete a DatagramQueue will be to call first shutdown() and then wait for all known threads to terminate. Then it is safe to delete the queue.

Definition at line 76 of file datagramQueue.cxx.

References _cv, _cvlock, _max_queue_size, and _queue.


Member Data Documentation

PRCondVar* DatagramQueue::_cv [private]
 

Definition at line 59 of file datagramQueue.h.

Referenced by insert(), and shutdown().

PRLock* DatagramQueue::_cvlock [private]
 

Definition at line 58 of file datagramQueue.h.

Referenced by extract(), insert(), and shutdown().

int DatagramQueue::_max_queue_size [private]
 

Definition at line 71 of file datagramQueue.h.

Referenced by extract(), and shutdown().

QueueType DatagramQueue::_queue [private]
 

Definition at line 69 of file datagramQueue.h.

Referenced by insert(), and shutdown().

bool DatagramQueue::_shutdown [private]
 

Definition at line 70 of file datagramQueue.h.

Referenced by insert().


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:49:11 2003 for Panda by doxygen1.3