SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MFXEventQue.h
Go to the documentation of this file.
1 /****************************************************************************/
7 // missing_desc
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2004-2015 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 #ifndef MFXEventQue_h
21 #define MFXEventQue_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <fx.h>
34 #include <list>
35 #include <cassert>
37 
38 template<class T>
39 class MFXEventQue {
40 public:
43 
44  T top() {
45  assert(size() != 0);
46  myMutex.lock();
47  T ret = myItems.front();
48  myMutex.unlock();
49  return ret;
50  }
51 
52 
53  void pop() {
54  myMutex.lock();
55  myItems.erase(myItems.begin());
56  myMutex.unlock();
57  }
58 
59  void add(T what) {
60  myMutex.lock();
61  myItems.push_back(what);
62  myMutex.unlock();
63  }
64 
65  size_t size() {
66  myMutex.lock();
67  const size_t ret = myItems.size();
68  myMutex.unlock();
69  return ret;
70  }
71 
72  bool empty() {
73  myMutex.lock();
74  const bool ret = myItems.size() == 0;
75  myMutex.unlock();
76  return ret;
77  }
78 
79 private:
81  std::list<T> myItems;
82 };
83 
84 
85 #endif
86 
87 /****************************************************************************/
88 
void pop()
Definition: MFXEventQue.h:53
bool empty()
Definition: MFXEventQue.h:72
void add(T what)
Definition: MFXEventQue.h:59
std::list< T > myItems
Definition: MFXEventQue.h:81
void unlock()
release mutex lock
Definition: MFXMutex.cpp:96
void lock()
lock mutex
Definition: MFXMutex.cpp:86
MFXMutex myMutex
Definition: MFXEventQue.h:80
size_t size()
Definition: MFXEventQue.h:65