summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@gnu.org>2008-08-12 15:07:50 +0000
committerThomas Schwinge <tschwinge@gnu.org>2009-04-07 23:52:49 +0200
commitbd70818a914257c32ca47623206632ed4a484802 (patch)
treed71c01aee86e32e3aafc43d75225c0576223c90f
parent63dd6dd8f1d546d0b180fc4baf1e1fbd32deaa4d (diff)
2008-08-12 Neal H. Walfield <neal@gnu.org>
Merge changes from hurd-l4 fork. * Makefile (SRCS): Add pt-startup.c and pt-mutex-transfer-np.c. (sysdeps_headers): Add pthread-np.h. 2008-08-12 Neal H. Walfield <neal@gnu.org> * sysdeps/generic/bits/pthread-np.h: New file. 2008-08-12 Neal H. Walfield <neal@gnu.org> * sysdeps/generic/pt-startup.c: New file. 2008-08-12 Neal H. Walfield <neal@gnu.org> * sysdeps/generic/bits/mutex.h (__PTHREAD_RECURSIVE_MUTEX_INITIALIZER): Define. (__PTHREAD_MUTEX_RECURSIVE_INITIALIZER): Don't define. * include/pthread/pthread.h (PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) [__USE_GNU]: Define. (PTHREAD_MUTEX_RECURSIVE_INITIALIZER_NP): Don't define. 2008-08-12 Neal H. Walfield <neal@gnu.org> * include/pthread/pthread.h: Include <sys/cdefs.h>. (__extern_inline): If not defined, define appropriately. 2008-06-01 Neal H. Walfield <neal@gnu.org> * include/pthread/pthread.h (PTHREAD_MUTEX_RECURSIVE_INITIALIZER_NP): New definition. * sysdeps/generic/bits/mutex.h (__PTHREAD_MUTEX_RECURSIVE_INITIALIZER): New definition. * sysdeps/generic/bits/mutex-attr.h (__pthread_recursive_mutexattr): New definition. * sysdeps/generic/pt-mutexattr.c (__pthread_recursive_mutexattr): New declaration. * sysdeps/generic/pt-mutex-init.c (_pthread_mutex_init): If ATTR is &__PTHREAD_RECURSIVE_MUTEXATTR, don't allocate a copy, just save in MUTEX->ATTR. * sysdeps/generic/pt-mutex-destroy.c (_pthread_mutex_destroy): If MUTEX->ATTR is &__PTHREAD_RECURSIVE_MUTEXATTR, don't free it. 2008-05-29 Thomas Schwinge <tschwinge@gnu.org> * sysdeps/generic/sem-timedwait.c: Don't include <error.h>. 2008-05-21 Neal H. Walfield <neal@gnu.org> * include/pthread/pthread.h: Include <bits/pthread-np.h>. 2008-03-01 Neal H. Walfield <neal@gnu.org> * sysdeps/generic/pt-mutex-transfer-np.c: New file. * pthread/pt-self.c (pthread_self): Assert that SELF is not NULL. 2007-12-23 Neal H. Walfield <neal@gnu.org> * pthread/pt-join.c (pthread_join): Cast argument to pthread_cleanup_push to avoid warning. 2007-11-23 Neal H. Walfield <neal@gnu.org> * pthread/pt-internal.h (__pthread_startup): Add declaration. * pthread/pt-create.c (entry_point): Call __pthread_startup.
-rw-r--r--pthread/pt-alloc.c18
-rw-r--r--pthread/pt-create.c8
-rw-r--r--pthread/pt-dealloc.c12
-rw-r--r--pthread/pt-exit.c4
-rw-r--r--pthread/pt-internal.h12
-rw-r--r--sysdeps/generic/pt-mutex-unlock.c7
-rw-r--r--sysdeps/hurd/pt-setspecific.c5
-rw-r--r--sysdeps/ia32/bits/atomic.h66
-rw-r--r--sysdeps/posix/pt-spin.c2
9 files changed, 90 insertions, 44 deletions
diff --git a/pthread/pt-alloc.c b/pthread/pt-alloc.c
index 6cf9106b..30dcede0 100644
--- a/pthread/pt-alloc.c
+++ b/pthread/pt-alloc.c
@@ -1,5 +1,5 @@
/* Allocate a new thread structure.
- Copyright (C) 2000, 2002, 2005, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2002, 2005 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
@@ -25,7 +25,7 @@
#include <pt-internal.h>
-#include <atomic.h>
+#include <bits/atomic.h>
/* This braindamage is necessary because the standard says that some
of the threads functions "shall fail" if "No thread could be found
@@ -46,7 +46,7 @@ pthread_rwlock_t __pthread_threads_lock;
/* List of thread structures corresponding to free thread IDs. */
-atomicptr_t __pthread_free_threads;
+__atomicptr_t __pthread_free_threads;
static inline error_t
initialize_pthread (struct __pthread *new, int recycling)
@@ -97,10 +97,8 @@ __pthread_alloc (struct __pthread **pthread)
/* Try to re-use a thread structure before creating a new one. */
while ((new = (struct __pthread *)__pthread_free_threads))
{
- if (atomic_compare_and_exchange_val_acq (&__pthread_free_threads,
- (uintptr_t) new->next,
- (uintptr_t) new)
- == (uintptr_t) new)
+ if (__atomicptr_compare_and_swap (&__pthread_free_threads,
+ new, new->next))
{
/* Yes, we managed to get one. The thread number in the
thread structure still refers to the correct slot. */
@@ -112,10 +110,8 @@ __pthread_alloc (struct __pthread **pthread)
while (1)
{
new->next = (struct __pthread *)__pthread_free_threads;
- if (atomic_compare_and_exchange_val_acq
- (&__pthread_free_threads,
- (uintptr_t) new, (uintptr_t) new->next)
- == (uintptr_t) new->next)
+ if (__atomicptr_compare_and_swap (&__pthread_free_threads,
+ new->next, new))
break;
}
diff --git a/pthread/pt-create.c b/pthread/pt-create.c
index 5bb9f1f9..210f9672 100644
--- a/pthread/pt-create.c
+++ b/pthread/pt-create.c
@@ -22,7 +22,7 @@
#include <pthread.h>
#include <signal.h>
-#include <atomic.h>
+#include <bits/atomic.h>
#include <pt-internal.h>
@@ -33,7 +33,7 @@
/* The total number of pthreads currently active. This is defined
here since it would be really stupid to have a threads-using
program that doesn't call `pthread_create'. */
-atomic_fast32_t __pthread_total;
+__atomic_t __pthread_total;
/* The entry-point for new threads. */
@@ -163,7 +163,7 @@ __pthread_create_internal (struct __pthread **thread,
the number of threads from within the new thread isn't an option
since this thread might return and call `pthread_exit' before the
new thread runs. */
- atomic_increment (&__pthread_total);
+ __atomic_inc (&__pthread_total);
/* Store a pointer to this thread in the thread ID lookup table. We
could use __thread_setid, however, we only lock for reading as no
@@ -190,7 +190,7 @@ __pthread_create_internal (struct __pthread **thread,
failed_starting:
__pthread_setid (pthread->thread, NULL);
- atomic_decrement (&__pthread_total);
+ __atomic_dec (&__pthread_total);
failed_sigstate:
__pthread_sigstate_destroy (pthread);
failed_setup:
diff --git a/pthread/pt-dealloc.c b/pthread/pt-dealloc.c
index 879608b9..1fc7a7b3 100644
--- a/pthread/pt-dealloc.c
+++ b/pthread/pt-dealloc.c
@@ -23,10 +23,10 @@
#include <pt-internal.h>
-#include <atomic.h>
+#include <bits/atomic.h>
/* List of thread structures corresponding to free thread IDs. */
-extern atomicptr_t __pthread_free_threads;
+extern __atomicptr_t __pthread_free_threads;
/* Deallocate the thread structure for PTHREAD and the resources
associated with it. */
@@ -54,11 +54,9 @@ __pthread_dealloc (struct __pthread *pthread)
while (1)
{
pthread->next = (struct __pthread *)__pthread_free_threads;
- if (atomic_compare_and_exchange_val_acq (&__pthread_free_threads,
- (uintptr_t) pthread,
- (uintptr_t) pthread->next)
- == (uintptr_t) pthread->next)
- break;
+ if (__atomicptr_compare_and_swap (&__pthread_free_threads,
+ pthread->next, pthread))
+ return;
}
/* NOTREACHED */
diff --git a/pthread/pt-exit.c b/pthread/pt-exit.c
index a8f85b1a..7484ffd1 100644
--- a/pthread/pt-exit.c
+++ b/pthread/pt-exit.c
@@ -24,7 +24,7 @@
#include <pt-internal.h>
-#include <atomic.h>
+#include <bits/atomic.h>
/* Terminate the current thread and make STATUS available to any
@@ -57,7 +57,7 @@ pthread_exit (void *status)
/* Decrease the number of threads. We use an atomic operation to
make sure that only the last thread calls `exit'. */
- if (atomic_decrement_and_test (&__pthread_total))
+ if (__atomic_dec_and_test (&__pthread_total))
/* We are the last thread. */
exit (0);
diff --git a/pthread/pt-internal.h b/pthread/pt-internal.h
index 9eb84ed1..0fd7920f 100644
--- a/pthread/pt-internal.h
+++ b/pthread/pt-internal.h
@@ -26,15 +26,13 @@
#include <signal.h>
#include <assert.h>
-#include <atomic.h>
+#include <bits/atomic.h>
#include <pt-key.h>
#include <pt-sysdep.h>
#include <pt-machdep.h>
-#include <sig-internal.h>
-
/* Thread state. */
enum pthread_state
{
@@ -52,10 +50,6 @@ enum pthread_state
# define PTHREAD_SYSDEP_MEMBERS
#endif
-#ifndef PTHREAD_SIGNAL_MEMBERS
-# define PTHREAD_SIGNAL_MEMBERS
-#endif
-
/* This structure describes a POSIX thread. */
struct __pthread
{
@@ -91,8 +85,6 @@ struct __pthread
PTHREAD_SYSDEP_MEMBERS
- PTHREAD_SIGNAL_MEMBERS
-
struct __pthread *next, **prevp;
};
@@ -140,7 +132,7 @@ __pthread_dequeue (struct __pthread *thread)
)
/* The total number of threads currently active. */
-extern atomic_fast32_t __pthread_total;
+extern __atomic_t __pthread_total;
/* The total number of thread IDs currently in use, or on the list of
available thread IDs. */
diff --git a/sysdeps/generic/pt-mutex-unlock.c b/sysdeps/generic/pt-mutex-unlock.c
index d2a42570..492dfcb5 100644
--- a/sysdeps/generic/pt-mutex-unlock.c
+++ b/sysdeps/generic/pt-mutex-unlock.c
@@ -37,12 +37,7 @@ __pthread_mutex_unlock (pthread_mutex_t *mutex)
if (_pthread_self ())
{
assert (mutex->owner);
- assertx (mutex->owner == _pthread_self (),
- "%p(%x) != %p(%x)",
- mutex->owner,
- ((struct __pthread *) mutex->owner)->threadid,
- _pthread_self (),
- _pthread_self ()->threadid);
+ assert (mutex->owner == _pthread_self ());
mutex->owner = NULL;
}
#endif
diff --git a/sysdeps/hurd/pt-setspecific.c b/sysdeps/hurd/pt-setspecific.c
index d2d1157c..89ca4d7f 100644
--- a/sysdeps/hurd/pt-setspecific.c
+++ b/sysdeps/hurd/pt-setspecific.c
@@ -1,5 +1,5 @@
/* pthread_setspecific. Generic version.
- Copyright (C) 2002, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2002 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
@@ -30,8 +30,7 @@ pthread_setspecific (pthread_key_t key, const void *value)
if (! self->thread_specifics)
{
- err = hurd_ihash_create (&self->thread_specifics, false,
- HURD_IHASH_NO_LOCP);
+ err = hurd_ihash_create (&self->thread_specifics, HURD_IHASH_NO_LOCP);
if (err)
return ENOMEM;
}
diff --git a/sysdeps/ia32/bits/atomic.h b/sysdeps/ia32/bits/atomic.h
new file mode 100644
index 00000000..0dfc1f60
--- /dev/null
+++ b/sysdeps/ia32/bits/atomic.h
@@ -0,0 +1,66 @@
+/* Atomic operations. i386 version.
+ Copyright (C) 2000 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
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _BITS_ATOMIC_H
+#define _BITS_ATOMIC_H 1
+
+typedef __volatile int __atomic_t;
+
+static inline void
+__atomic_inc (__atomic_t *__var)
+{
+ __asm__ __volatile ("lock; incl %0" : "=m" (*__var) : "m" (*__var));
+}
+
+static inline void
+__atomic_dec (__atomic_t *__var)
+{
+ __asm__ __volatile ("lock; decl %0" : "=m" (*__var) : "m" (*__var));
+}
+
+static inline int
+__atomic_dec_and_test (__atomic_t *__var)
+{
+ unsigned char __ret;
+
+ __asm__ __volatile ("lock; decl %0; sete %1"
+ : "=m" (*__var), "=qm" (__ret) : "m" (*__var));
+ return __ret != 0;
+}
+
+/* We assume that an __atomicptr_t is only used for pointers to
+ word-aligned objects, and use the lowest bit for a simple lock. */
+typedef __volatile int * __atomicptr_t;
+
+/* Actually we don't implement that yet, and assume that we run on
+ something that has the i486 instruction set. */
+static inline int
+__atomicptr_compare_and_swap (__atomicptr_t *__ptr, void *__oldval,
+ void * __newval)
+{
+ char __ret;
+ int __dummy;
+
+ __asm__ __volatile ("lock; cmpxchgl %3, %1; sete %0"
+ : "=q" (__ret), "=m" (*__ptr), "=a" (__dummy)
+ : "r" (__newval), "m" (*__ptr), "a" (__oldval));
+ return __ret;
+}
+
+#endif
diff --git a/sysdeps/posix/pt-spin.c b/sysdeps/posix/pt-spin.c
index 26793b08..cb809c64 100644
--- a/sysdeps/posix/pt-spin.c
+++ b/sysdeps/posix/pt-spin.c
@@ -1,5 +1,5 @@
/* Spin locks.
- Copyright (C) 2000, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2004, 2005 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