diff options
author | Ulrich Drepper <drepper@redhat.com> | 2007-05-18 00:55:10 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2007-05-18 00:55:10 +0000 |
commit | 113ad5fc9192340269d2ce19b896d51309e785ea (patch) | |
tree | 0028c672ecec9626a07fa3dfc5bcba89b690d2f4 /nptl | |
parent | bec51a302f0e7046fcb8c4fcd13ea2969a43a9b7 (diff) | |
download | glibc-113ad5fc9192340269d2ce19b896d51309e785ea.tar.gz glibc-113ad5fc9192340269d2ce19b896d51309e785ea.tar.xz glibc-113ad5fc9192340269d2ce19b896d51309e785ea.zip |
[BZ #4512]
* pthread_mutex_lock.c: Preserve FUTEX_WAITERS bit when dead owner is detected. * pthread_mutex_timedlock.c: Likewise. * pthread_mutex_trylock.c: Likewise. Patch in part by Atsushi Nemoto <anemo@mba.ocn.ne.jp>. * Makefile (tests): Add tst-robust9 and tst-robustpi9. * tst-robust9.c: New file. * tst-robustpi9.c: New file.
Diffstat (limited to 'nptl')
-rw-r--r-- | nptl/ChangeLog | 11 | ||||
-rw-r--r-- | nptl/Makefile | 8 | ||||
-rw-r--r-- | nptl/pthread_mutex_lock.c | 4 | ||||
-rw-r--r-- | nptl/pthread_mutex_timedlock.c | 8 | ||||
-rw-r--r-- | nptl/pthread_mutex_trylock.c | 6 | ||||
-rw-r--r-- | nptl/tst-robust9.c | 87 |
6 files changed, 114 insertions, 10 deletions
diff --git a/nptl/ChangeLog b/nptl/ChangeLog index bc6caefce9..894a9bd9fb 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -1,5 +1,16 @@ 2007-05-17 Ulrich Drepper <drepper@redhat.com> + [BZ #4512] + * pthread_mutex_lock.c: Preserve FUTEX_WAITERS bit when dead owner + is detected. + * pthread_mutex_timedlock.c: Likewise. + * pthread_mutex_trylock.c: Likewise. + Patch in part by Atsushi Nemoto <anemo@mba.ocn.ne.jp>. + + * Makefile (tests): Add tst-robust9 and tst-robustpi9. + * tst-robust9.c: New file. + * tst-robustpi9.c: New file. + * sysdeps/unix/sysv/linux/sem_wait.c (__new_sem_wait): Remove unnecessary extra cancellation test. diff --git a/nptl/Makefile b/nptl/Makefile index 9393cab009..42f2fe699f 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 2002,2003,2004,2005,2006 Free Software Foundation, Inc. +# Copyright (C) 2002,2003,2004,2005,2006,2007 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 @@ -209,9 +209,9 @@ tests = tst-typesizes \ tst-cond14 tst-cond15 tst-cond16 tst-cond17 tst-cond18 tst-cond19 \ tst-cond20 tst-cond21 tst-cond22 \ tst-robust1 tst-robust2 tst-robust3 tst-robust4 tst-robust5 \ - tst-robust6 tst-robust7 tst-robust8 \ - tst-robustpi1 tst-robustpi2 tst-robustpi3 tst-robustpi4 \ - tst-robustpi5 tst-robustpi6 tst-robustpi7 tst-robustpi8 \ + tst-robust6 tst-robust7 tst-robust8 tst-robust9 \ + tst-robustpi1 tst-robustpi2 tst-robustpi3 tst-robustpi4 tst-robustpi5 \ + tst-robustpi6 tst-robustpi7 tst-robustpi8 tst-robustpi9 \ tst-rwlock1 tst-rwlock2 tst-rwlock3 tst-rwlock4 tst-rwlock5 \ tst-rwlock6 tst-rwlock7 tst-rwlock8 tst-rwlock9 tst-rwlock10 \ tst-rwlock11 tst-rwlock12 tst-rwlock13 tst-rwlock14 \ diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c index 52cc47f4cc..1c3ee4fe25 100644 --- a/nptl/pthread_mutex_lock.c +++ b/nptl/pthread_mutex_lock.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. @@ -127,6 +127,8 @@ __pthread_mutex_lock (mutex) int newval = id; #ifdef NO_INCR newval |= FUTEX_WAITERS; +#else + newval |= (oldval & FUTEX_WAITERS); #endif newval diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c index c8e6b8507a..8fd681c6ef 100644 --- a/nptl/pthread_mutex_timedlock.c +++ b/nptl/pthread_mutex_timedlock.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. @@ -119,9 +119,11 @@ pthread_mutex_timedlock (mutex, abstime) if ((oldval & FUTEX_OWNER_DIED) != 0) { /* The previous owner died. Try locking the mutex. */ - int newval + int newval = id | (oldval & FUTEX_WAITERS); + + newval = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock, - id, oldval); + newval, oldval); if (newval != oldval) { oldval = newval; diff --git a/nptl/pthread_mutex_trylock.c b/nptl/pthread_mutex_trylock.c index 4990ecd711..9db904c60b 100644 --- a/nptl/pthread_mutex_trylock.c +++ b/nptl/pthread_mutex_trylock.c @@ -84,9 +84,11 @@ __pthread_mutex_trylock (mutex) if ((oldval & FUTEX_OWNER_DIED) != 0) { /* The previous owner died. Try locking the mutex. */ - int newval + int newval = id | (oldval & FUTEX_WAITERS); + + newval = atomic_compare_and_exchange_val_acq (&mutex->__data.__lock, - id, oldval); + newval, oldval); if (newval != oldval) { diff --git a/nptl/tst-robust9.c b/nptl/tst-robust9.c new file mode 100644 index 0000000000..20cbd062dc --- /dev/null +++ b/nptl/tst-robust9.c @@ -0,0 +1,87 @@ +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <pthread.h> +#include <unistd.h> +#include <sys/time.h> + + +static pthread_mutex_t m; + +static void * +tf (void *data) +{ + int err = pthread_mutex_lock (&m); + if (err == EOWNERDEAD) + { + err = pthread_mutex_consistent_np (&m); + if (err) + { + puts ("pthread_mutex_consistent_np"); + exit (1); + } + } + else if (err) + { + puts ("pthread_mutex_lock"); + exit (1); + } + printf ("thread%ld got the lock.\n", (long int) data); + sleep (1); + /* exit without unlock */ + return NULL; +} + +static int +do_test (void) +{ + int err, i; + pthread_t t[3]; + pthread_mutexattr_t ma; + + pthread_mutexattr_init (&ma); + err = pthread_mutexattr_setrobust_np (&ma, PTHREAD_MUTEX_ROBUST_NP); + if (err) + { + puts ("pthread_mutexattr_setrobust_np"); + return 1; + } +#ifdef ENABLE_PI + if (pthread_mutexattr_setprotocol (&ma, PTHREAD_PRIO_INHERIT) != 0) + { + puts ("pthread_mutexattr_setprotocol failed"); + return 1; + } +#endif + err = pthread_mutex_init (&m, &ma); + if (err) + { + puts ("pthread_mutex_init"); + return 1; + } + + for (i = 0; i < sizeof (t) / sizeof (t[0]); i++) + { + err = pthread_create (&t[i], NULL, tf, (void *) (long int) i); + if (err) + { + puts ("pthread_create"); + return 1; + } + } + + for (i = 0; i < sizeof (t) / sizeof (t[0]); i++) + { + err = pthread_join (t[i], NULL); + if (err) + { + puts ("pthread_join"); + return 1; + } + } + return 0; +} + +#define TIMEOUT 5 +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" |