Mir
proof_of_mutex_lock.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2021 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 2 or 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 #ifndef MIR_PROOF_OF_MUTEX_LOCK_H_
17 #define MIR_PROOF_OF_MUTEX_LOCK_H_
18 
19 #include "fatal.h"
20 #include <mutex>
21 
22 namespace mir
23 {
24 /// A method can take an instance of this class by reference to require callers to hold a mutex lock, without requiring
25 /// a specific type of lock
27 {
28 public:
29  ProofOfMutexLock(std::lock_guard<std::mutex> const&) {}
30  ProofOfMutexLock(std::unique_lock<std::mutex> const& lock)
31  {
32  if (!lock.owns_lock())
33  {
34  fatal_error("ProofOfMutexLock created with unlocked unique_lock");
35  }
36  }
39 };
40 } // namespace mir
41 
42 #endif // MIR_PROOF_OF_MUTEX_LOCK_H_

Copyright © 2012-2022 Canonical Ltd.
Generated on Thu Sep 8 12:37:23 UTC 2022
This documentation is licensed under the GPL version 2 or 3.