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  * Authored by: William Wold <william.wold@canonical.com>
17  */
18 #ifndef MIR_PROOF_OF_MUTEX_LOCK_H_
19 #define MIR_PROOF_OF_MUTEX_LOCK_H_
20 
21 #include "fatal.h"
22 #include <mutex>
23 
24 namespace mir
25 {
29 {
30 public:
31  ProofOfMutexLock(std::lock_guard<std::mutex> const&) {}
32  ProofOfMutexLock(std::unique_lock<std::mutex> const& lock)
33  {
34  if (!lock.owns_lock())
35  {
36  fatal_error("ProofOfMutexLock created with unlocked unique_lock");
37  }
38  }
41 };
42 } // namespace mir
43 
44 #endif // MIR_PROOF_OF_MUTEX_LOCK_H_
A method can take an instance of this class by reference to require callers to hold a mutex lock,...
Definition: proof_of_mutex_lock.h:29
ProofOfMutexLock operator=(ProofOfMutexLock const &)=delete
ProofOfMutexLock(std::lock_guard< std::mutex > const &)
Definition: proof_of_mutex_lock.h:31
ProofOfMutexLock(std::unique_lock< std::mutex > const &lock)
Definition: proof_of_mutex_lock.h:32
ProofOfMutexLock(ProofOfMutexLock const &)=delete
Definition: splash_session.h:24
void(* fatal_error)(char const *reason,...)
fatal_error() is strictly for "this should never happen" situations that you cannot recover from.

Copyright © 2012-2022 Canonical Ltd.
Generated on Thu Feb 24 23:57:55 UTC 2022
This documentation is licensed under the GPL version 2 or 3.