summaryrefslogtreecommitdiff
path: root/pthread
diff options
context:
space:
mode:
Diffstat (limited to 'pthread')
-rw-r--r--pthread/pt-alloc.c18
-rw-r--r--pthread/pt-create.c12
-rw-r--r--pthread/pt-dealloc.c12
-rw-r--r--pthread/pt-exit.c4
-rw-r--r--pthread/pt-internal.h16
-rw-r--r--pthread/pt-join.c3
-rw-r--r--pthread/pt-self.c7
7 files changed, 48 insertions, 24 deletions
diff --git a/pthread/pt-alloc.c b/pthread/pt-alloc.c
index 30dcede..6cf9106 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 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2002, 2005, 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
@@ -25,7 +25,7 @@
#include <pt-internal.h>
-#include <bits/atomic.h>
+#include <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,8 +97,10 @@ __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 (__atomicptr_compare_and_swap (&__pthread_free_threads,
- new, new->next))
+ if (atomic_compare_and_exchange_val_acq (&__pthread_free_threads,
+ (uintptr_t) new->next,
+ (uintptr_t) new)
+ == (uintptr_t) new)
{
/* Yes, we managed to get one. The thread number in the
thread structure still refers to the correct slot. */
@@ -110,8 +112,10 @@ __pthread_alloc (struct __pthread **pthread)
while (1)
{
new->next = (struct __pthread *)__pthread_free_threads;
- if (__atomicptr_compare_and_swap (&__pthread_free_threads,
- new->next, new))
+ if (atomic_compare_and_exchange_val_acq
+ (&__pthread_free_threads,
+ (uintptr_t) new, (uintptr_t) new->next)
+ == (uintptr_t) new->next)
break;
}
diff --git a/pthread/pt-create.c b/pthread/pt-create.c
index bad5d83..5bb9f1f 100644
--- a/pthread/pt-create.c
+++ b/pthread/pt-create.c
@@ -1,5 +1,5 @@
/* Thread creation.
- Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2002, 2005, 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
@@ -22,7 +22,7 @@
#include <pthread.h>
#include <signal.h>
-#include <bits/atomic.h>
+#include <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_t __pthread_total;
+atomic_fast32_t __pthread_total;
/* The entry-point for new threads. */
@@ -45,6 +45,8 @@ entry_point (void *(*start_routine)(void *), void *arg)
uselocale (LC_GLOBAL_LOCALE);
#endif
+ __pthread_startup ();
+
pthread_exit (start_routine (arg));
}
@@ -161,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_inc (&__pthread_total);
+ atomic_increment (&__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
@@ -188,7 +190,7 @@ __pthread_create_internal (struct __pthread **thread,
failed_starting:
__pthread_setid (pthread->thread, NULL);
- __atomic_dec (&__pthread_total);
+ atomic_decrement (&__pthread_total);
failed_sigstate:
__pthread_sigstate_destroy (pthread);
failed_setup:
diff --git a/pthread/pt-dealloc.c b/pthread/pt-dealloc.c
index 1fc7a7b..879608b 100644
--- a/pthread/pt-dealloc.c
+++ b/pthread/pt-dealloc.c
@@ -23,10 +23,10 @@
#include <pt-internal.h>
-#include <bits/atomic.h>
+#include <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,9 +54,11 @@ __pthread_dealloc (struct __pthread *pthread)
while (1)
{
pthread->next = (struct __pthread *)__pthread_free_threads;
- if (__atomicptr_compare_and_swap (&__pthread_free_threads,
- pthread->next, pthread))
- return;
+ if (atomic_compare_and_exchange_val_acq (&__pthread_free_threads,
+ (uintptr_t) pthread,
+ (uintptr_t) pthread->next)
+ == (uintptr_t) pthread->next)
+ break;
}
/* NOTREACHED */
diff --git a/pthread/pt-exit.c b/pthread/pt-exit.c
index 7484ffd..a8f85b1 100644
--- a/pthread/pt-exit.c
+++ b/pthread/pt-exit.c
@@ -24,7 +24,7 @@
#include <pt-internal.h>
-#include <bits/atomic.h>
+#include <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_dec_and_test (&__pthread_total))
+ if (atomic_decrement_and_test (&__pthread_total))
/* We are the last thread. */
exit (0);
diff --git a/pthread/pt-internal.h b/pthread/pt-internal.h
index e7c85fd..9eb84ed 100644
--- a/pthread/pt-internal.h
+++ b/pthread/pt-internal.h
@@ -26,13 +26,15 @@
#include <signal.h>
#include <assert.h>
-#include <bits/atomic.h>
+#include <atomic.h>
#include <pt-key.h>
#include <pt-sysdep.h>
#include <pt-machdep.h>
+#include <sig-internal.h>
+
/* Thread state. */
enum pthread_state
{
@@ -50,6 +52,10 @@ 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
{
@@ -85,6 +91,8 @@ struct __pthread
PTHREAD_SYSDEP_MEMBERS
+ PTHREAD_SIGNAL_MEMBERS
+
struct __pthread *next, **prevp;
};
@@ -132,7 +140,7 @@ __pthread_dequeue (struct __pthread *thread)
)
/* The total number of threads currently active. */
-extern __atomic_t __pthread_total;
+extern atomic_fast32_t __pthread_total;
/* The total number of thread IDs currently in use, or on the list of
available thread IDs. */
@@ -225,6 +233,10 @@ extern void __pthread_thread_halt (struct __pthread *thread,
int need_dealloc);
+/* Called by a thread just before it calls the provided start
+ routine. */
+extern void __pthread_startup (void);
+
/* Block THREAD. */
extern void __pthread_block (struct __pthread *thread);
diff --git a/pthread/pt-join.c b/pthread/pt-join.c
index 698b6c9..06e9f1f 100644
--- a/pthread/pt-join.c
+++ b/pthread/pt-join.c
@@ -37,7 +37,8 @@ pthread_join (pthread_t thread, void **status)
return ESRCH;
__pthread_mutex_lock (&pthread->state_lock);
- pthread_cleanup_push (__pthread_mutex_unlock, &pthread->state_lock);
+ pthread_cleanup_push ((void (*)(void *)) __pthread_mutex_unlock,
+ &pthread->state_lock);
while (pthread->state == PTHREAD_JOINABLE)
pthread_cond_wait (&pthread->state_cond, &pthread->state_lock);
diff --git a/pthread/pt-self.c b/pthread/pt-self.c
index e14fe1e..4976864 100644
--- a/pthread/pt-self.c
+++ b/pthread/pt-self.c
@@ -1,5 +1,5 @@
/* Get calling thread's ID.
- Copyright (C) 2000 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2008 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,5 +25,8 @@
pthread_t
pthread_self (void)
{
- return _pthread_self()->thread;
+ struct __pthread *self = _pthread_self ();
+ assert (self);
+
+ return self->thread;
}