Mir
proof_of_mutex_lock.h
Go to the documentation of this file.
1/*
2 * Copyright © 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
22namespace 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{
28public:
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_
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:27
ProofOfMutexLock operator=(ProofOfMutexLock const &)=delete
ProofOfMutexLock(std::lock_guard< std::mutex > const &)
Definition: proof_of_mutex_lock.h:29
ProofOfMutexLock(std::unique_lock< std::mutex > const &lock)
Definition: proof_of_mutex_lock.h:30
ProofOfMutexLock(ProofOfMutexLock const &)=delete
Definition: runner.h:27
void(* fatal_error)(char const *reason,...)
fatal_error() is strictly for "this should never happen" situations that you cannot recover from.

Copyright © 2012-2023 Canonical Ltd.
Generated on Tue 2 May 10:01:24 UTC 2023
This documentation is licensed under the GPL version 2 or 3.