00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _OASYS_MSG_QUEUE_H_
00019 #define _OASYS_MSG_QUEUE_H_
00020
00021 #include <queue>
00022 #include <unistd.h>
00023 #include <errno.h>
00024 #include <sys/poll.h>
00025
00026 #include "Notifier.h"
00027 #include "SpinLock.h"
00028 #include "../debug/Log.h"
00029 #include "../debug/DebugUtils.h"
00030
00031 namespace oasys {
00032
00038 template<typename _elt_t>
00039 class MsgQueue : public Notifier {
00040 public:
00044 MsgQueue(const char* logpath, SpinLock* lock = NULL);
00045
00049 ~MsgQueue();
00050
00055 void push(_elt_t msg, bool at_back = true);
00056
00061 void push_front(_elt_t msg)
00062 {
00063 push(msg, false);
00064 }
00065
00070 void push_back(_elt_t msg)
00071 {
00072 push(msg, true);
00073 }
00074
00078 _elt_t pop_blocking();
00079
00084 bool try_pop(_elt_t* eltp);
00085
00089 size_t size()
00090 {
00091 ScopeLock l(lock_, "MsgQueue::size");
00092 return queue_.size();
00093 }
00094
00107 void notify_when_empty();
00108
00109 protected:
00110 SpinLock* lock_;
00111 std::deque<_elt_t> queue_;
00112 bool notify_when_empty_;
00113 };
00114
00115 #include "MsgQueue.tcc"
00116
00117 }
00118
00119 #endif //_OASYS_MSG_QUEUE_H_