summaryrefslogtreecommitdiff
path: root/private.c
diff options
context:
space:
mode:
Diffstat (limited to 'private.c')
-rw-r--r--private.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/private.c b/private.c
index a880042..9499e07 100644
--- a/private.c
+++ b/private.c
@@ -17,7 +17,8 @@ _pthread_getthreadindex(pthread_t thread)
/* The hash table works as follows:
hash into the table,
if the thread in this slot doesn't match then start single
- stepping from there until we find it.
+ stepping from there until we find it, or we hit an empty slot, or
+ we end up where we started from.
The scheme should have these characteristics:
- if the thread handle is a sequence number then the hash will
@@ -25,14 +26,16 @@ _pthread_getthreadindex(pthread_t thread)
- if the thread handle is a pseudo randomish value (eg. a pointer)
then the hash should succeed first time most times.
*/
- int t = _PTHREAD_HASH_INDEX(*thread);
- int it = t; /* The initial thread index */
+ int t = _PTHREAD_HASH_INDEX(thread);
+ int it = t; /* Remember where we started from. */
while ((_pthread_threads_table[t])->thread != thread) {
t++;
+
if (t == PTHREAD_THREADS_MAX)
t = 0; /* Wrap around to the first slot */
- if (t == it)
+
+ if ((_pthread_threads_table[t])->thread == NULL || t == it)
return -1; /* Failed to find the thread */
}
return t;