From d213275f9a14e5f311453980d9215a548402e419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net> Date: Sat, 28 Feb 1998 19:33:50 -0800 Subject: [PATCH] new thread stuff: th_hash & th_equal Rev: src/threads.c:1.58 Rev: src/threads.h:1.33 --- src/threads.c | 17 +++++++++++------ src/threads.h | 12 ++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/threads.c b/src/threads.c index 0ccd6462aa..ce12dfa49c 100644 --- a/src/threads.c +++ b/src/threads.c @@ -1,5 +1,5 @@ #include "global.h" -RCSID("$Id: threads.c,v 1.57 1998/02/27 20:09:04 marcus Exp $"); +RCSID("$Id: threads.c,v 1.58 1998/03/01 03:33:50 hubbe Exp $"); int num_threads = 1; int threads_disabled = 0; @@ -168,7 +168,7 @@ void thread_table_init() unsigned INT32 thread_table_hash(THREAD_T *tid) { - return hashmem((unsigned char *)tid, sizeof(*tid), 16) % THREAD_TABLE_SIZE; + return th_hash(*tid) % THREAD_TABLE_SIZE; } void thread_table_insert(struct object *o) @@ -198,13 +198,18 @@ struct thread_state *thread_state_for_id(THREAD_T tid) unsigned INT32 h = thread_table_hash(&tid); struct thread_state *s = NULL; mt_lock( & thread_table_lock ); - if(thread_table_chains[h] == NULL) { + if(thread_table_chains[h] == NULL) + { /* NULL result */ - } else if((s=thread_table_chains[h])->id == tid) { + } + else if(th_equal((s=thread_table_chains[h])->id, tid)) + { /* Quick return */ - } else { + } + else + { while((s = s->hashlink) != NULL) - if(s->id == tid) + if(th_equal(s->id, tid)) break; if(s != NULL) { /* Move the thread_state to the head of the chain, in case diff --git a/src/threads.h b/src/threads.h index 35d4830cef..d315955b9c 100644 --- a/src/threads.h +++ b/src/threads.h @@ -150,6 +150,8 @@ extern pthread_attr_t small_pattr; #define th_exit(X) exit(X) #define th_self() getpid() #define th_yield() sginap(0) +#define th_equal(X,Y) ((X)==(Y)) +#define th_hash(X) ((unsigned INT32)(X)) /* * No cond_vars yet @@ -170,6 +172,8 @@ extern pthread_attr_t small_pattr; #define th_self() GetCurrentThread() #define th_destroy(X) #define th_yield() Sleep(0) +#define th_equal(X,Y) ((X)==(Y)) +#define th_hash(X) ((unsigned INT32)(X)) #define MUTEX_T HANDLE #define mt_init(X) CheckValidHandle((*(X)=CreateMutex(NULL, 0, NULL))) @@ -250,6 +254,14 @@ struct thread_state { #define th_yield() #endif +#ifndef th_equal +#define th_equal(X,Y) (!MEMCPY(&(X),&(Y),sizeof(THREAD_T))) +#endif + +#ifndef th_hash +#define th_hash(X) hashmem(&(X),sizeof(THREAD_T), 16) +#endif + /* Define to get a debug-trace of some of the threads operations. */ /* #define VERBOSE_THREADS_DEBUG */ -- GitLab