cppfig 0.1.0
Modern C++20 compile-time type-safe configuration library
Loading...
Searching...
No Matches
thread_policy.h
Go to the documentation of this file.
1#pragma once
2
3#include <mutex>
4#include <shared_mutex>
5
6namespace cppfig {
7
20 struct mutex_type { // NOLINT(readability-identifier-naming)
21 void lock() { } // NOLINT(readability-identifier-naming) LCOV_EXCL_LINE
22 void unlock() { } // NOLINT(readability-identifier-naming) LCOV_EXCL_LINE
23 void lock_shared() { } // NOLINT(readability-identifier-naming) LCOV_EXCL_LINE
24 void unlock_shared() { } // NOLINT(readability-identifier-naming) LCOV_EXCL_LINE
25 };
26
28 struct shared_lock { // NOLINT(readability-identifier-naming)
29 explicit shared_lock(mutex_type& /*unused*/) { }
30 ~shared_lock() = default;
31
32 shared_lock(const shared_lock&) = delete;
33 auto operator=(const shared_lock&) -> shared_lock& = delete;
35 auto operator=(shared_lock&&) -> shared_lock& = delete;
36 };
37
39 struct unique_lock { // NOLINT(readability-identifier-naming)
40 explicit unique_lock(mutex_type& /*unused*/) { }
41 ~unique_lock() = default;
42
43 unique_lock(const unique_lock&) = delete;
44 auto operator=(const unique_lock&) -> unique_lock& = delete;
46 auto operator=(unique_lock&&) -> unique_lock& = delete;
47 };
48};
49
63 using mutex_type = std::shared_mutex;
64
66 using shared_lock = std::shared_lock<std::shared_mutex>;
67
69 using unique_lock = std::unique_lock<std::shared_mutex>;
70};
71
72} // namespace cppfig
C++20 compile-time type-safe configuration library.
Definition conf.h:13
Thread policy for multi-threaded usage.
Definition thread_policy.h:61
std::shared_mutex mutex_type
Standard shared mutex for reader-writer locking.
Definition thread_policy.h:63
std::shared_lock< std::shared_mutex > shared_lock
Shared (reader) lock — multiple threads may hold simultaneously.
Definition thread_policy.h:66
std::unique_lock< std::shared_mutex > unique_lock
Unique (writer) lock — exclusive access.
Definition thread_policy.h:69
No-op mutex type (lower_case to satisfy C++ BasicLockable/SharedLockable).
Definition thread_policy.h:20
void unlock()
Definition thread_policy.h:22
void lock_shared()
Definition thread_policy.h:23
void lock()
Definition thread_policy.h:21
void unlock_shared()
Definition thread_policy.h:24
No-op shared (reader) lock (mirrors std::shared_lock).
Definition thread_policy.h:28
shared_lock(mutex_type &)
Definition thread_policy.h:29
auto operator=(const shared_lock &) -> shared_lock &=delete
shared_lock(const shared_lock &)=delete
auto operator=(shared_lock &&) -> shared_lock &=delete
No-op unique (writer) lock (mirrors std::unique_lock).
Definition thread_policy.h:39
unique_lock(mutex_type &)
Definition thread_policy.h:40
auto operator=(const unique_lock &) -> unique_lock &=delete
unique_lock(const unique_lock &)=delete
auto operator=(unique_lock &&) -> unique_lock &=delete
Thread policy for single-threaded usage (zero overhead).
Definition thread_policy.h:18