From: Ivan Maidanski Date: Mon, 26 Mar 2018 18:30:32 +0000 (+0300) Subject: Reduce probability of collision in threads hashtable for 64-bit targets X-Git-Tag: v8.0.0~272 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=553ed5607385e85f30aefe8d60b737b5c232439c;p=gc Reduce probability of collision in threads hashtable for 64-bit targets * include/private/pthread_support.h [GC_PTHREADS && !GC_WIN32_THREADS && CPP_WORDSZ==64] (THREAD_TABLE_INDEX): Xor also 4th byte of id value. --- diff --git a/include/private/pthread_support.h b/include/private/pthread_support.h index 8df6bc21..ae5c2e9e 100644 --- a/include/private/pthread_support.h +++ b/include/private/pthread_support.h @@ -140,10 +140,17 @@ typedef struct GC_Thread_Rep { # define THREAD_TABLE_SZ 256 /* Power of 2 (for speed). */ #endif -#define THREAD_TABLE_INDEX(id) \ +#if CPP_WORDSZ == 64 +# define THREAD_TABLE_INDEX(id) \ + (int)(((((NUMERIC_THREAD_ID(id) >> 8) ^ NUMERIC_THREAD_ID(id)) >> 16) \ + ^ ((NUMERIC_THREAD_ID(id) >> 8) ^ NUMERIC_THREAD_ID(id))) \ + % THREAD_TABLE_SZ) +#else +# define THREAD_TABLE_INDEX(id) \ (int)(((NUMERIC_THREAD_ID(id) >> 16) \ ^ (NUMERIC_THREAD_ID(id) >> 8) \ ^ NUMERIC_THREAD_ID(id)) % THREAD_TABLE_SZ) +#endif GC_EXTERN volatile GC_thread GC_threads[THREAD_TABLE_SZ];