]>
Commit | Line | Data |
---|---|---|
d1e44df1 | 1 | /* Low-level locking access to futex facilities. NaCl version. |
bfff8b1b | 2 | Copyright (C) 2015-2017 Free Software Foundation, Inc. |
d1e44df1 RM |
3 | This file is part of the GNU C Library. |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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/>. */ | |
18 | ||
19 | #ifndef _LOWLEVELLOCK_FUTEX_H | |
20 | #define _LOWLEVELLOCK_FUTEX_H 1 | |
21 | ||
22 | #include <nacl-interfaces.h> | |
23 | #include <time.h> | |
24 | ||
25 | ||
26 | #pragma GCC diagnostic ignored "-Wunused-value" /* XXX */ | |
27 | ||
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 | |
32 | ||
33 | #define FUTEX_PRIVATE_FLAG 0 /* XXX */ | |
34 | ||
35 | ||
36 | /* Wait while *FUTEXP == VAL for an lll_futex_wake call on FUTEXP. */ | |
37 | #define lll_futex_wait(futexp, val, private) \ | |
a3140836 RM |
38 | ((void) (private), \ |
39 | - __nacl_irt_futex.futex_wait_abs ((volatile int *) (futexp), val, NULL)) | |
d1e44df1 RM |
40 | |
41 | /* Wait until a lll_futex_wake call on FUTEXP, or TIMEOUT elapses. */ | |
42 | #define lll_futex_timed_wait(futexp, val, timeout, private) \ | |
43 | ({ \ | |
f2175470 | 44 | /* This timeout is relative, but the IRT call wants it absolute. */\ |
d1e44df1 RM |
45 | const struct timespec *_to = (timeout); \ |
46 | struct timespec _ts; \ | |
47 | int _err = 0; \ | |
48 | if (_to != NULL \ | |
f2175470 RM |
49 | && __glibc_likely ((_err = __nacl_irt_clock.clock_gettime \ |
50 | (CLOCK_REALTIME, &_ts)) == 0)) \ | |
d1e44df1 | 51 | { \ |
f2175470 RM |
52 | _ts.tv_sec += _to->tv_sec; \ |
53 | _ts.tv_nsec += _to->tv_nsec; \ | |
54 | while (_ts.tv_nsec >= 1000000000) \ | |
55 | { \ | |
56 | _ts.tv_nsec -= 1000000000; \ | |
57 | ++_ts.tv_sec; \ | |
58 | } \ | |
59 | _to = &_ts; \ | |
d1e44df1 RM |
60 | } \ |
61 | if (_err == 0) \ | |
62 | _err = __nacl_irt_futex.futex_wait_abs \ | |
f2175470 | 63 | ((volatile int *) (futexp), val, _to); \ |
a3140836 RM |
64 | (void) (private); \ |
65 | -_err; \ | |
d1e44df1 RM |
66 | }) |
67 | ||
68 | /* Wake up up to NR waiters on FUTEXP. */ | |
69 | #define lll_futex_wake(futexp, nr, private) \ | |
70 | ({ \ | |
71 | int _woken; \ | |
a3140836 | 72 | (void) (private); \ |
d1e44df1 RM |
73 | - __nacl_irt_futex.futex_wake ((volatile int *) (futexp), nr, &_woken); \ |
74 | }) | |
75 | ||
76 | /* NaCl does not support the requeue operation. The only use of this is in | |
77 | pthread_cond_broadcast, which handles an error return by falling back to | |
78 | plain lll_futex_wake. */ | |
79 | #define lll_futex_requeue(futexp, nr_wake, nr_move, mutex, val, private) \ | |
80 | ((futexp), (nr_wake), (nr_move), (mutex), (val), (private), -ENOSYS) | |
81 | ||
82 | /* NaCl does not support the special wake-unlock operation. The only use | |
83 | of this is in pthread_cond_signal, which handles an error return by | |
84 | falling back to plain lll_futex_wake. */ | |
85 | /* Wake up up to NR_WAKE waiters on FUTEXP and NR_WAKE2 on FUTEXP2. */ | |
86 | #define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2, private) \ | |
87 | ((futexp), (nr_wake), (nr_wake2), (futexp2), (private), -ENOSYS) | |
88 | ||
89 | ||
90 | #endif /* lowlevellock-futex.h */ |