SUMO - Simulation of Urban MObility
MFXEventQue.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2004-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // missing_desc
18 /****************************************************************************/
19 #ifndef MFXEventQue_h
20 #define MFXEventQue_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <fx.h>
33 #include <list>
34 #include <cassert>
36 
37 template<class T>
38 class MFXEventQue {
39 public:
42 
43  T top() {
44  assert(size() != 0);
45  myMutex.lock();
46  T ret = myItems.front();
47  myMutex.unlock();
48  return ret;
49  }
50 
51 
52  void pop() {
53  myMutex.lock();
54  myItems.erase(myItems.begin());
55  myMutex.unlock();
56  }
57 
58  void add(T what) {
59  myMutex.lock();
60  myItems.push_back(what);
61  myMutex.unlock();
62  }
63 
64  int size() {
65  myMutex.lock();
66  const int ret = (int)myItems.size();
67  myMutex.unlock();
68  return ret;
69  }
70 
71  bool empty() {
72  myMutex.lock();
73  const bool ret = myItems.size() == 0;
74  myMutex.unlock();
75  return ret;
76  }
77 
78 private:
80  std::list<T> myItems;
81 };
82 
83 
84 #endif
85 
86 /****************************************************************************/
87 
int size()
Definition: MFXEventQue.h:64
void pop()
Definition: MFXEventQue.h:52
bool empty()
Definition: MFXEventQue.h:71
void add(T what)
Definition: MFXEventQue.h:58
std::list< T > myItems
Definition: MFXEventQue.h:80
void unlock()
release mutex lock
Definition: MFXMutex.cpp:93
void lock()
lock mutex
Definition: MFXMutex.cpp:83
MFXMutex myMutex
Definition: MFXEventQue.h:79