]>
Commit | Line | Data |
---|---|---|
581c785b | 1 | /* Copyright (C) 2006-2022 Free Software Foundation, Inc. |
679d83ba UD |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 | 15 | License along with the GNU C Library; if not, see |
5a82c748 | 16 | <https://www.gnu.org/licenses/>. */ |
679d83ba UD |
17 | |
18 | /* We define a special synchronization primitive for AIO. POSIX | |
19 | conditional variables would be ideal but the pthread_cond_*wait | |
20 | operations do not return on EINTR. This is a requirement for | |
21 | correct aio_suspend and lio_listio implementations. */ | |
22 | ||
23 | #include <assert.h> | |
3c79234c | 24 | #include <pthreadP.h> |
a2f0363f | 25 | #include <futex-internal.h> |
679d83ba UD |
26 | |
27 | #define DONT_NEED_AIO_MISC_COND 1 | |
28 | ||
29 | #define AIO_MISC_NOTIFY(waitlist) \ | |
30 | do { \ | |
d052233c | 31 | if (*waitlist->counterp > 0 && --*waitlist->counterp == 0) \ |
a2f0363f | 32 | futex_wake ((unsigned int *) waitlist->counterp, 1, FUTEX_PRIVATE); \ |
679d83ba UD |
33 | } while (0) |
34 | ||
35 | #define AIO_MISC_WAIT(result, futex, timeout, cancel) \ | |
36 | do { \ | |
86edd44f RM |
37 | volatile unsigned int *futexaddr = &futex; \ |
38 | unsigned int oldval = futex; \ | |
679d83ba UD |
39 | \ |
40 | if (oldval != 0) \ | |
41 | { \ | |
d12506b2 | 42 | __pthread_mutex_unlock (&__aio_requests_mutex); \ |
679d83ba | 43 | \ |
679d83ba UD |
44 | int status; \ |
45 | do \ | |
46 | { \ | |
ce7eb0e9 | 47 | if (cancel) \ |
cc5d5852 LM |
48 | status = __futex_abstimed_wait_cancelable64 ( \ |
49 | (unsigned int *) futexaddr, oldval, CLOCK_MONOTONIC, timeout, \ | |
50 | FUTEX_PRIVATE); \ | |
ce7eb0e9 | 51 | else \ |
cc5d5852 LM |
52 | status = __futex_abstimed_wait64 ((unsigned int *) futexaddr, \ |
53 | oldval, CLOCK_REALTIME, timeout, FUTEX_PRIVATE); \ | |
a2f0363f | 54 | if (status != EAGAIN) \ |
679d83ba UD |
55 | break; \ |
56 | \ | |
04454efb | 57 | oldval = *futexaddr; \ |
679d83ba UD |
58 | } \ |
59 | while (oldval != 0); \ | |
60 | \ | |
a2f0363f | 61 | if (status == EINTR) \ |
679d83ba | 62 | result = EINTR; \ |
a2f0363f | 63 | else if (status == ETIMEDOUT) \ |
679d83ba | 64 | result = EAGAIN; \ |
cc5d5852 LM |
65 | else if (status == EOVERFLOW) \ |
66 | result = EOVERFLOW; \ | |
679d83ba | 67 | else \ |
a2f0363f | 68 | assert (status == 0 || status == EAGAIN); \ |
679d83ba | 69 | \ |
d12506b2 | 70 | __pthread_mutex_lock (&__aio_requests_mutex); \ |
679d83ba UD |
71 | } \ |
72 | } while (0) | |
73 | ||
74 | #include_next <aio_misc.h> |