libjmmcg
release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
thread_api_traits.hpp
Go to the documentation of this file.
1
/******************************************************************************
2
** Copyright © 2004 by J.M.McGuiness, coder@hussar.me.uk
3
**
4
** This library is free software; you can redistribute it and/or
5
** modify it under the terms of the GNU Lesser General Public
6
7
** License as published by the Free Software Foundation; either
8
** version 2.1 of the License, or (at your option) any later version.
9
**
10
** This library is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
** Lesser General Public License for more details.
14
**
15
** You should have received a copy of the GNU Lesser General Public
16
** License along with this library; if not, write to the Free Software
17
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*/
19
20
#
include
"../core/exception.hpp"
21
#
include
"../core/atomic_counter.hpp"
22
23
#
include
<
atomic
>
24
#
include
<
csignal
>
25
26
#
include
<
errno
.
h
>
27
#
include
<
pthread
.
h
>
28
29
#
if
_POSIX_C_SOURCE
<
200112L
30
#
error
"POSIX semaphores, sem_*()s, required for this library. Also link with -lrt or -pthread to include the sem_*()s."
31
#
endif
32
33
#
include
<
semaphore
.
h
>
34
35
namespace
jmmcg
{
namespace
LIBJMMCG_VER_NAMESPACE
{
namespace
ppd
{
36
37
namespace
pthreads
{
38
class
anon_mutex
;
39
class
nonrecursive_anon_mutex;
40
class
recursive_anon_mutex;
41
class
anon_semaphore
;
42
class
critical_section;
43
class
mutex;
44
class
recursive_mutex;
45
class
event;
46
class
anon_semaphore
;
47
class
semaphore
;
48
}
49
50
/// The various lock-types for POSIX-threads derived, platforms.
51
template
<>
52
struct
api_lock_traits
<
generic_traits
::
api_type
::
posix_pthreads
,
heavyweight_threading
> {
53
static
constexpr
generic_traits
::
api_type
api_type
=
generic_traits
::
api_type
::
posix_pthreads
;
54
typedef
heavyweight_threading
model_type
;
55
enum
atomic_state_type
{
56
atom_set
=0,
57
atom_abandoned
=EINVAL,
58
atom_already_set
=EBUSY,
59
atom_max_recurse
=EAGAIN,
60
atom_deadlocked
=EDEADLK,
61
atom_perm_error
=EPERM,
62
atom_failed
=ESRCH,
63
atom_interrupted
=EINTR,
64
atom_nomemory
=ENOMEM,
65
atom_unset
=ETIMEDOUT,
66
atom_sem_overflow
=EOVERFLOW,
67
atom_errno
=-1
68
};
69
70
typedef
ppd
::
pthreads
::
anon_mutex
anon_mutex_type
;
71
typedef
ppd
::
pthreads
::
nonrecursive_anon_mutex
nonrecursive_anon_mutex_type
;
72
typedef
ppd
::
pthreads
::
recursive_anon_mutex
recursive_anon_mutex_type
;
73
typedef
ppd
::
pthreads
::
anon_semaphore
anon_event_type
;
74
using
anon_spin_event_type
=
ppd
::
lock
::
anon_spin_event
<
api_lock_traits
>;
75
typedef
ppd
::
pthreads
::
anon_mutex
critical_section_type
;
76
typedef
ppd
::
pthreads
::
mutex
mutex_type
;
77
typedef
ppd
::
pthreads
::
recursive_mutex
recursive_mutex_type
;
78
typedef
ppd
::
pthreads
::
recursive_mutex
recursive_critical_section_type
;
79
typedef
ppd
::
pthreads
::
semaphore
event_type
;
80
typedef
ppd
::
pthreads
::
anon_semaphore
anon_semaphore_type
;
81
typedef
ppd
::
pthreads
::
semaphore
semaphore_type
;
82
template
<
class
V
>
83
using
atomic_counter_type
=
atomic_ctr
<
V
,
api_lock_traits
<
api_type
,
model_type
>>;
84
template
<
class
V
>
85
using
noop_atomic_ctr
=
noop_atomic_ctr_base
<
V
,
api_lock_traits
<
api_type
,
model_type
>>;
86
template
<
class
V
>
87
using
atomic
=
atomic_ctr
<
V
,
api_lock_traits
<
api_type
,
model_type
>>;
88
using
api_mutex_type
=
pthread_mutex_t
;
89
using
api_event_type
=
sem_t
;
90
using
timeout_type
=
unsigned
long
;
91
template
<
class
...
T
>
92
using
scoped_lock
=
std
::
scoped_lock
<
T
...>;
93
94
using
exception_type
=
crt_exception
<
generic_traits
::
api_type
::
posix_pthreads
,
heavyweight_threading
>;
95
96
static
constexpr
timeout_type
__fastcall
infinite_timeout
()
noexcept
(
true
)
FORCE_INLINE
{
97
return
~
static_cast
<
timeout_type
>(0);
98
}
99
100
api_lock_traits
()=
delete
;
101
};
102
103
template
<>
104
struct
api_threading_traits
<
generic_traits
::
api_type
::
no_api
,
sequential_mode
> :
api_threading_traits
<
generic_traits
::
api_type
::
posix_pthreads
,
sequential_mode
> {};
105
106
} } }
107
108
#
include
"thread_api_traits_impl.hpp"
unix
thread_api_traits.hpp
Generated on Tue May 11 2021 17:31:27 for libjmmcg by
1.9.2