]> granicus.if.org Git - gc/commitdiff
Code refactoring of specific.c and specific.h;
authorIvan Maidanski <ivmai@mail.ru>
Sat, 21 Apr 2012 19:44:19 +0000 (23:44 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Sat, 21 Apr 2012 19:44:19 +0000 (23:44 +0400)
cast pointers to word instead of unsigned long

* include/private/specific.h (CACHE_HASH, HASH): Add parentheses
around the argument.
* include/private/specific.h (CACHE_HASH): Remove unnecessary cast to
long.
* include/private/specific.h (HASH): Rename "n" argument to "p";
cast "p" to word instead of long; cast result to unsigned.
* include/private/specific.h (quick_thread_id, INVALID_QTID): Cast to
word instead of unsigned long.
* specific.c (GC_key_create_inner): Cast invalid_tse.next (pointer) to
word instead of unsigned long.
* include/private/specific.h (GC_slow_getspecific, GC_getspecific):
Change type of "qtid" from unsigned long to word.
* specific.c (GC_slow_getspecific): Likewise.
* include/private/specific.h (GC_getspecific): Remove "hash_val"
local variable.
* specific.c: Do not include gc_priv.h as included from
thread_local_alloc.h; do not include atomic_ops.h as included from
specific.h file.

include/private/specific.h
specific.c

index 3382558e7ab47092515396027174bbb8681da88e..7648f2c199d9313057f40da0ce6dea4828c1d625 100644 (file)
 #define MALLOC_CLEAR(n) GC_INTERNAL_MALLOC(n, NORMAL)
 
 #define TS_CACHE_SIZE 1024
-#define CACHE_HASH(n) (((((long)n) >> 8) ^ (long)n) & (TS_CACHE_SIZE - 1))
+#define CACHE_HASH(n) ((((n) >> 8) ^ (n)) & (TS_CACHE_SIZE - 1))
+
 #define TS_HASH_SIZE 1024
-#define HASH(n) (((((long)n) >> 8) ^ (long)n) & (TS_HASH_SIZE - 1))
+#define HASH(p) \
+          ((unsigned)((((word)(p)) >> 8) ^ (word)(p)) & (TS_HASH_SIZE - 1))
 
 /* An entry describing a thread-specific value for a given thread.      */
 /* All such accessible structures preserve the invariant that if either */
@@ -52,9 +54,9 @@ typedef struct thread_specific_entry {
 /* or at least thread stack separation, is at least 4K.                 */
 /* Must be defined so that it never returns 0.  (Page 0 can't really be */
 /* part of any stack, since that would make 0 a valid stack pointer.)   */
-#define quick_thread_id() (((unsigned long)GC_approx_sp()) >> 12)
+#define quick_thread_id() (((word)GC_approx_sp()) >> 12)
 
-#define INVALID_QTID ((unsigned long)0)
+#define INVALID_QTID ((word)0)
 #define INVALID_THREADID ((pthread_t)0)
 
 union ptse_ao_u {
@@ -77,15 +79,14 @@ GC_INNER int GC_setspecific(tsd * key, void * value);
 GC_INNER void GC_remove_specific(tsd * key);
 
 /* An internal version of getspecific that assumes a cache miss.        */
-GC_INNER void * GC_slow_getspecific(tsd * key, unsigned long qtid,
+GC_INNER void * GC_slow_getspecific(tsd * key, word qtid,
                                     tse * volatile * cache_entry);
 
 /* GC_INLINE is defined in gc_priv.h. */
 GC_INLINE void * GC_getspecific(tsd * key)
 {
-    unsigned long qtid = quick_thread_id();
-    unsigned hash_val = CACHE_HASH(qtid);
-    tse * volatile * entry_ptr = key -> cache + hash_val;
+    word qtid = quick_thread_id();
+    tse * volatile * entry_ptr = &key->cache[CACHE_HASH(qtid)];
     tse * entry = *entry_ptr;   /* Must be loaded only once.    */
     if (EXPECT(entry -> qtid == qtid, TRUE)) {
       GC_ASSERT(entry -> thread == pthread_self());
index 5f4765dfb08a09bb48ad75a198c06ebb44e1a370..e35c9b574fd9067bd10da63bceda5780296051df 100644 (file)
@@ -11,7 +11,6 @@
  * modified is included with the above copyright notice.
  */
 
-#include "private/gc_priv.h"    /* For configuration, pthreads.h. */
 #include "private/thread_local_alloc.h"
                 /* To determine type of tsd impl.       */
                 /* Includes private/specific.h          */
@@ -19,8 +18,6 @@
 
 #if defined(USE_CUSTOM_SPECIFIC)
 
-#include "atomic_ops.h"
-
 static const tse invalid_tse = {INVALID_QTID, 0, 0, INVALID_THREADID};
             /* A thread-specific data entry which will never    */
             /* appear valid to a reader.  Used to fill in empty */
@@ -32,7 +29,7 @@ GC_INNER int GC_key_create_inner(tsd ** key_ptr)
     tsd * result = (tsd *)MALLOC_CLEAR(sizeof(tsd));
 
     /* A quick alignment check, since we need atomic stores */
-    GC_ASSERT((unsigned long)(&invalid_tse.next) % sizeof(tse *) == 0);
+    GC_ASSERT((word)(&invalid_tse.next) % sizeof(tse *) == 0);
     if (0 == result) return ENOMEM;
     pthread_mutex_init(&(result -> lock), NULL);
     for (i = 0; i < TS_CACHE_SIZE; ++i) {
@@ -109,7 +106,7 @@ GC_INNER void GC_remove_specific(tsd * key)
 }
 
 /* Note that even the slow path doesn't lock.   */
-GC_INNER void * GC_slow_getspecific(tsd * key, unsigned long qtid,
+GC_INNER void * GC_slow_getspecific(tsd * key, word qtid,
                                     tse * volatile * cache_ptr)
 {
     pthread_t self = pthread_self();