Modify elf/tst-audit9.c to use test-skeleton.c
[glibc.git] / sysdeps / nacl / lowlevellock-futex.h
blobb614ac8183f29f1d3b42522496602182b2aa1989
1 /* Low-level locking access to futex facilities. NaCl version.
2 Copyright (C) 2015 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 _LOWLEVELLOCK_FUTEX_H
20 #define _LOWLEVELLOCK_FUTEX_H 1
22 #include <nacl-interfaces.h>
23 #include <time.h>
26 #pragma GCC diagnostic ignored "-Wunused-value" /* XXX */
28 /* Values for 'private' parameter of locking macros. Note pthreadP.h
29 optimizes for these exact values, though they are not required. */
30 #define LLL_PRIVATE 0
31 #define LLL_SHARED 128
33 #define FUTEX_PRIVATE_FLAG 0 /* XXX */
36 /* Wait while *FUTEXP == VAL for an lll_futex_wake call on FUTEXP. */
37 #define lll_futex_wait(futexp, val, private) \
38 (- __nacl_irt_futex.futex_wait_abs ((volatile int *) (futexp), val, NULL))
40 /* Wait until a lll_futex_wake call on FUTEXP, or TIMEOUT elapses. */
41 #define lll_futex_timed_wait(futexp, val, timeout, private) \
42 ({ \
43 /* This timeout is relative, but the IRT call wants it absolute. */\
44 const struct timespec *_to = (timeout); \
45 struct timespec _ts; \
46 int _err = 0; \
47 if (_to != NULL \
48 && __glibc_likely ((_err = __nacl_irt_clock.clock_gettime \
49 (CLOCK_REALTIME, &_ts)) == 0)) \
50 { \
51 _ts.tv_sec += _to->tv_sec; \
52 _ts.tv_nsec += _to->tv_nsec; \
53 while (_ts.tv_nsec >= 1000000000) \
54 { \
55 _ts.tv_nsec -= 1000000000; \
56 ++_ts.tv_sec; \
57 } \
58 _to = &_ts; \
59 } \
60 if (_err == 0) \
61 _err = __nacl_irt_futex.futex_wait_abs \
62 ((volatile int *) (futexp), val, _to); \
63 -_err; \
66 /* Wake up up to NR waiters on FUTEXP. */
67 #define lll_futex_wake(futexp, nr, private) \
68 ({ \
69 int _woken; \
70 - __nacl_irt_futex.futex_wake ((volatile int *) (futexp), nr, &_woken); \
73 /* NaCl does not support the requeue operation. The only use of this is in
74 pthread_cond_broadcast, which handles an error return by falling back to
75 plain lll_futex_wake. */
76 #define lll_futex_requeue(futexp, nr_wake, nr_move, mutex, val, private) \
77 ((futexp), (nr_wake), (nr_move), (mutex), (val), (private), -ENOSYS)
79 /* NaCl does not support the special wake-unlock operation. The only use
80 of this is in pthread_cond_signal, which handles an error return by
81 falling back to plain lll_futex_wake. */
82 /* Wake up up to NR_WAKE waiters on FUTEXP and NR_WAKE2 on FUTEXP2. */
83 #define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2, private) \
84 ((futexp), (nr_wake), (nr_wake2), (futexp2), (private), -ENOSYS)
87 #endif /* lowlevellock-futex.h */