]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/pthread/aio_cancel.c
1 /* Cancel requests associated with given file descriptor.
2 Copyright (C) 1997, 1998, 2000, 2002 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
22 /* We use an UGLY hack to prevent gcc from finding us cheating. The
23 implementation of aio_cancel and aio_cancel64 are identical and so
24 we want to avoid code duplication by using aliases. But gcc sees
25 the different parameter lists and prints a warning. We define here
26 a function so that aio_cancel64 has no prototype. */
28 #define aio_cancel64 XXX
30 /* And undo the hack. */
41 aio_cancel (fildes
, aiocbp
)
45 struct requestlist
*req
= NULL
;
46 int result
= AIO_ALLDONE
;
48 /* If fildes is invalid, error. */
49 if (fcntl (fildes
, F_GETFL
) < 0)
55 /* Request the mutex. */
56 pthread_mutex_lock (&__aio_requests_mutex
);
58 /* We are asked to cancel a specific AIO request. */
61 /* If the AIO request is not for this descriptor it has no value
62 to look for the request block. */
63 if (aiocbp
->aio_fildes
== fildes
)
65 struct requestlist
*last
= NULL
;
67 req
= __aio_find_req_fd (fildes
);
72 pthread_mutex_unlock (&__aio_requests_mutex
);
77 while (req
->aiocbp
!= (aiocb_union
*) aiocbp
)
85 /* Don't remove the entry if a thread is already working on it. */
86 if (req
->running
== allocated
)
88 result
= AIO_NOTCANCELED
;
93 /* We can remove the entry. */
94 __aio_remove_request (last
, req
, 0);
96 result
= AIO_CANCELED
;
98 req
->next_prio
= NULL
;
104 /* Find the beginning of the list of all requests for this
106 req
= __aio_find_req_fd (fildes
);
108 /* If any request is worked on by a thread it must be the first.
109 So either we can delete all requests or all but the first. */
112 if (req
->running
== allocated
)
114 struct requestlist
*old
= req
;
115 req
= req
->next_prio
;
116 old
->next_prio
= NULL
;
118 result
= AIO_NOTCANCELED
;
121 __aio_remove_request (old
, req
, 1);
125 result
= AIO_CANCELED
;
127 /* We can remove the entry. */
128 __aio_remove_request (NULL
, req
, 1);
133 /* Mark requests as canceled and send signal. */
136 struct requestlist
*old
= req
;
137 assert (req
->running
== yes
|| req
->running
== queued
);
138 req
->aiocbp
->aiocb
.__error_code
= ECANCELED
;
139 req
->aiocbp
->aiocb
.__return_value
= -1;
141 req
= req
->next_prio
;
142 __aio_free_request (old
);
145 /* Release the mutex. */
146 pthread_mutex_unlock (&__aio_requests_mutex
);
152 weak_alias (aio_cancel
, aio_cancel64
)