From 492c73cf1f1b3e35b394aec991d1201726ec606d Mon Sep 17 00:00:00 2001 From: rpj Date: Tue, 21 Jul 1998 17:04:38 +0000 Subject: Wed Jul 22 00:16:22 1998 Ross Johnson * cleanup.c (_pthread_cleanup_push): Implement. (_pthread_cleanup_pop): Implement. (_pthread_do_cancellation): Implement. These are private to the implementation. The real cleanup functions are macros. See below. * pthread.h (pthread_cleanup_push): Implement as a macro. (pthread_cleanup_pop): Implement as a macro. Because these are macros which start and end a block, the POSIX scoping requirement is observed. See the comment in the file. * exit.c (pthread_exit): Refine the code. * create.c (pthread_create): Code cleanup. * implement.h (RND_SIZEOF): Add RND_SIZEOF(T) to round sizeof(T) up to multiple of DWORD. Add function prototypes. * private.c (_pthread_getthreadindex): "*thread" should have been "thread". Detect empty slot fail condition. --- private.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'private.c') 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; -- cgit v1.2.3