2021-06-22 07:50:27 +00:00
|
|
|
/* Suspend until termination of a requests.
|
2023-01-06 21:08:04 +00:00
|
|
|
Copyright (C) 1997-2023 Free Software Foundation, Inc.
|
1997-06-23 21:55:26 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1997-06-23 21:55:26 +00:00
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
1997-06-23 21:55:26 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
1995-02-18 01:27:10 +00:00
|
|
|
|
2005-12-14 08:43:25 +00:00
|
|
|
|
|
|
|
/* We use an UGLY hack to prevent gcc from finding us cheating. The
|
|
|
|
implementations of aio_suspend and aio_suspend64 are identical and so
|
|
|
|
we want to avoid code duplication by using aliases. But gcc sees
|
|
|
|
the different parameter lists and prints a warning. We define here
|
|
|
|
a function so that aio_suspend64 has no prototype. */
|
|
|
|
#define aio_suspend64 XXX
|
|
|
|
#include <aio.h>
|
|
|
|
/* And undo the hack. */
|
|
|
|
#undef aio_suspend64
|
|
|
|
|
2021-06-22 07:50:27 +00:00
|
|
|
#include <assert.h>
|
1995-02-18 01:27:10 +00:00
|
|
|
#include <errno.h>
|
2021-06-22 07:50:27 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
2005-12-14 08:43:25 +00:00
|
|
|
#include <sys/time.h>
|
1995-02-18 01:27:10 +00:00
|
|
|
|
2021-06-22 07:50:27 +00:00
|
|
|
#include <libc-lock.h>
|
|
|
|
#include <aio_misc.h>
|
2021-06-25 08:30:36 +00:00
|
|
|
#include <pthreadP.h>
|
|
|
|
#include <shlib-compat.h>
|
2021-06-22 07:50:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct clparam
|
|
|
|
{
|
|
|
|
const struct aiocb *const *list;
|
|
|
|
struct waitlist *waitlist;
|
|
|
|
struct requestlist **requestlist;
|
|
|
|
#ifndef DONT_NEED_AIO_MISC_COND
|
|
|
|
pthread_cond_t *cond;
|
|
|
|
#endif
|
|
|
|
int nent;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
cleanup (void *arg)
|
|
|
|
{
|
|
|
|
#ifdef DONT_NEED_AIO_MISC_COND
|
|
|
|
/* Acquire the mutex. If pthread_cond_*wait is used this would
|
|
|
|
happen implicitly. */
|
2021-06-25 08:30:36 +00:00
|
|
|
__pthread_mutex_lock (&__aio_requests_mutex);
|
2021-06-22 07:50:27 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
const struct clparam *param = (const struct clparam *) arg;
|
|
|
|
|
|
|
|
/* Now remove the entry in the waiting list for all requests
|
|
|
|
which didn't terminate. */
|
|
|
|
int cnt = param->nent;
|
|
|
|
while (cnt-- > 0)
|
|
|
|
if (param->list[cnt] != NULL
|
|
|
|
&& param->list[cnt]->__error_code == EINPROGRESS)
|
|
|
|
{
|
|
|
|
struct waitlist **listp;
|
|
|
|
|
|
|
|
assert (param->requestlist[cnt] != NULL);
|
|
|
|
|
|
|
|
/* There is the chance that we cannot find our entry anymore. This
|
|
|
|
could happen if the request terminated and restarted again. */
|
|
|
|
listp = ¶m->requestlist[cnt]->waiting;
|
|
|
|
while (*listp != NULL && *listp != ¶m->waitlist[cnt])
|
|
|
|
listp = &(*listp)->next;
|
|
|
|
|
|
|
|
if (*listp != NULL)
|
|
|
|
*listp = (*listp)->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef DONT_NEED_AIO_MISC_COND
|
|
|
|
/* Release the conditional variable. */
|
|
|
|
(void) pthread_cond_destroy (param->cond);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Release the mutex. */
|
2021-06-25 08:30:36 +00:00
|
|
|
__pthread_mutex_unlock (&__aio_requests_mutex);
|
2021-06-22 07:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DONT_NEED_AIO_MISC_COND
|
|
|
|
static int
|
|
|
|
__attribute__ ((noinline))
|
|
|
|
do_aio_misc_wait (unsigned int *cntr, const struct __timespec64 *timeout)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
AIO_MISC_WAIT (result, *cntr, timeout, 1);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
1995-02-18 01:27:10 +00:00
|
|
|
|
2005-12-14 08:43:25 +00:00
|
|
|
int
|
2021-06-25 08:30:36 +00:00
|
|
|
___aio_suspend_time64 (const struct aiocb *const list[], int nent,
|
2021-06-22 07:50:27 +00:00
|
|
|
const struct __timespec64 *timeout)
|
1995-02-18 01:27:10 +00:00
|
|
|
{
|
2021-06-22 07:50:27 +00:00
|
|
|
if (__glibc_unlikely (nent < 0))
|
|
|
|
{
|
|
|
|
__set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct waitlist waitlist[nent];
|
|
|
|
struct requestlist *requestlist[nent];
|
|
|
|
#ifndef DONT_NEED_AIO_MISC_COND
|
|
|
|
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
|
|
|
|
#endif
|
|
|
|
int cnt;
|
|
|
|
bool any = false;
|
|
|
|
int result = 0;
|
|
|
|
unsigned int cntr = 1;
|
|
|
|
|
|
|
|
/* Request the mutex. */
|
2021-06-25 08:30:36 +00:00
|
|
|
__pthread_mutex_lock (&__aio_requests_mutex);
|
2021-06-22 07:50:27 +00:00
|
|
|
|
|
|
|
/* There is not yet a finished request. Signal the request that
|
|
|
|
we are working for it. */
|
|
|
|
for (cnt = 0; cnt < nent; ++cnt)
|
|
|
|
if (list[cnt] != NULL)
|
|
|
|
{
|
|
|
|
if (list[cnt]->__error_code == EINPROGRESS)
|
|
|
|
{
|
|
|
|
requestlist[cnt] = __aio_find_req ((aiocb_union *) list[cnt]);
|
|
|
|
|
|
|
|
if (requestlist[cnt] != NULL)
|
|
|
|
{
|
|
|
|
#ifndef DONT_NEED_AIO_MISC_COND
|
|
|
|
waitlist[cnt].cond = &cond;
|
|
|
|
#endif
|
|
|
|
waitlist[cnt].result = NULL;
|
|
|
|
waitlist[cnt].next = requestlist[cnt]->waiting;
|
|
|
|
waitlist[cnt].counterp = &cntr;
|
|
|
|
waitlist[cnt].sigevp = NULL;
|
|
|
|
requestlist[cnt]->waiting = &waitlist[cnt];
|
|
|
|
any = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* We will never suspend. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* We will never suspend. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct __timespec64 ts;
|
|
|
|
if (timeout != NULL)
|
|
|
|
{
|
|
|
|
__clock_gettime64 (CLOCK_MONOTONIC, &ts);
|
|
|
|
ts.tv_sec += timeout->tv_sec;
|
|
|
|
ts.tv_nsec += timeout->tv_nsec;
|
|
|
|
if (ts.tv_nsec >= 1000000000)
|
|
|
|
{
|
|
|
|
ts.tv_nsec -= 1000000000;
|
|
|
|
ts.tv_sec++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only if none of the entries is NULL or finished to be wait. */
|
|
|
|
if (cnt == nent && any)
|
|
|
|
{
|
|
|
|
struct clparam clparam =
|
|
|
|
{
|
|
|
|
.list = list,
|
|
|
|
.waitlist = waitlist,
|
|
|
|
.requestlist = requestlist,
|
|
|
|
#ifndef DONT_NEED_AIO_MISC_COND
|
|
|
|
.cond = &cond,
|
|
|
|
#endif
|
|
|
|
.nent = nent
|
|
|
|
};
|
|
|
|
|
2021-06-25 08:30:36 +00:00
|
|
|
#if PTHREAD_IN_LIBC
|
|
|
|
__libc_cleanup_region_start (1, cleanup, &clparam);
|
|
|
|
#else
|
|
|
|
__pthread_cleanup_push (cleanup, &clparam);
|
|
|
|
#endif
|
2021-06-22 07:50:27 +00:00
|
|
|
|
|
|
|
#ifdef DONT_NEED_AIO_MISC_COND
|
|
|
|
result = do_aio_misc_wait (&cntr, timeout == NULL ? NULL : &ts);
|
|
|
|
#else
|
|
|
|
struct timespec ts32 = valid_timespec64_to_timespec (ts);
|
|
|
|
result = pthread_cond_timedwait (&cond, &__aio_requests_mutex,
|
|
|
|
timeout == NULL ? NULL : &ts32);
|
|
|
|
#endif
|
|
|
|
|
2021-06-25 08:30:36 +00:00
|
|
|
#if PTHREAD_IN_LIBC
|
|
|
|
__libc_cleanup_region_end (0);
|
|
|
|
#else
|
2021-06-22 07:50:27 +00:00
|
|
|
pthread_cleanup_pop (0);
|
2021-06-25 08:30:36 +00:00
|
|
|
#endif
|
2021-06-22 07:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now remove the entry in the waiting list for all requests
|
|
|
|
which didn't terminate. */
|
|
|
|
while (cnt-- > 0)
|
|
|
|
if (list[cnt] != NULL && list[cnt]->__error_code == EINPROGRESS)
|
|
|
|
{
|
|
|
|
struct waitlist **listp;
|
|
|
|
|
|
|
|
assert (requestlist[cnt] != NULL);
|
|
|
|
|
|
|
|
/* There is the chance that we cannot find our entry anymore. This
|
|
|
|
could happen if the request terminated and restarted again. */
|
|
|
|
listp = &requestlist[cnt]->waiting;
|
|
|
|
while (*listp != NULL && *listp != &waitlist[cnt])
|
|
|
|
listp = &(*listp)->next;
|
|
|
|
|
|
|
|
if (*listp != NULL)
|
|
|
|
*listp = (*listp)->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef DONT_NEED_AIO_MISC_COND
|
|
|
|
/* Release the conditional variable. */
|
|
|
|
if (__glibc_unlikely (pthread_cond_destroy (&cond) != 0))
|
|
|
|
/* This must never happen. */
|
|
|
|
abort ();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (result != 0)
|
|
|
|
{
|
|
|
|
#ifndef DONT_NEED_AIO_MISC_COND
|
|
|
|
/* An error occurred. Possibly it's ETIMEDOUT. We have to translate
|
|
|
|
the timeout error report of `pthread_cond_timedwait' to the
|
|
|
|
form expected from `aio_suspend'. */
|
|
|
|
if (result == ETIMEDOUT)
|
|
|
|
__set_errno (EAGAIN);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
__set_errno (result);
|
|
|
|
|
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the mutex. */
|
2021-06-25 08:30:36 +00:00
|
|
|
__pthread_mutex_unlock (&__aio_requests_mutex);
|
2021-06-22 07:50:27 +00:00
|
|
|
|
|
|
|
return result;
|
1995-02-18 01:27:10 +00:00
|
|
|
}
|
|
|
|
|
2021-06-25 08:30:36 +00:00
|
|
|
#if __TIMESIZE == 64
|
|
|
|
strong_alias (___aio_suspend_time64, __aio_suspend)
|
|
|
|
#else /* __TIMESIZE != 64 */
|
|
|
|
# if PTHREAD_IN_LIBC
|
|
|
|
libc_hidden_ver (___aio_suspend_time64, __aio_suspend_time64)
|
|
|
|
/* The conditional is slightly wrong: PTHREAD_IN_LIBC is a stand-in
|
|
|
|
for whether time64 support is needed. */
|
|
|
|
versioned_symbol (libc, ___aio_suspend_time64, __aio_suspend_time64, GLIBC_2_34);
|
|
|
|
# else
|
|
|
|
librt_hidden_ver (___aio_suspend_time64, __aio_suspend_time64)
|
|
|
|
# endif
|
2021-06-22 07:50:27 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
__aio_suspend (const struct aiocb *const list[], int nent,
|
|
|
|
const struct timespec *timeout)
|
|
|
|
{
|
|
|
|
struct __timespec64 ts64;
|
|
|
|
|
|
|
|
if (timeout != NULL)
|
|
|
|
ts64 = valid_timespec_to_timespec64 (*timeout);
|
|
|
|
|
|
|
|
return __aio_suspend_time64 (list, nent, timeout != NULL ? &ts64 : NULL);
|
|
|
|
}
|
2021-06-25 08:30:36 +00:00
|
|
|
#endif /* __TIMESPEC64 != 64 */
|
|
|
|
|
|
|
|
#if PTHREAD_IN_LIBC
|
|
|
|
versioned_symbol (libc, __aio_suspend, aio_suspend, GLIBC_2_34);
|
|
|
|
versioned_symbol (libc, __aio_suspend, aio_suspend64, GLIBC_2_34);
|
|
|
|
# if OTHER_SHLIB_COMPAT (librt, GLIBC_2_1, GLIBC_2_34)
|
|
|
|
compat_symbol (librt, __aio_suspend, aio_suspend, GLIBC_2_1);
|
|
|
|
compat_symbol (librt, __aio_suspend, aio_suspend64, GLIBC_2_1);
|
|
|
|
# endif
|
|
|
|
#else /* !PTHREAD_IN_LIBC */
|
2021-06-22 07:50:27 +00:00
|
|
|
weak_alias (__aio_suspend, aio_suspend)
|
2021-06-25 08:30:36 +00:00
|
|
|
weak_alias (__aio_suspend, aio_suspend64)
|
|
|
|
#endif /* !PTHREAD_IN_LIBC */
|