CoreNEURON
nrnmutdec.hpp
Go to the documentation of this file.
1
/*
2
# =============================================================================
3
# Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
4
#
5
# See top-level LICENSE file for details.
6
# =============================================================================.
7
*/
8
#pragma once
9
10
#if defined(_OPENMP)
11
#include <omp.h>
12
13
// This class respects the requirement *Mutex*
14
class
OMP_Mutex
{
15
public
:
16
// Default constructible
17
OMP_Mutex
() {
18
omp_init_lock(&mut_);
19
}
20
21
// Destructible
22
~OMP_Mutex
() {
23
omp_destroy_lock(&mut_);
24
}
25
26
// Not copyable
27
OMP_Mutex
(
const
OMP_Mutex
&) =
delete
;
28
OMP_Mutex
&
operator=
(
const
OMP_Mutex
&) =
delete
;
29
30
// Not movable
31
OMP_Mutex
(
const
OMP_Mutex
&&) =
delete
;
32
OMP_Mutex
&
operator=
(
const
OMP_Mutex
&&) =
delete
;
33
34
// Basic Lockable
35
void
lock
() {
36
omp_set_lock(&mut_);
37
}
38
39
void
unlock
() {
40
omp_unset_lock(&mut_);
41
}
42
43
// Lockable
44
bool
try_lock
() {
45
return
omp_test_lock(&mut_) != 0;
46
}
47
48
private
:
49
omp_lock_t mut_;
50
};
51
52
#else
53
54
// This class respects the requirement *Mutex*
55
class
OMP_Mutex
{
56
public
:
57
// Default constructible
58
OMP_Mutex
() =
default
;
59
60
// Destructible
61
~OMP_Mutex
() =
default
;
62
63
// Not copyable
64
OMP_Mutex
(
const
OMP_Mutex
&) =
delete
;
65
OMP_Mutex
&
operator=
(
const
OMP_Mutex
&) =
delete
;
66
67
// Not movable
68
OMP_Mutex
(
const
OMP_Mutex
&&) =
delete
;
69
OMP_Mutex
&
operator=
(
const
OMP_Mutex
&&) =
delete
;
70
71
// Basic Lockable
72
void
lock
() {}
73
74
void
unlock
() {}
75
76
// Lockable
77
bool
try_lock
() {
78
return
true
;
79
}
80
};
81
#endif
OMP_Mutex
Definition:
nrnmutdec.hpp:55
OMP_Mutex::operator=
OMP_Mutex & operator=(const OMP_Mutex &)=delete
OMP_Mutex::unlock
void unlock()
Definition:
nrnmutdec.hpp:74
OMP_Mutex::OMP_Mutex
OMP_Mutex()=default
OMP_Mutex::~OMP_Mutex
~OMP_Mutex()=default
OMP_Mutex::lock
void lock()
Definition:
nrnmutdec.hpp:72
OMP_Mutex::try_lock
bool try_lock()
Definition:
nrnmutdec.hpp:77
coreneuron
utils
nrnmutdec.hpp