]> git.ipfire.org Git - people/ms/gcc.git/blame - libphobos/libdruntime/core/sys/posix/semaphore.d
d: Merge upstream dmd, druntime 4ca4140e58, phobos 454dff14d.
[people/ms/gcc.git] / libphobos / libdruntime / core / sys / posix / semaphore.d
CommitLineData
b4c522fa
IB
1/**
2 * D header file for POSIX.
3 *
4 * Copyright: Copyright Sean Kelly 2005 - 2009.
5 * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6 * Authors: Sean Kelly, Alex Rønne Petersen
7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8 */
9
10/* Copyright Sean Kelly 2005 - 2009.
11 * Distributed under the Boost Software License, Version 1.0.
12 * (See accompanying file LICENSE or copy at
13 * http://www.boost.org/LICENSE_1_0.txt)
14 */
15module core.sys.posix.semaphore;
16
92dd3e71
IB
17import core.sys.posix.config;
18import core.sys.posix.time;
b4c522fa
IB
19
20version (OSX)
21 version = Darwin;
22else version (iOS)
23 version = Darwin;
24else version (TVOS)
25 version = Darwin;
26else version (WatchOS)
27 version = Darwin;
28
29version (Posix):
30extern (C):
31nothrow:
32@nogc:
33
34//
35// Required
36//
37/*
38sem_t
39SEM_FAILED
40
41int sem_close(sem_t*);
42int sem_destroy(sem_t*);
43int sem_getvalue(sem_t*, int*);
44int sem_init(sem_t*, int, uint);
92dd3e71 45sem_t* sem_open(const scope char*, int, ...);
b4c522fa
IB
46int sem_post(sem_t*);
47int sem_trywait(sem_t*);
92dd3e71 48int sem_unlink(const scope char*);
b4c522fa
IB
49int sem_wait(sem_t*);
50*/
51
52version (CRuntime_Glibc)
53{
54 private alias int __atomic_lock_t;
55
56 private struct _pthread_fastlock
57 {
58 c_long __status;
59 __atomic_lock_t __spinlock;
60 }
61
62 struct sem_t
63 {
64 _pthread_fastlock __sem_lock;
65 int __sem_value;
66 void* __sem_waiting;
67 }
68
69 enum SEM_FAILED = cast(sem_t*) null;
70}
71else version (Darwin)
72{
73 alias int sem_t;
74
75 enum SEM_FAILED = cast(sem_t*) null;
76}
77else version (FreeBSD)
78{
79 // FBSD-9.0 definition
80 struct sem_t
81 {
82 uint _magic;
83 struct _usem
84 {
85 shared uint _has_waiters;
86 shared uint _count;
87 uint _flags;
88 } _usem _kern;
89 }
90
91 enum SEM_FAILED = cast(sem_t*) null;
92}
93else version (NetBSD)
94{
95 alias size_t sem_t;
96
97 enum SEM_FAILED = cast(sem_t*) null;
98}
99else version (OpenBSD)
100{
5fee5ec3 101 struct __sem;
b4c522fa
IB
102 alias sem_t = __sem*;
103
104 enum SEM_FAILED = cast(sem_t*) null;
105}
106else version (DragonFlyBSD)
107{
108 struct sem_t
109 {
110 uint _magic;
111 struct _usem
112 {
113 shared uint _has_waiters;
114 shared uint _count;
115 uint _flags;
116 } _usem _kern;
117 }
118
119 enum SEM_FAILED = cast(sem_t*) null;
120}
121else version (Solaris)
122{
123 struct sem_t
124 {
125 uint sem_count;
126 ushort sem_type;
127 ushort sem_magic;
128 ulong[3] sem_pad1;
129 ulong[2] sem_pad2;
130 }
131
132 enum SEM_FAILED = cast(sem_t*)-1;
133}
134else version (CRuntime_Bionic)
135{
136 struct sem_t
137 {
138 uint count; //volatile
139 }
140
141 enum SEM_FAILED = null;
142}
143else version (CRuntime_Musl)
144{
145 struct sem_t {
6e5084b4 146 int[4*c_long.sizeof/int.sizeof] __val;
b4c522fa 147 }
6e5084b4
IB
148
149 enum SEM_FAILED = (sem_t*).init;
b4c522fa
IB
150}
151else version (CRuntime_UClibc)
152{
153 enum __SIZEOF_SEM_T = 16;
154
155 union sem_t
156 {
157 byte[__SIZEOF_SEM_T] __size;
158 c_long __align;
159 }
160
161 enum SEM_FAILED = cast(sem_t*) null;
162}
163else
164{
165 static assert(false, "Unsupported platform");
166}
167
168int sem_close(sem_t*);
169int sem_destroy(sem_t*);
170int sem_getvalue(sem_t*, int*);
171int sem_init(sem_t*, int, uint);
92dd3e71 172sem_t* sem_open(const scope char*, int, ...);
b4c522fa
IB
173int sem_post(sem_t*);
174int sem_trywait(sem_t*);
92dd3e71 175int sem_unlink(const scope char*);
b4c522fa
IB
176int sem_wait(sem_t*);
177
178//
179// Timeouts (TMO)
180//
181/*
92dd3e71 182int sem_timedwait(sem_t*, const scope timespec*);
b4c522fa
IB
183*/
184
185version (CRuntime_Glibc)
186{
92dd3e71 187 int sem_timedwait(sem_t*, const scope timespec*);
b4c522fa
IB
188}
189else version (Darwin)
190{
92dd3e71 191 int sem_timedwait(sem_t*, const scope timespec*);
b4c522fa
IB
192}
193else version (FreeBSD)
194{
92dd3e71 195 int sem_timedwait(sem_t*, const scope timespec*);
b4c522fa
IB
196}
197else version (NetBSD)
198{
92dd3e71 199 int sem_timedwait(sem_t*, const scope timespec*);
b4c522fa
IB
200}
201else version (OpenBSD)
202{
92dd3e71 203 int sem_timedwait(sem_t*, const scope timespec*);
b4c522fa
IB
204}
205else version (DragonFlyBSD)
206{
92dd3e71 207 int sem_timedwait(sem_t*, const scope timespec*);
b4c522fa
IB
208}
209else version (Solaris)
210{
92dd3e71 211 int sem_timedwait(sem_t*, const scope timespec*);
b4c522fa
IB
212}
213else version (CRuntime_Bionic)
214{
92dd3e71 215 int sem_timedwait(sem_t*, const scope timespec*);
b4c522fa
IB
216}
217else version (CRuntime_Musl)
218{
8da8c7d3 219 pragma(mangle, muslRedirTime64Mangle!("sem_timedwait", "__sem_timedwait_time64"))
92dd3e71 220 int sem_timedwait(sem_t*, const scope timespec*);
b4c522fa
IB
221}
222else version (CRuntime_UClibc)
223{
92dd3e71 224 int sem_timedwait(sem_t*, const scope timespec*);
b4c522fa
IB
225}
226else
227{
228 static assert(false, "Unsupported platform");
229}