diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2018-03-19 00:47:53 +0100 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2018-03-19 00:47:53 +0100 |
commit | 1efaba2cd9eb0c5af4617c5be01a6b5e96d7d8a0 (patch) | |
tree | 02c0f399da54477fb9d042d28ca009ed8aca6f84 | |
parent | 332c0bf4bca963ee6f104634349546864ecf62e5 (diff) |
Remove bits/pt-atomic.h
* pthread/pt-create.c: Include <atomic.h> instead of <bits/pt-atomic.h>.
(__pthread_total): Change type from __atomic_t to unsigned int.
(__pthread_create_internal): Use atomic_increment and atomic_decrement
instead of __atomic_inc and __atomic_dec.
* pthread/pt-dealloc.c: Include <atomic.h> instead of
<bits/pt-atomic.h>.
(__pthread_dealloc): Use atomic_decrement_and_test instead of
__atomic_dec_and_test.
* pthread/pt-exit.c: Include <atomic.h> instead of <bits/pt-atomic.h>.
(__pthread_exit): Use atomic_decrement_and_test instead of
__atomic_dec_and_test.
* pthread/pt-internal.h: Include <atomic.h> instead of
<bits/pt-atomic.h>.
(struct __pthread): Use unsigned int type for nr_refs field instead of
__atomic_t.
(__pthread_total): Use unsigned int type instead of nr_refs.
-rw-r--r-- | pthread/pt-create.c | 8 | ||||
-rw-r--r-- | pthread/pt-dealloc.c | 4 | ||||
-rw-r--r-- | pthread/pt-exit.c | 4 | ||||
-rw-r--r-- | pthread/pt-internal.h | 6 | ||||
-rw-r--r-- | sysdeps/i386/bits/pt-atomic.h | 65 |
5 files changed, 11 insertions, 76 deletions
diff --git a/pthread/pt-create.c b/pthread/pt-create.c index 5ac01c7..cf226cc 100644 --- a/pthread/pt-create.c +++ b/pthread/pt-create.c @@ -22,7 +22,7 @@ #include <signal.h> #include <resolv.h> -#include <bits/pt-atomic.h> +#include <atomic.h> #include <hurd/resource.h> #include <pt-internal.h> @@ -37,7 +37,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; +unsigned int __pthread_total; /* The entry-point for new threads. */ @@ -195,7 +195,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 @@ -226,7 +226,7 @@ __pthread_create_internal (struct __pthread **thread, __pthread_dealloc (pthread); __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 806e078..1807a1d 100644 --- a/pthread/pt-dealloc.c +++ b/pthread/pt-dealloc.c @@ -22,7 +22,7 @@ #include <pt-internal.h> -#include <bits/pt-atomic.h> +#include <atomic.h> /* List of thread structures corresponding to free thread IDs. */ extern struct __pthread *__pthread_free_threads; @@ -35,7 +35,7 @@ __pthread_dealloc (struct __pthread *pthread) { assert (pthread->state != PTHREAD_TERMINATED); - if (! __atomic_dec_and_test (&pthread->nr_refs)) + if (! atomic_decrement_and_test (&pthread->nr_refs)) return; /* Withdraw this thread from the thread ID lookup table. */ diff --git a/pthread/pt-exit.c b/pthread/pt-exit.c index a23a540..14e560e 100644 --- a/pthread/pt-exit.c +++ b/pthread/pt-exit.c @@ -23,7 +23,7 @@ #include <pt-internal.h> -#include <bits/pt-atomic.h> +#include <atomic.h> /* Terminate the current thread and make STATUS available to any @@ -49,7 +49,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 3024e64..24111ad 100644 --- a/pthread/pt-internal.h +++ b/pthread/pt-internal.h @@ -26,7 +26,7 @@ #include <assert.h> #include <bits/types/res_state.h> -#include <bits/pt-atomic.h> +#include <atomic.h> #include <pt-key.h> @@ -76,7 +76,7 @@ struct __pthread /* Thread ID. */ pthread_t thread; - __atomic_t nr_refs; /* Detached threads have a self reference only, + unsigned int nr_refs; /* Detached threads have a self reference only, while joinable threads have two references. These are used to keep the structure valid at thread destruction. Detaching/joining a thread @@ -171,7 +171,7 @@ __pthread_dequeue (struct __pthread *thread) ) /* The total number of threads currently active. */ -extern __atomic_t __pthread_total; +extern unsigned int __pthread_total; /* The total number of thread IDs currently in use, or on the list of available thread IDs. */ diff --git a/sysdeps/i386/bits/pt-atomic.h b/sysdeps/i386/bits/pt-atomic.h deleted file mode 100644 index fe5ded5..0000000 --- a/sysdeps/i386/bits/pt-atomic.h +++ /dev/null @@ -1,65 +0,0 @@ -/* Atomic operations. i386 version. - Copyright (C) 2000-2018 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, see <http://www.gnu.org/licenses/>. */ - -#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 |