1 /* Notify initiator of AIO request.
2 Copyright (C) 1997,98,99,2000,01 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
29 notify_func_wrapper (void *arg
)
31 struct sigevent
*sigev
= arg
;
32 sigev
->sigev_notify_function (sigev
->sigev_value
);
39 __aio_notify_only (struct sigevent
*sigev
, pid_t caller_pid
)
43 /* Send the signal to notify about finished processing of the request. */
44 if (sigev
->sigev_notify
== SIGEV_THREAD
)
46 /* We have to start a thread. */
48 pthread_attr_t attr
, *pattr
;
50 pattr
= (pthread_attr_t
*) sigev
->sigev_notify_attributes
;
53 pthread_attr_init (&attr
);
54 pthread_attr_setdetachstate (&attr
, PTHREAD_CREATE_DETACHED
);
58 if (pthread_create (&tid
, pattr
, notify_func_wrapper
, sigev
) < 0)
61 else if (sigev
->sigev_notify
== SIGEV_SIGNAL
)
63 /* We have to send a signal. */
64 #if _POSIX_REALTIME_SIGNALS
65 /* Note that the standard gives us the option of using a plain
66 non-queuing signal here when SA_SIGINFO is not set for the signal. */
67 if (__aio_sigqueue (sigev
->sigev_signo
, sigev
->sigev_value
, caller_pid
)
71 /* There are no queued signals on this system at all. */
72 result
= raise (sigev
->sigev_signo
);
82 __aio_notify (struct requestlist
*req
)
84 struct waitlist
*waitlist
;
85 struct aiocb
*aiocbp
= &req
->aiocbp
->aiocb
;
87 if (__aio_notify_only (&aiocbp
->aio_sigevent
, req
->caller_pid
) != 0)
89 /* XXX What shall we do if already an error is set by
91 aiocbp
->__error_code
= errno
;
92 aiocbp
->__return_value
= -1;
95 /* Now also notify possibly waiting threads. */
96 waitlist
= req
->waiting
;
97 while (waitlist
!= NULL
)
99 struct waitlist
*next
= waitlist
->next
;
101 /* Decrement the counter. This is used in both cases. */
102 --*waitlist
->counterp
;
104 if (waitlist
->sigevp
== NULL
)
105 pthread_cond_signal (waitlist
->cond
);
107 /* This is part of a asynchronous `lio_listio' operation. If
108 this request is the last one, send the signal. */
109 if (*waitlist
->counterp
== 0)
111 __aio_notify_only (waitlist
->sigevp
, waitlist
->caller_pid
);
112 /* This is tricky. See lio_listio.c for the reason why
114 free ((void *) waitlist
->counterp
);