Eclipse SUMO - Simulation of Urban MObility
FXConditionalLock.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2018-2019 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 // A scoped lock which only triggers on condition
16 /****************************************************************************/
17 
18 #ifndef FXConditionalLock_h
19 #define FXConditionalLock_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <fx.h>
28 
29 
30 // ===========================================================================
31 // class definitions
32 // ===========================================================================
38 public:
40  FXConditionalLock(FXMutex& m, const bool condition)
41  : myMutex(m), myCondition(condition) {
42  if (condition) {
43  m.lock();
44  }
45  }
46 
49  if (myCondition) {
50  myMutex.unlock();
51  }
52  }
53 
54 private:
55  FXMutex& myMutex;
56  const bool myCondition;
57 
58 private:
60 };
61 
62 
63 #endif
FXConditionalLock(FXMutex &m, const bool condition)
Construct & lock associated mutex if the condition is true.
A scoped lock which only triggers on condition.
FXConditionalLock & operator=(const FXConditionalLock &)=delete
~FXConditionalLock()
Destroy and unlock associated mutex.