clang-tidy: add most bugprone warnings
[lttng-tools.git] / src / common / urcu.hpp
CommitLineData
0a325f4d
JG
1/*
2 * Copyright (C) 2022 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8#ifndef LTTNG_URCU_H
9#define LTTNG_URCU_H
10
11#define _LGPL_SOURCE
12#include <urcu.h>
13#include <mutex>
14
15namespace lttng {
16namespace urcu {
17
18namespace details {
19/*
20 * Wrapper around an urcu read lock which satisfies the 'Mutex' named
21 * requirements of C++11. Satisfying those requirements facilitates the use of
22 * standard concurrency support library facilities.
23 *
24 * read_lock is under the details namespace since it is unlikely to be used
25 * directly by exception-safe code. See read_lock_guard.
26 */
27class read_lock {
28public:
29 read_lock() = default;
30
31 /* "Not copyable" and "not moveable" Mutex requirements. */
32 read_lock(read_lock const &) = delete;
33 read_lock &operator=(read_lock const &) = delete;
34
35 void lock()
36 {
37 rcu_read_lock();
38 }
39
40 bool try_lock()
41 {
42 lock();
43 return true;
44 }
45
46 void unlock()
47 {
48 rcu_read_unlock();
49 }
50};
51} /* namespace details */
52
53/*
54 * Provides the basic concept of std::lock_guard for rcu reader locks.
55 *
56 * The RCU reader lock is held for the duration of lock_guard's lifetime.
57 */
58class read_lock_guard {
59public:
5c7248cd 60 read_lock_guard() = default;
0a325f4d
JG
61
62 read_lock_guard(const read_lock_guard &) = delete;
63
64private:
65 details::read_lock _lock;
5c7248cd 66 std::lock_guard<details::read_lock> _guard{_lock};
0a325f4d
JG
67};
68
d7bfb9b0
JG
69using unique_read_lock = std::unique_lock<details::read_lock>;
70
0a325f4d
JG
71} /* namespace urcu */
72} /* namespace lttng */
73
74#endif /* LTTNG_URCU_H */
This page took 0.028182 seconds and 4 git commands to generate.