/* It may not be safe to allocate when we register the first thread. */
static struct GC_Thread_Rep first_thread;
+#define THREAD_TABLE_INDEX(id) \
+ (int)(((NUMERIC_THREAD_ID(id) >> 16) \
+ ^ (NUMERIC_THREAD_ID(id) >> 8) \
+ ^ NUMERIC_THREAD_ID(id)) % THREAD_TABLE_SZ)
+
/* Add a thread to GC_threads. We assume it wasn't already there. */
/* Caller holds allocation lock. */
STATIC GC_thread GC_new_thread(pthread_t id)
{
- int hv = NUMERIC_THREAD_ID(id) % THREAD_TABLE_SZ;
+ int hv = THREAD_TABLE_INDEX(id);
GC_thread result;
static GC_bool first_thread_used = FALSE;
+
# ifdef DEBUG_THREADS
GC_log_printf("Creating thread %p\n", (void *)id);
# endif
-
GC_ASSERT(I_HOLD_LOCK());
if (!EXPECT(first_thread_used, TRUE)) {
result = &first_thread;
/* It is safe to delete the main thread. */
STATIC void GC_delete_thread(pthread_t id)
{
- int hv = NUMERIC_THREAD_ID(id) % THREAD_TABLE_SZ;
+ int hv = THREAD_TABLE_INDEX(id);
register GC_thread p = GC_threads[hv];
register GC_thread prev = 0;
STATIC void GC_delete_gc_thread(GC_thread t)
{
pthread_t id = t -> id;
- int hv = NUMERIC_THREAD_ID(id) % THREAD_TABLE_SZ;
+ int hv = THREAD_TABLE_INDEX(id);
register GC_thread p = GC_threads[hv];
register GC_thread prev = 0;
/* return the most recent one. */
GC_INNER GC_thread GC_lookup_thread(pthread_t id)
{
- int hv = NUMERIC_THREAD_ID(id) % THREAD_TABLE_SZ;
- register GC_thread p = GC_threads[hv];
+ GC_thread p = GC_threads[THREAD_TABLE_INDEX(id)];
while (p != 0 && !THREAD_EQUAL(p -> id, id)) p = p -> next;
return(p);
# define THREAD_TABLE_SZ 256 /* Power of 2 (for speed). */
#endif
#define THREAD_TABLE_INDEX(id) /* id is of DWORD type */ \
- (int)(((id) >> 2) % THREAD_TABLE_SZ)
+ (int)((((id) >> 8) ^ (id)) % THREAD_TABLE_SZ)
STATIC GC_thread GC_threads[THREAD_TABLE_SZ];
/* It may not be safe to allocate when we register the first thread. */
/* else */ {
/* We first try the cache. If that fails, we use a very slow */
/* approach. */
- int hv_guess = THREAD_TABLE_INDEX(GET_PTHREAD_MAP_CACHE(id));
+ DWORD win32_id = GET_PTHREAD_MAP_CACHE(id);
+ int hv_guess = THREAD_TABLE_INDEX(win32_id);
int hv;
GC_thread p;
DCL_LOCK_STATE;