summaryrefslogtreecommitdiff
path: root/sysdeps/pthread
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2006-01-06 09:23:26 +0000
committerJakub Jelinek <jakub@redhat.com>2006-01-06 09:23:26 +0000
commitdd486f53ee367e1667c61ec1fffdb59f9a8130e9 (patch)
tree6e85e00b5a067e5717c98dcadbcc6303118ffad7 /sysdeps/pthread
parent04c414477bd220f2c842453314a6dbb928e3c9e6 (diff)
Updated to fedora-glibc-20060106T0916cvs/fedora-glibc-2_3_90-28
Diffstat (limited to 'sysdeps/pthread')
-rw-r--r--sysdeps/pthread/aio_misc.h7
-rw-r--r--sysdeps/pthread/aio_notify.c22
-rw-r--r--sysdeps/pthread/aio_suspend.c40
-rw-r--r--sysdeps/pthread/lio_listio.c27
4 files changed, 79 insertions, 17 deletions
diff --git a/sysdeps/pthread/aio_misc.h b/sysdeps/pthread/aio_misc.h
index 44d53b078f..50962c7519 100644
--- a/sysdeps/pthread/aio_misc.h
+++ b/sysdeps/pthread/aio_misc.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1997,1999,2000,2001,2003,2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -46,7 +46,12 @@ struct waitlist
{
struct waitlist *next;
+ /* The next two fields is used in synchronous `lio_listio' operations. */
+#ifndef DONT_NEED_AIO_MISC_COND
pthread_cond_t *cond;
+#endif
+ int *result;
+
volatile int *counterp;
/* The next field is used in asynchronous `lio_listio' operations. */
struct sigevent *sigevp;
diff --git a/sysdeps/pthread/aio_notify.c b/sysdeps/pthread/aio_notify.c
index 877e8d9363..3f7f70ef7c 100644
--- a/sysdeps/pthread/aio_notify.c
+++ b/sysdeps/pthread/aio_notify.c
@@ -1,6 +1,5 @@
/* Notify initiator of AIO request.
- Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004
- Free Software Foundation, Inc.
+ Copyright (C) 1997-2001, 2003, 2004, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
@@ -144,15 +143,24 @@ __aio_notify (struct requestlist *req)
{
struct waitlist *next = waitlist->next;
- /* Decrement the counter. This is used in both cases. */
- --*waitlist->counterp;
-
if (waitlist->sigevp == NULL)
- pthread_cond_signal (waitlist->cond);
+ {
+ if (waitlist->result != NULL && aiocbp->__return_value == -1)
+ *waitlist->result = -1;
+
+#ifdef DONT_NEED_AIO_MISC_COND
+ AIO_MISC_NOTIFY (waitlist);
+#else
+ /* Decrement the counter. */
+ --*waitlist->counterp;
+
+ pthread_cond_signal (waitlist->cond);
+#endif
+ }
else
/* This is part of a asynchronous `lio_listio' operation. If
this request is the last one, send the signal. */
- if (*waitlist->counterp == 0)
+ if (--*waitlist->counterp == 0)
{
#ifdef BROKEN_THREAD_SIGNALS
__aio_notify_only (waitlist->sigevp, waitlist->caller_pid);
diff --git a/sysdeps/pthread/aio_suspend.c b/sysdeps/pthread/aio_suspend.c
index 8f8e33a7dc..b85b16d10e 100644
--- a/sysdeps/pthread/aio_suspend.c
+++ b/sysdeps/pthread/aio_suspend.c
@@ -1,6 +1,5 @@
/* Suspend until termination of a requests.
- Copyright (C) 1997,1998,1999,2000,2002,2003,2005
- Free Software Foundation, Inc.
+ Copyright (C) 1997-2000,2002,2003,2005,2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
@@ -45,7 +44,9 @@ 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;
};
@@ -53,6 +54,12 @@ struct clparam
static void
cleanup (void *arg)
{
+#ifdef DONT_NEED_AIO_MISC_COND
+ /* Acquire the mutex. If pthread_cond_*wait is used this would
+ happen implicitly. */
+ pthread_mutex_lock (&__aio_requests_mutex);
+#endif
+
const struct clparam *param = (const struct clparam *) arg;
/* Now remove the entry in the waiting list for all requests
@@ -76,8 +83,10 @@ cleanup (void *arg)
*listp = (*listp)->next;
}
+#ifndef DONT_NEED_AIO_MISC_COND
/* Release the conditional variable. */
(void) pthread_cond_destroy (param->cond);
+#endif
/* Release the mutex. */
pthread_mutex_unlock (&__aio_requests_mutex);
@@ -90,13 +99,21 @@ aio_suspend (list, nent, timeout)
int nent;
const struct timespec *timeout;
{
+ if (__builtin_expect (nent < 0, 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;
- int dummy;
+ int cntr = 1;
/* Request the mutex. */
pthread_mutex_lock (&__aio_requests_mutex);
@@ -112,9 +129,12 @@ aio_suspend (list, nent, timeout)
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 = &dummy;
+ waitlist[cnt].counterp = &cntr;
waitlist[cnt].sigevp = NULL;
#ifdef BROKEN_THREAD_SIGNALS
waitlist[cnt].caller_pid = 0; /* Not needed. */
@@ -140,12 +160,17 @@ aio_suspend (list, nent, timeout)
.list = list,
.waitlist = waitlist,
.requestlist = requestlist,
+#ifndef DONT_NEED_AIO_MISC_COND
.cond = &cond,
+#endif
.nent = nent
};
pthread_cleanup_push (cleanup, &clparam);
+#ifdef DONT_NEED_AIO_MISC_COND
+ AIO_MISC_WAIT (result, cntr, timeout, 1);
+#else
if (timeout == NULL)
result = pthread_cond_wait (&cond, &__aio_requests_mutex);
else
@@ -167,6 +192,7 @@ aio_suspend (list, nent, timeout)
result = pthread_cond_timedwait (&cond, &__aio_requests_mutex,
&abstime);
}
+#endif
pthread_cleanup_pop (0);
}
@@ -190,19 +216,23 @@ aio_suspend (list, nent, timeout)
*listp = (*listp)->next;
}
+#ifndef DONT_NEED_AIO_MISC_COND
/* Release the conditional variable. */
if (__builtin_expect (pthread_cond_destroy (&cond) != 0, 0))
/* This must never happen. */
abort ();
+#endif
if (result != 0)
{
- /* An error occurred. Possibly it's EINTR. We have to translate
+#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;
diff --git a/sysdeps/pthread/lio_listio.c b/sysdeps/pthread/lio_listio.c
index 815840397e..c652404ae2 100644
--- a/sysdeps/pthread/lio_listio.c
+++ b/sysdeps/pthread/lio_listio.c
@@ -122,9 +122,11 @@ lio_listio_internal (int mode, struct aiocb *const list[], int nent,
}
else if (LIO_MODE (mode) == LIO_WAIT)
{
+#ifndef DONT_NEED_AIO_MISC_COND
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
- struct waitlist waitlist[nent];
int oldstate;
+#endif
+ struct waitlist waitlist[nent];
total = 0;
for (cnt = 0; cnt < nent; ++cnt)
@@ -133,7 +135,10 @@ lio_listio_internal (int mode, struct aiocb *const list[], int nent,
if (requests[cnt] != NULL && list[cnt]->aio_lio_opcode != LIO_NOP)
{
+#ifndef DONT_NEED_AIO_MISC_COND
waitlist[cnt].cond = &cond;
+#endif
+ waitlist[cnt].result = &result;
waitlist[cnt].next = requests[cnt]->waiting;
waitlist[cnt].counterp = &total;
waitlist[cnt].sigevp = NULL;
@@ -145,21 +150,32 @@ lio_listio_internal (int mode, struct aiocb *const list[], int nent,
}
}
- /* Since `pthread_cond_wait'/`pthread_cond_timedwait' are cancelation
+#ifdef DONT_NEED_AIO_MISC_COND
+ AIO_MISC_WAIT (result, total, NULL, 0);
+#else
+ /* Since `pthread_cond_wait'/`pthread_cond_timedwait' are cancellation
points we must be careful. We added entries to the waiting lists
- which we must remove. So defer cancelation for now. */
+ which we must remove. So defer cancellation for now. */
pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &oldstate);
while (total > 0)
pthread_cond_wait (&cond, &__aio_requests_mutex);
- /* Now it's time to restore the cancelation state. */
+ /* Now it's time to restore the cancellation state. */
pthread_setcancelstate (oldstate, NULL);
/* Release the conditional variable. */
if (pthread_cond_destroy (&cond) != 0)
/* This must never happen. */
abort ();
+#endif
+
+ /* If any of the I/O requests failed, return -1 and set errno. */
+ if (result != 0)
+ {
+ __set_errno (result == EINTR ? EINTR : EIO);
+ result = -1;
+ }
}
else
{
@@ -188,7 +204,10 @@ lio_listio_internal (int mode, struct aiocb *const list[], int nent,
if (requests[cnt] != NULL
&& list[cnt]->aio_lio_opcode != LIO_NOP)
{
+#ifndef DONT_NEED_AIO_MISC_COND
waitlist->list[cnt].cond = NULL;
+#endif
+ waitlist->list[cnt].result = NULL;
waitlist->list[cnt].next = requests[cnt]->waiting;
waitlist->list[cnt].counterp = &waitlist->counter;
waitlist->list[cnt].sigevp = &waitlist->sigev;