1 /* Notify initiator of AIO request.
2 Copyright (C) 1997, 1998 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 Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 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 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
27 __aio_notify_only (struct sigevent
*sigev
)
31 /* Send the signal to notify about finished processing of the request. */
32 if (sigev
->sigev_notify
== SIGEV_THREAD
)
34 /* We have to start a thread. */
36 pthread_attr_t attr
, *pattr
;
38 pattr
= (pthread_attr_t
*) sigev
->sigev_notify_attributes
;
41 pthread_attr_init (&attr
);
42 pthread_attr_setdetachstate (&attr
, PTHREAD_CREATE_DETACHED
);
46 if (pthread_create (&tid
, pattr
,
47 (void *(*) (void *)) sigev
->sigev_notify_function
,
48 sigev
->sigev_value
.sival_ptr
) < 0)
51 else if (sigev
->sigev_notify
== SIGEV_SIGNAL
)
52 /* We have to send a signal. */
53 if (__aio_sigqueue (sigev
->sigev_signo
, sigev
->sigev_value
) < 0)
61 __aio_notify (struct requestlist
*req
)
63 struct waitlist
*waitlist
;
64 struct aiocb
*aiocbp
= &req
->aiocbp
->aiocb
;
66 if (__aio_notify_only (&aiocbp
->aio_sigevent
) != 0)
68 /* XXX What shall we do if already an error is set by
70 aiocbp
->__error_code
= errno
;
71 aiocbp
->__return_value
= -1;
74 /* Now also notify possibly waiting threads. */
75 waitlist
= req
->waiting
;
76 while (waitlist
!= NULL
)
78 struct waitlist
*next
= waitlist
->next
;
80 /* Decrement the counter. This is used in both cases. */
81 --*waitlist
->counterp
;
83 if (waitlist
->sigevp
== NULL
)
84 pthread_cond_signal (waitlist
->cond
);
86 /* This is part of a asynchronous `lio_listio' operation. If
87 this request is the last one, send the signal. */
88 if (*waitlist
->counterp
== 0)
90 __aio_notify_only (waitlist
->sigevp
);
91 /* This is tricky. See lio_listio.c for the reason why
93 free ((void *) waitlist
->counterp
);