SUMO - Simulation of Urban MObility
AbstractMutex.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-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 /****************************************************************************/
18 // An abstract class for encapsulating mutex implementations
19 /****************************************************************************/
20 #ifndef AbstractMutex_h
21 #define AbstractMutex_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 
34 // ===========================================================================
35 // class definitions
36 // ===========================================================================
49 public:
52 
53 
55  virtual ~AbstractMutex() { }
56 
57 
59  virtual void lock() = 0;
60 
61 
63  virtual void unlock() = 0;
64 
65 
66 
70  class ScopedLocker {
71  public:
78  myLock.lock();
79  }
80 
81 
86  myLock.unlock();
87  }
88 
89  private:
92 
93  private:
95  ScopedLocker(const ScopedLocker&);
96 
99 
100 
101  };
102 
103 
104 
105 };
106 
107 
108 #endif
109 
110 /****************************************************************************/
111 
An abstract class for encapsulating mutex implementations.
Definition: AbstractMutex.h:48
AbstractMutex & myLock
The mutex to lock.
Definition: AbstractMutex.h:91
virtual ~AbstractMutex()
Destructor.
Definition: AbstractMutex.h:55
virtual void lock()=0
Locks the mutex.
ScopedLocker & operator=(const ScopedLocker &)
Invalidated assignment operator.
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:70
virtual void unlock()=0
Unlocks the mutex.
~ScopedLocker()
Destructor Unlocks the mutex.
Definition: AbstractMutex.h:85
AbstractMutex()
Constructor.
Definition: AbstractMutex.h:51
ScopedLocker(AbstractMutex &lock)
Constructor.
Definition: AbstractMutex.h:77