MsgQueue.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
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 } // namespace oasys
00118 
00119 #endif //_OASYS_MSG_QUEUE_H_

Generated on Thu Jun 7 16:56:50 2007 for DTN Reference Implementation by  doxygen 1.5.1