summaryrefslogtreecommitdiff
path: root/pthread
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@gnu.org>2005-05-02 22:00:34 +0000
committerNeal H. Walfield <neal@gnu.org>2005-05-02 22:00:34 +0000
commit6c7755ebb4718153b144b59f9becbf1b5e785f02 (patch)
tree8ee76a9219839b5ae4f2537fc13a021463c33849 /pthread
parent3f126cc9b3b8fb6f98dd4bdbe4f69f89ec7ab1a4 (diff)
libpthread/
2005-05-02 Neal H. Walfield <neal@gnu.org> * pthread/pt-alloc.c (__pthread_alloc): Set the thread id to the table index plus one. * pthread/pt-internal.h (__pthread_getid): Index __pthread_threads using THREAD - 1, not THREAD. (__pthread_setid): Likewise. * pthread/pt-create.c (__pthread_create_internal): Likewise. * sysdeps/generic/pt-mutex-trylock.c (__pthread_mutex_trylock): When returning EBUSY, don't forget to first unlock MUTEX->__HELD.
Diffstat (limited to 'pthread')
-rw-r--r--pthread/pt-alloc.c14
-rw-r--r--pthread/pt-create.c4
-rw-r--r--pthread/pt-internal.h11
3 files changed, 16 insertions, 13 deletions
diff --git a/pthread/pt-alloc.c b/pthread/pt-alloc.c
index 5cdc85df..e8d3c033 100644
--- a/pthread/pt-alloc.c
+++ b/pthread/pt-alloc.c
@@ -1,5 +1,5 @@
/* Allocate a new thread structure.
- Copyright (C) 2000, 2002 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
@@ -139,10 +139,10 @@ __pthread_alloc (struct __pthread **pthread)
if (__pthread_num_threads < __pthread_max_threads)
{
- /* We have a free slot. Use the slot number as
- the thread ID for the new thread. */
- new->thread = __pthread_num_threads++;
- __pthread_threads[new->thread] = NULL;
+ /* We have a free slot. Use the slot number plus one as the
+ thread ID for the new thread. */
+ new->thread = 1 + __pthread_num_threads++;
+ __pthread_threads[new->thread - 1] = NULL;
pthread_rwlock_unlock (&__pthread_threads_lock);
@@ -203,8 +203,8 @@ __pthread_alloc (struct __pthread **pthread)
__pthread_threads = threads;
/* And allocate ourselves one of the newly created slots. */
- new->thread = __pthread_num_threads++;
- __pthread_threads[new->thread] = NULL;
+ new->thread = 1 + __pthread_num_threads++;
+ __pthread_threads[new->thread - 1] = NULL;
pthread_rwlock_unlock (&__pthread_threads_lock);
diff --git a/pthread/pt-create.c b/pthread/pt-create.c
index 0295a0af..cf5b32d8 100644
--- a/pthread/pt-create.c
+++ b/pthread/pt-create.c
@@ -1,5 +1,5 @@
/* Thread creation.
- Copyright (C) 2000, 2002 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
@@ -168,7 +168,7 @@ __pthread_create_internal (struct __pthread **thread,
other thread should be using this entry (we also assume that the
store is atomic). */
pthread_rwlock_rdlock (&__pthread_threads_lock);
- __pthread_threads[pthread->thread] = pthread;
+ __pthread_threads[pthread->thread - 1] = pthread;
pthread_rwlock_unlock (&__pthread_threads_lock);
/* At this point it is possible to guess our pthread ID. We have to
diff --git a/pthread/pt-internal.h b/pthread/pt-internal.h
index a32345c4..75631db0 100644
--- a/pthread/pt-internal.h
+++ b/pthread/pt-internal.h
@@ -1,5 +1,5 @@
/* Internal defenitions for pthreads library.
- Copyright (C) 2000 Free Software Foundation, Inc.
+ Copyright (C) 2000, 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
@@ -134,20 +134,23 @@ extern int __pthread_num_threads;
/* Concurrency hint. */
extern int __pthread_concurrency;
-/* Array of __pthread structures and its lock. */
+/* Array of __pthread structures and its lock. Indexed by the pthread
+ id minus one. (Why not just use the pthread id? Because some
+ brain-dead users of the pthread interface incorrectly assume that 0
+ is an invalid pthread id.) */
extern struct __pthread **__pthread_threads;
extern pthread_rwlock_t __pthread_threads_lock;
#define __pthread_getid(thread) \
({ struct __pthread *__t; \
pthread_rwlock_rdlock (&__pthread_threads_lock); \
- __t = __pthread_threads[thread]; \
+ __t = __pthread_threads[thread - 1]; \
pthread_rwlock_unlock (&__pthread_threads_lock); \
__t; })
#define __pthread_setid(thread, pthread) \
pthread_rwlock_wrlock (&__pthread_threads_lock); \
- __pthread_threads[thread] = pthread; \
+ __pthread_threads[thread - 1] = pthread; \
pthread_rwlock_unlock (&__pthread_threads_lock);
/* Similar to pthread_self, but returns the thread descriptor instead