Adjust use of lll_futex_* macros.
[kopensolaris-gnu/glibc.git] / nptl / sysdeps / pthread / aio_misc.h
1 /* Copyright (C) 2006, 2007 Free Software Foundation, Inc.
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
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18
19 /* We define a special synchronization primitive for AIO.  POSIX
20    conditional variables would be ideal but the pthread_cond_*wait
21    operations do not return on EINTR.  This is a requirement for
22    correct aio_suspend and lio_listio implementations.  */
23
24 #include <assert.h>
25 #include <pthreadP.h>
26 #include <lowlevellock.h>
27
28 #define DONT_NEED_AIO_MISC_COND 1
29
30 #define AIO_MISC_NOTIFY(waitlist) \
31   do {                                                                        \
32     if (*waitlist->counterp > 0 && --*waitlist->counterp == 0)                \
33       lll_private_futex_wake (waitlist->counterp, 1);                         \
34   } while (0)
35
36 #define AIO_MISC_WAIT(result, futex, timeout, cancel)                         \
37   do {                                                                        \
38     volatile int *futexaddr = &futex;                                         \
39     int oldval = futex;                                                       \
40                                                                               \
41     if (oldval != 0)                                                          \
42       {                                                                       \
43         pthread_mutex_unlock (&__aio_requests_mutex);                         \
44                                                                               \
45         int oldtype;                                                          \
46         if (cancel)                                                           \
47           oldtype = LIBC_CANCEL_ASYNC ();                                     \
48                                                                               \
49         int status;                                                           \
50         do                                                                    \
51           {                                                                   \
52             status = lll_private_futex_timed_wait (futexaddr, oldval,         \
53                                                    timeout);                  \
54             if (status != -EWOULDBLOCK)                                       \
55               break;                                                          \
56                                                                               \
57             oldval = *futexaddr;                                              \
58           }                                                                   \
59         while (oldval != 0);                                                  \
60                                                                               \
61         if (cancel)                                                           \
62           LIBC_CANCEL_RESET (oldtype);                                        \
63                                                                               \
64         if (status == -EINTR)                                                 \
65           result = EINTR;                                                     \
66         else if (status == -ETIMEDOUT)                                        \
67           result = EAGAIN;                                                    \
68         else                                                                  \
69           assert (status == 0 || status == -EWOULDBLOCK);                     \
70                                                                               \
71         pthread_mutex_lock (&__aio_requests_mutex);                           \
72       }                                                                       \
73   } while (0)
74
75 #include_next <aio_misc.h>