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 /****************************************************************************/
14 // A scoped lock which only triggers on condition
15 /****************************************************************************/
16 
17 #ifndef FXConditionalLock_h
18 #define FXConditionalLock_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <fx.h>
27 
28 
29 // ===========================================================================
30 // class definitions
31 // ===========================================================================
37 public:
39  FXConditionalLock(FXMutex& m, const bool condition)
40  : myMutex(m), myCondition(condition) {
41  if (condition) {
42  m.lock();
43  }
44  }
45 
48  if (myCondition) {
49  myMutex.unlock();
50  }
51  }
52 
53 private:
54  FXMutex& myMutex;
55  const bool myCondition;
56 
57 private:
59 };
60 
61 
62 #endif
FXConditionalLock::~FXConditionalLock
~FXConditionalLock()
Destroy and unlock associated mutex.
Definition: FXConditionalLock.h:47
FXConditionalLock::FXConditionalLock
FXConditionalLock(FXMutex &m, const bool condition)
Construct & lock associated mutex if the condition is true.
Definition: FXConditionalLock.h:39
FXConditionalLock
A scoped lock which only triggers on condition.
Definition: FXConditionalLock.h:36
FXConditionalLock::myMutex
FXMutex & myMutex
Definition: FXConditionalLock.h:54
config.h
FXConditionalLock::myCondition
const bool myCondition
Definition: FXConditionalLock.h:55
FXConditionalLock::operator=
FXConditionalLock & operator=(const FXConditionalLock &)=delete