Use THREAD_EQUAL consistently to compare pthread_t values
authorIvan Maidanski <ivmai@mail.ru>
Thu, 19 Apr 2018 21:32:14 +0000 (00:32 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 19 Apr 2018 21:32:14 +0000 (00:32 +0300)
(code refactoring)

* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD] (GC_suspend_thread):
Use THREAD_EQUAL() to compare pthread_t values.
* pthread_support.c (GC_unregister_my_thread): Likewise.
* specific.c [USE_CUSTOM_SPECIFIC] (GC_remove_specific_after_fork,
GC_slow_getspecific): Likewise.

pthread_stop_world.c
pthread_support.c
specific.c

index d3e8b2d..c20ec17 100644 (file)
@@ -547,7 +547,7 @@ STATIC void GC_restart_handler(int sig)
       /* Set the flag making the change visible to the signal handler.  */
       AO_store_release(&t->suspended_ext, TRUE);
 
-      if ((pthread_t)thread == pthread_self()) {
+      if (THREAD_EQUAL((pthread_t)thread, pthread_self())) {
         UNLOCK();
         /* It is safe as "t" cannot become invalid here (no race with   */
         /* GC_unregister_my_thread).                                    */
index 339d631..34b8c76 100644 (file)
@@ -1503,7 +1503,7 @@ GC_API int GC_CALL GC_unregister_my_thread(void)
                 "Called GC_unregister_my_thread on %p, gc_thread = %p\n",
                 (void *)self, (void *)me);
 #   endif
-    GC_ASSERT(me->id == self);
+    GC_ASSERT(THREAD_EQUAL(me->id, self));
     GC_unregister_my_thread_inner(me);
     RESTORE_CANCEL(cancel_state);
     UNLOCK();
index 0ded036..954b215 100644 (file)
@@ -91,7 +91,7 @@ GC_INNER void GC_remove_specific_after_fork(tsd * key, pthread_t t)
 #   endif
     pthread_mutex_lock(&(key -> lock));
     entry = *link;
-    while (entry != NULL && entry -> thread != t) {
+    while (entry != NULL && !THREAD_EQUAL(entry->thread, t)) {
       link = &(entry -> next);
       entry = *link;
     }
@@ -132,7 +132,7 @@ GC_INNER void * GC_slow_getspecific(tsd * key, word qtid,
     tse *entry = key->hash[hash_val].p;
 
     GC_ASSERT(qtid != INVALID_QTID);
-    while (entry != NULL && entry -> thread != self) {
+    while (entry != NULL && !THREAD_EQUAL(entry->thread, self)) {
       entry = entry -> next;
     }
     if (entry == NULL) return NULL;