Skip to content
Snippets Groups Projects
Commit d213275f authored by Fredrik Hübinette (Hubbe)'s avatar Fredrik Hübinette (Hubbe)
Browse files

new thread stuff: th_hash & th_equal

Rev: src/threads.c:1.58
Rev: src/threads.h:1.33
parent ea5c9eae
No related branches found
No related tags found
No related merge requests found
#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
......
......@@ -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 */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment