header_utils
Loading...
Searching...
No Matches
threading.h
1
4
5
#pragma once
6
7
#include <mutex>
8
9
namespace
ghassanpl
10
{
11
template
<
typename
T>
12
concept
mutex_type =
requires
(T
t
)
13
{
14
{
t
.lock() };
15
{
t
.try_lock() } -> std::convertible_to<bool>;
16
{
t
.unlock() };
17
};
18
19
template
<mutex_type
MUTEX_TYPE
,
typename
FUNC
,
typename
...
ARGS
>
20
auto
under_protection(
MUTEX_TYPE
&
m
,
FUNC
&&
func
,
ARGS
&&...
args
)
21
{
22
std::lock_guard
guard
{
m
};
23
if
constexpr
(std::invocable<
FUNC
,
MUTEX_TYPE
&,
ARGS
...>)
24
return
func
(
m
, std::forward<ARGS>(
args
)...);
25
else
26
return
func
(std::forward<ARGS>(
args
)...);
27
}
28
29
template
<mutex_type MUTEX_TYPE,
typename
T>
30
auto
protected_copy(
MUTEX_TYPE
&
m
, T&&
t
)
31
{
32
std::lock_guard
guard
{
m
};
33
return
std::forward<T>(
t
);
34
}
35
36
}
ghassanpl::bit_count
constexpr auto bit_count
Equal to the number of bits in the type.
Definition
bits.h:33
ghassanpl
Primary namespace for everything in this library.
Definition
align+rec2.h:10
include
ghassanpl
threading.h
Generated by
1.9.8