Panda3D
|
00001 // Filename: datagramQueue.h 00002 // Created by: drose (07Feb00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef DATAGRAMQUEUE_H 00016 #define DATAGRAMQUEUE_H 00017 00018 #include "pandabase.h" 00019 00020 #include "netDatagram.h" 00021 #include "pmutex.h" 00022 #include "conditionVarFull.h" 00023 #include "pdeque.h" 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Class : DatagramQueue 00027 // Description : A thread-safe, FIFO queue of NetDatagrams. This is used 00028 // by ConnectionWriter for queuing up datagrams for 00029 // its various threads to write to sockets. 00030 //////////////////////////////////////////////////////////////////// 00031 class EXPCL_PANDA_NET DatagramQueue { 00032 public: 00033 DatagramQueue(); 00034 ~DatagramQueue(); 00035 void shutdown(); 00036 00037 bool insert(const NetDatagram &data, bool block = false); 00038 bool extract(NetDatagram &result); 00039 00040 void set_max_queue_size(int max_size); 00041 int get_max_queue_size() const; 00042 int get_current_queue_size() const; 00043 00044 private: 00045 Mutex _cvlock; 00046 ConditionVarFull _cv; // signaled when queue contents change. 00047 00048 typedef pdeque<NetDatagram> QueueType; 00049 QueueType _queue; 00050 bool _shutdown; 00051 int _max_queue_size; 00052 }; 00053 00054 #endif 00055