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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // missing_desc
16 /****************************************************************************/
17 #ifndef MFXEventQue_h
18 #define MFXEventQue_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <fx.h>
27 #include <list>
28 #include <cassert>
30 
31 template<class T>
32 class MFXEventQue {
33 public:
36 
37  T top() {
38  assert(size() != 0);
39  myMutex.lock();
40  T ret = myItems.front();
41  myMutex.unlock();
42  return ret;
43  }
44 
45 
46  void pop() {
47  myMutex.lock();
48  myItems.erase(myItems.begin());
49  myMutex.unlock();
50  }
51 
52  void add(T what) {
53  myMutex.lock();
54  myItems.push_back(what);
55  myMutex.unlock();
56  }
57 
58  int size() {
59  myMutex.lock();
60  const int ret = (int)myItems.size();
61  myMutex.unlock();
62  return ret;
63  }
64 
65  bool empty() {
66  myMutex.lock();
67  const bool ret = myItems.size() == 0;
68  myMutex.unlock();
69  return ret;
70  }
71 
72 private:
74  std::list<T> myItems;
75 };
76 
77 
78 #endif
79 
80 /****************************************************************************/
81 
int size()
Definition: MFXEventQue.h:58
void pop()
Definition: MFXEventQue.h:46
bool empty()
Definition: MFXEventQue.h:65
void add(T what)
Definition: MFXEventQue.h:52
std::list< T > myItems
Definition: MFXEventQue.h:74
void unlock()
release mutex lock
Definition: MFXMutex.cpp:87
void lock()
lock mutex
Definition: MFXMutex.cpp:77
MFXMutex myMutex
Definition: MFXEventQue.h:73