This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 426
/
semaphore.d
151 lines (135 loc) · 2.79 KB
/
semaphore.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* D header file for POSIX.
*
* Copyright: Copyright Sean Kelly 2005 - 2009.
* License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
* Authors: Sean Kelly, Alex Rønne Petersen
* Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
*/
/* Copyright Sean Kelly 2005 - 2009.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
module core.sys.posix.semaphore;
private import core.sys.posix.config;
private import core.sys.posix.time;
version (Posix):
extern (C):
nothrow:
@nogc:
//
// Required
//
/*
sem_t
SEM_FAILED
int sem_close(sem_t*);
int sem_destroy(sem_t*);
int sem_getvalue(sem_t*, int*);
int sem_init(sem_t*, int, uint);
sem_t* sem_open(in char*, int, ...);
int sem_post(sem_t*);
int sem_trywait(sem_t*);
int sem_unlink(in char*);
int sem_wait(sem_t*);
*/
version( CRuntime_Glibc )
{
private alias int __atomic_lock_t;
private struct _pthread_fastlock
{
c_long __status;
__atomic_lock_t __spinlock;
}
struct sem_t
{
_pthread_fastlock __sem_lock;
int __sem_value;
void* __sem_waiting;
}
enum SEM_FAILED = cast(sem_t*) null;
}
else version( OSX )
{
alias int sem_t;
enum SEM_FAILED = cast(sem_t*) null;
}
else version( FreeBSD )
{
// FBSD-9.0 definition
struct sem_t
{
uint _magic;
struct _usem
{
shared uint _has_waiters;
shared uint _count;
uint _flags;
} _usem _kern;
}
enum SEM_FAILED = cast(sem_t*) null;
}
else version (Solaris)
{
struct sem_t
{
uint sem_count;
ushort sem_type;
ushort sem_magic;
ulong[3] sem_pad1;
ulong[2] sem_pad2;
}
enum SEM_FAILED = cast(sem_t*)-1;
}
else version( CRuntime_Bionic )
{
struct sem_t
{
uint count; //volatile
}
enum SEM_FAILED = null;
}
else
{
static assert(false, "Unsupported platform");
}
int sem_close(sem_t*);
int sem_destroy(sem_t*);
int sem_getvalue(sem_t*, int*);
int sem_init(sem_t*, int, uint);
sem_t* sem_open(in char*, int, ...);
int sem_post(sem_t*);
int sem_trywait(sem_t*);
int sem_unlink(in char*);
int sem_wait(sem_t*);
//
// Timeouts (TMO)
//
/*
int sem_timedwait(sem_t*, in timespec*);
*/
version( CRuntime_Glibc )
{
int sem_timedwait(sem_t*, in timespec*);
}
else version( OSX )
{
int sem_timedwait(sem_t*, in timespec*);
}
else version( FreeBSD )
{
int sem_timedwait(sem_t*, in timespec*);
}
else version (Solaris)
{
int sem_timedwait(sem_t*, in timespec*);
}
else version( CRuntime_Bionic )
{
int sem_timedwait(sem_t*, in timespec*);
}
else
{
static assert(false, "Unsupported platform");
}