]> granicus.if.org Git - gc/commitdiff
2011-05-10 Ivan Maidanski <ivmai@mail.ru>
authorivmai <ivmai>
Tue, 10 May 2011 12:53:40 +0000 (12:53 +0000)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 26 Jul 2011 17:06:58 +0000 (21:06 +0400)
* pthread_support.c (GC_unregister_my_thread): Call pthread_self
only once.
* win32_threads.c (GC_pthread_start_inner): Ditto.
* pthread_support.c (GC_unregister_my_thread): Add debug output.
* win32_threads.c (GC_unregister_my_thread): Ditto.
* pthread_support.c (GC_register_my_thread,
GC_start_rtn_prepare_thread): Rename "my_pthread" local variable
to "self".

ChangeLog
pthread_support.c
win32_threads.c

index e2108958e08fabeaa51deb714c952886a7da32b7..283dc2b2d7ad6f78d5f15192e76d8785add6b4ae 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-05-10  Ivan Maidanski  <ivmai@mail.ru>
+
+       * pthread_support.c (GC_unregister_my_thread): Call pthread_self
+       only once.
+       * win32_threads.c (GC_pthread_start_inner): Ditto.
+       * pthread_support.c (GC_unregister_my_thread): Add debug output.
+       * win32_threads.c (GC_unregister_my_thread): Ditto.
+       * pthread_support.c (GC_register_my_thread,
+       GC_start_rtn_prepare_thread): Rename "my_pthread" local variable
+       to "self".
+
 2011-05-10  Ivan Maidanski  <ivmai@mail.ru>
 
        * include/gc.h (GC_HIDE_POINTER, GC_REVEAL_POINTER): Define
index 575ac9d31749f5326160a81b9a83f0e2ecd2236e..34793248b6ca23dce91e87dc5b873ce85759ceee 100644 (file)
@@ -1164,16 +1164,20 @@ GC_API void * GC_CALL GC_call_with_gc_active(GC_fn_type fn,
 
 GC_API int GC_CALL GC_unregister_my_thread(void)
 {
+    pthread_t self = pthread_self();
     GC_thread me;
     IF_CANCEL(int cancel_state;)
     DCL_LOCK_STATE;
 
+#   ifdef DEBUG_THREADS
+      GC_log_printf("Unregistering thread 0x%x\n", (unsigned)self);
+#   endif
     LOCK();
     DISABLE_CANCEL(cancel_state);
     /* Wait for any GC that may be marking from our stack to    */
     /* complete before we remove this thread.                   */
     GC_wait_for_gc_completion(FALSE);
-    me = GC_lookup_thread(pthread_self());
+    me = GC_lookup_thread(self);
     GC_ASSERT(!(me -> flags & FINISHED));
 #   if defined(THREAD_LOCAL_ALLOC)
       GC_destroy_thread_local(&(me->tlfs));
@@ -1186,7 +1190,7 @@ GC_API int GC_CALL GC_unregister_my_thread(void)
       }
 #   endif
     if (me -> flags & DETACHED) {
-        GC_delete_thread(pthread_self());
+        GC_delete_thread(self);
     } else {
         me -> flags |= FINISHED;
     }
@@ -1363,7 +1367,7 @@ GC_API void GC_CALL GC_allow_register_threads(void)
 
 GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)
 {
-    pthread_t my_pthread = pthread_self();
+    pthread_t self = pthread_self();
     GC_thread me;
     DCL_LOCK_STATE;
 
@@ -1371,9 +1375,9 @@ GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)
         ABORT("Threads explicit registering is not previously enabled");
 
     LOCK();
-    me = GC_lookup_thread(my_pthread);
+    me = GC_lookup_thread(self);
     if (0 == me) {
-        me = GC_register_my_thread_inner(sb, my_pthread);
+        me = GC_register_my_thread_inner(sb, self);
         me -> flags |= DETACHED;
           /* Treat as detached, since we do not need to worry about     */
           /* pointer results.                                           */
@@ -1404,17 +1408,16 @@ GC_INNER void * GC_start_rtn_prepare_thread(void *(**pstart)(void *),
                                         struct GC_stack_base *sb, void *arg)
 {
     struct start_info * si = arg;
+    pthread_t self = pthread_self();
     GC_thread me;
-    pthread_t my_pthread;
     DCL_LOCK_STATE;
 
-    my_pthread = pthread_self();
 #   ifdef DEBUG_THREADS
       GC_log_printf("Starting thread 0x%x, pid = %ld, sp = %p\n",
-                    (unsigned)my_pthread, (long)getpid(), &arg);
+                    (unsigned)self, (long)getpid(), &arg);
 #   endif
     LOCK();
-    me = GC_register_my_thread_inner(sb, my_pthread);
+    me = GC_register_my_thread_inner(sb, self);
     me -> flags = si -> flags;
 #   if defined(THREAD_LOCAL_ALLOC)
         GC_init_thread_local(&(me->tlfs));
index 026f1629aa3b4f1bd45a0058f167f6e9358c9834..33227caefbf776ded8f8016b151dafa1c0c99cec 100644 (file)
@@ -729,6 +729,10 @@ GC_API int GC_CALL GC_unregister_my_thread(void)
 {
   DCL_LOCK_STATE;
 
+# ifdef DEBUG_THREADS
+    GC_log_printf("Unregistering thread 0x%lx\n", (long)GetCurrentThreadId());
+# endif
+
   /* FIXME: is GC_wait_for_gc_completion(FALSE) needed here? */
   if (GC_win32_dll_threads) {
 #   if defined(THREAD_LOCAL_ALLOC)
@@ -2448,9 +2452,8 @@ GC_INNER void GC_thr_init(void)
     pthread_cleanup_pop(1);
 
 #   ifdef DEBUG_THREADS
-      GC_log_printf("thread %p(0x%lx) returned from start routine\n",
-                    GC_PTHREAD_PTRVAL(pthread_self()),
-                    (long)GetCurrentThreadId());
+      GC_log_printf("thread %p(0x%x) returned from start routine\n",
+                    GC_PTHREAD_PTRVAL(pthread_id), (int)thread_id);
 #   endif
     return(result);
   }