Remove unneeded setting of errno after malloc failure
[glibc.git] / hurd / hurdlock.h
blob4a8f416a1a827c1e077bb9317f0a9a82d6664116
1 /* Low-level lock implementation. High-level Hurd helpers.
2 Copyright (C) 1999-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C 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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef _HURD_LOCK_H
20 #define _HURD_LOCK_H 1
22 #include <mach/lowlevellock.h>
24 struct timespec;
26 /* Flags for robust locks. */
27 #define LLL_WAITERS (1U << 31)
28 #define LLL_DEAD_OWNER (1U << 30)
30 #define LLL_OWNER_MASK ~(LLL_WAITERS | LLL_DEAD_OWNER)
32 /* Wait on 64-bit address PTR, without blocking if its contents
33 are different from the pair <LO, HI>. */
34 #define lll_xwait(ptr, lo, hi, flags) \
35 __gsync_wait (__mach_task_self (), \
36 (vm_offset_t)ptr, lo, hi, 0, flags | GSYNC_QUAD)
38 /* Same as 'lll_wait', but only block for MLSEC milliseconds. */
39 #define lll_timed_wait(ptr, val, mlsec, flags) \
40 __gsync_wait (__mach_task_self (), \
41 (vm_offset_t)ptr, val, 0, mlsec, flags | GSYNC_TIMED)
43 /* Same as 'lll_xwait', but only block for MLSEC milliseconds. */
44 #define lll_timed_xwait(ptr, lo, hi, mlsec, flags) \
45 __gsync_wait (__mach_task_self (), (vm_offset_t)ptr, \
46 lo, hi, mlsec, flags | GSYNC_TIMED | GSYNC_QUAD)
48 /* Same as 'lll_wait', but only block until TSP elapses,
49 using clock CLK. */
50 extern int __lll_abstimed_wait (void *__ptr, int __val,
51 const struct timespec *__tsp, int __flags, int __clk);
53 /* Same as 'lll_xwait', but only block until TSP elapses,
54 using clock CLK. */
55 extern int __lll_abstimed_xwait (void *__ptr, int __lo, int __hi,
56 const struct timespec *__tsp, int __flags, int __clk);
58 /* Same as 'lll_lock', but return with an error if TSP elapses,
59 using clock CLK. */
60 extern int __lll_abstimed_lock (void *__ptr,
61 const struct timespec *__tsp, int __flags, int __clk);
63 /* Acquire the lock at PTR, but return with an error if
64 the process containing the owner thread dies. */
65 extern int __lll_robust_lock (void *__ptr, int __flags);
67 /* Same as '__lll_robust_lock', but only block until TSP
68 elapses, using clock CLK. */
69 extern int __lll_robust_abstimed_lock (void *__ptr,
70 const struct timespec *__tsp, int __flags, int __clk);
72 /* Same as '__lll_robust_lock', but return with an error
73 if the lock cannot be acquired without blocking. */
74 extern int __lll_robust_trylock (void *__ptr);
76 /* Wake one or more threads waiting on address PTR,
77 setting its value to VAL before doing so. */
78 #define lll_set_wake(ptr, val, flags) \
79 __gsync_wake (__mach_task_self (), \
80 (vm_offset_t)ptr, val, flags | GSYNC_MUTATE)
82 /* Release the robust lock at PTR. */
83 extern void __lll_robust_unlock (void *__ptr, int __flags);
85 /* Rearrange threads waiting on address SRC to instead wait on
86 DST, waking one of them if WAIT_ONE is non-zero. */
87 #define lll_requeue(src, dst, wake_one, flags) \
88 __gsync_requeue (__mach_task_self (), (vm_offset_t)src, \
89 (vm_offset_t)dst, (boolean_t)wake_one, flags)
91 /* The following are hacks that allow us to simulate optional
92 parameters in C, to avoid having to pass the clock id for
93 every one of these calls, defaulting to CLOCK_REALTIME if
94 no argument is passed. */
96 #define lll_abstimed_wait(ptr, val, tsp, flags, ...) \
97 ({ \
98 const clockid_t __clk[] = { CLOCK_REALTIME, ##__VA_ARGS__ }; \
99 __lll_abstimed_wait ((ptr), (val), (tsp), (flags), \
100 __clk[sizeof (__clk) / sizeof (__clk[0]) - 1]); \
103 #define lll_abstimed_xwait(ptr, lo, hi, tsp, flags, ...) \
104 ({ \
105 const clockid_t __clk[] = { CLOCK_REALTIME, ##__VA_ARGS__ }; \
106 __lll_abstimed_xwait ((ptr), (lo), (hi), (tsp), (flags), \
107 __clk[sizeof (__clk) / sizeof (__clk[0]) - 1]); \
110 #define lll_abstimed_lock(ptr, tsp, flags, ...) \
111 ({ \
112 const clockid_t __clk[] = { CLOCK_REALTIME, ##__VA_ARGS__ }; \
113 __lll_abstimed_lock ((ptr), (tsp), (flags), \
114 __clk[sizeof (__clk) / sizeof (__clk[0]) - 1]); \
117 #define lll_robust_abstimed_lock(ptr, tsp, flags, ...) \
118 ({ \
119 const clockid_t __clk[] = { CLOCK_REALTIME, ##__VA_ARGS__ }; \
120 __lll_robust_abstimed_lock ((ptr), (tsp), (flags), \
121 __clk[sizeof (__clk) / sizeof (__clk[0]) - 1]); \
125 #endif