#include <datagramQueue.h>
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< NetDatagram > | QueueType |
Private Attributes | |
PRLock * | _cvlock |
PRCondVar * | _cv |
QueueType | _queue |
bool | _shutdown |
int | _max_queue_size |
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.
|
Definition at line 66 of file datagramQueue.h. |
|
Definition at line 33 of file datagramQueue.cxx. |
|
Definition at line 48 of file datagramQueue.cxx. |
|
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. |
|
Returns the current number of things in the queue.
Definition at line 236 of file datagramQueue.cxx. |
|
Returns the maximum size the queue is allowed to grow to. See set_max_queue_size(). Definition at line 223 of file datagramQueue.cxx. |
|
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(). |
|
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. |
|
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. |
|
Definition at line 59 of file datagramQueue.h. Referenced by insert(), and shutdown(). |
|
Definition at line 58 of file datagramQueue.h. Referenced by extract(), insert(), and shutdown(). |
|
Definition at line 71 of file datagramQueue.h. Referenced by extract(), and shutdown(). |
|
Definition at line 69 of file datagramQueue.h. Referenced by insert(), and shutdown(). |
|
Definition at line 70 of file datagramQueue.h. Referenced by insert(). |