From 733f25e6d34d8ced182ffd6366d7914d56e71d98 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Fri, 3 Jan 2003 21:15:43 +0000 Subject: Update. 2003-01-03 Jakub Jelinek * sysdeps/generic/ldsodefs.h (_dl_allocate_tls, _dl_deallocate_tls): Add rtld_hidden_proto. * sysdeps/generic/dl-tls.c (_dl_deallocate_tls): Add rtld_hidden_def. (_dl_allocate_tls): Likewise. Remove INTDEF. --- nptl/ChangeLog | 11 +++++++++++ nptl/Makefile | 4 +++- nptl/atomic.h | 8 ++++---- nptl/old_pthread_cond_broadcast.c | 19 ++++++++++--------- nptl/old_pthread_cond_signal.c | 18 ++++++++++-------- nptl/old_pthread_cond_timedwait.c | 18 ++++++++++-------- nptl/old_pthread_cond_wait.c | 18 ++++++++++-------- 7 files changed, 58 insertions(+), 38 deletions(-) (limited to 'nptl') diff --git a/nptl/ChangeLog b/nptl/ChangeLog index e7173f9e4f..62744b1e37 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -1,3 +1,14 @@ +2003-01-03 Ulrich Drepper + + * atomic.h: Correct definitions of atomic_full_barrier, + atomic_read_barrier, atomic_write_barrier. + + * old_pthread_cond_broadcast.c: Make memory allocate and initialization + race-free. + * old_pthread_cond_signal.c: Likewise. + * old_pthread_cond_timedwait.c: Likewise. + * old_pthread_cond_wait.c: Likewise. + 2003-01-03 Jakub Jelinek * Makefile ($(objpfx)libpthread.so): Depend on ld.so. diff --git a/nptl/Makefile b/nptl/Makefile index 2a68c2e566..ceee78758c 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -212,8 +212,10 @@ $(objpfx)libpthread.so: +preinit += $(objpfx)crti.o # Depend on libc.so so a DT_NEEDED is generated in the shared objects. # This ensures they will load libc.so for needed symbols if loaded by # a statically-linked program that hasn't already loaded it. +# Depend on ld.so too to get proper versions of ld.so symbols. $(objpfx)libpthread.so: $(common-objpfx)libc.so \ - $(common-objpfx)libc_nonshared.a + $(common-objpfx)libc_nonshared.a \ + $(if $(filter yes,$(elf)), $(elfobjdir)/ld.so) # Make sure we link with the thread library. ifeq ($(build-shared),yes) diff --git a/nptl/atomic.h b/nptl/atomic.h index 927e0fe5ac..0464705691 100644 --- a/nptl/atomic.h +++ b/nptl/atomic.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2002 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 2002. @@ -93,17 +93,17 @@ #ifndef atomic_full_barrier -# define full_barrier() __asm ("" ::: "memory") +# define atomic_full_barrier() __asm ("" ::: "memory") #endif #ifndef atomic_read_barrier -# define read_barrier() full_barrier() +# define atomic_read_barrier() atomic_full_barrier() #endif #ifndef atomic_write_barrier -# define write_barrier() full_barrier() +# define atomic_write_barrier() atomic_full_barrier() #endif #endif /* atomic.h */ diff --git a/nptl/old_pthread_cond_broadcast.c b/nptl/old_pthread_cond_broadcast.c index a9713f5e1b..05f24bb52b 100644 --- a/nptl/old_pthread_cond_broadcast.c +++ b/nptl/old_pthread_cond_broadcast.c @@ -20,7 +20,7 @@ #include #include #include "pthreadP.h" -#include +#include #include @@ -31,18 +31,19 @@ __pthread_cond_broadcast_2_0 (cond) { if (cond->cond == NULL) { - lll_mutex_lock (cond->lock); + pthread_cond_t *newcond; - /* Check whether the condvar is still not allocated. */ - if (cond->cond == NULL) - cond->cond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t)); + newcond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t)); + if (newcond == NULL) + return ENOMEM; - lll_mutex_unlock (cond->lock); + *newcond = (struct pthread_cond_t) PTHREAD_COND_INITIALIZER; - if (cond->cond == NULL) - return ENOMEM; + atomic_write_barrier (); - *cond->cond = (struct pthread_cond_t) PTHREAD_COND_INITIALIZER; + if (atomic_compare_and_exchange_acq (&cond->cond, newcond, NULL) != 0) + /* Somebody else just initialized the condvar. */ + free (newcond); } return __pthread_cond_broadcast (cond->cond); diff --git a/nptl/old_pthread_cond_signal.c b/nptl/old_pthread_cond_signal.c index 952ee6de41..717a33912b 100644 --- a/nptl/old_pthread_cond_signal.c +++ b/nptl/old_pthread_cond_signal.c @@ -20,6 +20,7 @@ #include #include #include "pthreadP.h" +#include #include @@ -30,18 +31,19 @@ __pthread_cond_signal_2_0 (cond) { if (cond->cond == NULL) { - lll_mutex_lock (cond->lock); + pthread_cond_t *newcond; - /* Check whether the condvar is still not allocated. */ - if (cond->cond == NULL) - cond->cond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t)); + newcond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t)); + if (newcond == NULL) + return ENOMEM; - lll_mutex_unlock (cond->lock); + *newcond = (struct pthread_cond_t) PTHREAD_COND_INITIALIZER; - if (cond->cond == NULL) - return ENOMEM; + atomic_write_barrier (); - *cond->cond = (struct pthread_cond_t) PTHREAD_COND_INITIALIZER; + if (atomic_compare_and_exchange_acq (&cond->cond, newcond, NULL) != 0) + /* Somebody else just initialized the condvar. */ + free (newcond); } return __pthread_cond_signal (cond->cond); diff --git a/nptl/old_pthread_cond_timedwait.c b/nptl/old_pthread_cond_timedwait.c index 7b0faa78d2..ef4db9e6e8 100644 --- a/nptl/old_pthread_cond_timedwait.c +++ b/nptl/old_pthread_cond_timedwait.c @@ -20,6 +20,7 @@ #include #include #include "pthreadP.h" +#include #include @@ -32,18 +33,19 @@ __pthread_cond_timedwait_2_0 (cond, mutex, abstime) { if (cond->cond == NULL) { - lll_mutex_lock (cond->lock); + pthread_cond_t *newcond; - /* Check whether the condvar is still not allocated. */ - if (cond->cond == NULL) - cond->cond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t)); + newcond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t)); + if (newcond == NULL) + return ENOMEM; - lll_mutex_unlock (cond->lock); + *newcond = (struct pthread_cond_t) PTHREAD_COND_INITIALIZER; - if (cond->cond == NULL) - return ENOMEM; + atomic_write_barrier (); - *cond->cond = (struct pthread_cond_t) PTHREAD_COND_INITIALIZER; + if (atomic_compare_and_exchange_acq (&cond->cond, newcond, NULL) != 0) + /* Somebody else just initialized the condvar. */ + free (newcond); } return __pthread_cond_timedwait (cond->cond, mutex, abstime); diff --git a/nptl/old_pthread_cond_wait.c b/nptl/old_pthread_cond_wait.c index 493f00a3eb..b124b260d4 100644 --- a/nptl/old_pthread_cond_wait.c +++ b/nptl/old_pthread_cond_wait.c @@ -20,6 +20,7 @@ #include #include #include "pthreadP.h" +#include #include @@ -31,18 +32,19 @@ __pthread_cond_wait_2_0 (cond, mutex) { if (cond->cond == NULL) { - lll_mutex_lock (cond->lock); + pthread_cond_t *newcond; - /* Check whether the condvar is still not allocated. */ - if (cond->cond == NULL) - cond->cond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t)); + newcond = (pthread_cond_t *) malloc (sizeof (pthread_cond_t)); + if (newcond == NULL) + return ENOMEM; - lll_mutex_unlock (cond->lock); + *newcond = (struct pthread_cond_t) PTHREAD_COND_INITIALIZER; - if (cond->cond == NULL) - return ENOMEM; + atomic_write_barrier (); - *cond->cond = (struct pthread_cond_t) PTHREAD_COND_INITIALIZER; + if (atomic_compare_and_exchange_acq (&cond->cond, newcond, NULL) != 0) + /* Somebody else just initialized the condvar. */ + free (newcond); } return __pthread_cond_wait (cond->cond, mutex); -- cgit 1.4.1