]> granicus.if.org Git - gc/commitdiff
Code refactoring of "event callbacks" functionality
authorIvan Maidanski <ivmai@mail.ru>
Sun, 17 May 2015 15:23:52 +0000 (18:23 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Sun, 17 May 2015 15:23:52 +0000 (18:23 +0300)
* alloc.c (GC_on_collection_event): Remove declaration (moved to
gc_priv.h).
* darwin_stop_world.c (GC_on_collection_event): Likewise.
* pthread_stop_world.c (GC_on_collection_event): Likewise.
* win32_threads.c (GC_on_collection_event): Likewise.
* alloc.c (start_world): Rename to start_world_inner; inline it.
* darwin_stop_world.c (GC_start_world): Wrap long code lines.
* pthread_stop_world.c (GC_suspend_all, GC_start_world): Likewise.
* win32_threads.c (GC_stop_world, GC_start_world): Likewise.
* include/gc.h: Remove trailing space at EOLn.
* include/private/gc_priv.h (GC_on_collection_event): Declare global
variable (using GC_EXTERN).
* misc.c (GC_on_collection_event): Add GC_INNER; replace NULL to 0.

alloc.c
darwin_stop_world.c
include/gc.h
include/private/gc_priv.h
misc.c
pthread_stop_world.c
win32_threads.c

diff --git a/alloc.c b/alloc.c
index 8bc68a22042572f83d0234bcde7a30eb8e372795..5dd19f63e0546e8eb2f7656e336d7cbca1b71f78 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -88,8 +88,6 @@ STATIC GC_bool GC_need_full_gc = FALSE;
 
 STATIC word GC_used_heap_size_after_full = 0;
 
-extern GC_on_collection_event_proc GC_on_collection_event;
-
 /* GC_copyright symbol is externally visible. */
 char * const GC_copyright[] =
 {"Copyright 1988,1989 Hans-J. Boehm and Alan J. Demers ",
@@ -586,7 +584,7 @@ GC_API int GC_CALL GC_collect_a_little(void)
 # define COMMA_IF_USE_MUNMAP(x) /* empty */
 #endif
 
-static void start_world()
+GC_INLINE void start_world_inner(void)
 {
   if (GC_on_collection_event)
     GC_on_collection_event(GC_EVENT_STARTWORLD_BEGIN, NULL);
@@ -664,7 +662,7 @@ STATIC GC_bool GC_stopped_mark(GC_stop_func stop_func)
             if (GC_on_collection_event)
               GC_on_collection_event(GC_EVENT_MARK_END, NULL);
 
-            start_world();
+            start_world_inner();
             return(FALSE);
           }
           if (GC_mark_some(GC_approx_sp())) break;
@@ -688,7 +686,7 @@ STATIC GC_bool GC_stopped_mark(GC_stop_func stop_func)
 #   ifdef THREAD_LOCAL_ALLOC
       GC_world_stopped = FALSE;
 #   endif
-    start_world();
+    start_world_inner();
 #   ifndef SMALL_CONFIG
       if (GC_PRINT_STATS_FLAG) {
         unsigned long time_diff;
index 32b1ea646d0b101fbe4e0b1f40f39b3b5dcf007e..2ef74af1df4183f31f48df42a89f4526b02963c2 100644 (file)
@@ -458,8 +458,6 @@ STATIC GC_bool GC_suspend_thread_list(thread_act_array_t act_list, int count,
 
 #endif /* !GC_NO_THREADS_DISCOVERY */
 
-extern GC_on_collection_event_proc GC_on_collection_event;
-
 /* Caller holds allocation lock.        */
 GC_INNER void GC_stop_world(void)
 {
@@ -660,7 +658,8 @@ GC_INNER void GC_start_world(void)
              p->stop_info.mach_thread != my_thread)
           GC_thread_resume(p->stop_info.mach_thread);
           if (GC_on_collection_event)
-            GC_on_collection_event(GC_EVENT_THREAD_UNSUSPENDED, (void *)p->stop_info.mach_thread);
+            GC_on_collection_event(GC_EVENT_THREAD_UNSUSPENDED,
+                                   (void *)p->stop_info.mach_thread);
       }
     }
 
index a034eb0f0d3a08b59131afde52b93751177b08b4..8eeb6257dcc06916447fbbef061668fcc77d363b 100644 (file)
@@ -150,7 +150,7 @@ typedef void (GC_CALLBACK * GC_on_collection_event_proc)(GCEventKind, void*);
                         /* allocation lock held).  May be 0.            */
 GC_API void GC_CALL GC_set_on_collection_event(GC_on_collection_event_proc);
 GC_API GC_on_collection_event_proc GC_CALL GC_get_on_collection_event(void);
+
 GC_API GC_ATTR_DEPRECATED int GC_find_leak;
                         /* Do not actually garbage collect, but simply  */
                         /* report inaccessible memory that was not      */
index 69c32e9c0dbbfef8d97c5a7ef5c6a45b5700797b..8e8e56b7b0edc5e1b2fce3ef743e8d7a1508f707 100644 (file)
@@ -1931,6 +1931,8 @@ GC_EXTERN void (*GC_print_heap_obj)(ptr_t p);
                         /* Print an address map of the process.         */
 #endif
 
+GC_EXTERN GC_on_collection_event_proc GC_on_collection_event;
+
 #ifndef SHORT_DBG_HDRS
   GC_EXTERN GC_bool GC_findleak_delay_free;
                         /* Do not immediately deallocate object on      */
diff --git a/misc.c b/misc.c
index 91a422b2b26b6570aadfe87889487b72ece68afa..7eb56c73761bd8a5efe796779bd2de95a0eb821c 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -2034,7 +2034,7 @@ GC_API GC_on_heap_resize_proc GC_CALL GC_get_on_heap_resize(void)
     return fn;
 }
 
-GC_on_collection_event_proc GC_on_collection_event = NULL;
+GC_INNER GC_on_collection_event_proc GC_on_collection_event = 0;
 
 GC_API void GC_CALL GC_set_on_collection_event(GC_on_collection_event_proc fn)
 {
index 9ad51e3a60a50ccc1e128ee75098b3d03b031ee8..2915a7863bbe1f3efb5a765ba1a1b88039b8339e 100644 (file)
@@ -459,8 +459,6 @@ GC_INNER void GC_push_all_stacks(void)
   }
 #endif /* PLATFORM_ANDROID */
 
-extern GC_on_collection_event_proc GC_on_collection_event;
-
 /* We hold the allocation lock.  Suspend all threads that might */
 /* still be running.  Return the number of suspend signals that */
 /* were sent.                                                   */
@@ -507,7 +505,8 @@ STATIC int GC_suspend_all(void)
                 p -> stop_info.stack_ptr = (ptr_t)stack.ss_sp - stack.ss_size;
 
                 if (GC_on_collection_event)
-                  GC_on_collection_event(GC_EVENT_THREAD_SUSPENDED, (void *)p->id);
+                  GC_on_collection_event(GC_EVENT_THREAD_SUSPENDED,
+                                         (void *)p->id);
               }
 #           else
 #             ifndef PLATFORM_ANDROID
@@ -854,7 +853,8 @@ GC_INNER void GC_start_world(void)
               result = android_thread_kill(thread_id, GC_sig_thr_restart);
 #           endif
             if (GC_on_collection_event)
-              GC_on_collection_event(GC_EVENT_THREAD_UNSUSPENDED, (void *)thread_id);
+              GC_on_collection_event(GC_EVENT_THREAD_UNSUSPENDED,
+                                     (void *)thread_id);
 
             switch(result) {
                 case ESRCH:
index 19da9cea37a6e07cccd7209b055d34a187f3cc7e..b7240c8616fe87284f21894361468b66e3a75505 100644 (file)
@@ -1182,8 +1182,6 @@ STATIC void GC_suspend(GC_thread t)
                 /* TRUE only if GC_stop_world() acquired GC_write_cs.   */
 #endif
 
-extern GC_on_collection_event_proc GC_on_collection_event;
-
 GC_INNER void GC_stop_world(void)
 {
   DWORD thread_id = GetCurrentThreadId();
@@ -1230,7 +1228,8 @@ GC_INNER void GC_stop_world(void)
             && t -> id != thread_id) {
           GC_suspend((GC_thread)t);
           if (GC_on_collection_event)
-            GC_on_collection_event(GC_EVENT_THREAD_SUSPENDED, (void *)THREAD_HANDLE(t));
+            GC_on_collection_event(GC_EVENT_THREAD_SUSPENDED,
+                                   (void *)THREAD_HANDLE(t));
         }
       }
     } else
@@ -1245,7 +1244,8 @@ GC_INNER void GC_stop_world(void)
             && !KNOWN_FINISHED(t) && t -> id != thread_id) {
           GC_suspend(t);
           if (GC_on_collection_event)
-            GC_on_collection_event(GC_EVENT_THREAD_SUSPENDED, (void *)THREAD_HANDLE(t));
+            GC_on_collection_event(GC_EVENT_THREAD_SUSPENDED,
+                                   (void *)THREAD_HANDLE(t));
         }
       }
     }
@@ -1280,7 +1280,8 @@ GC_INNER void GC_start_world(void)
           ABORT("ResumeThread failed");
         t -> suspended = FALSE;
         if (GC_on_collection_event)
-          GC_on_collection_event(GC_EVENT_THREAD_UNSUSPENDED, (void *)THREAD_HANDLE(t));
+          GC_on_collection_event(GC_EVENT_THREAD_UNSUSPENDED,
+                                 (void *)THREAD_HANDLE(t));
       }
     }
   } else {
@@ -1296,7 +1297,8 @@ GC_INNER void GC_start_world(void)
           UNPROTECT_THREAD(t);
           t -> suspended = FALSE;
           if (GC_on_collection_event)
-            GC_on_collection_event(GC_EVENT_THREAD_UNSUSPENDED, (void *)THREAD_HANDLE(t));
+            GC_on_collection_event(GC_EVENT_THREAD_UNSUSPENDED,
+                                   (void *)THREAD_HANDLE(t));
         }
       }
     }