Back to index

lightning-sunbird  0.9+nobinonly
generic_threads.c
Go to the documentation of this file.
00001 /*
00002   generic_threads.c
00003   
00004   A module that permits clients of the GC to supply callback functions
00005   for thread stack scanning.
00006   
00007   by Patrick C. Beard.
00008  */
00009 
00010 #include "generic_threads.h"
00011 # include "gc_priv.h"
00012 # include "gc_mark.h"
00013 
00014 static void mark_range(char* begin, char* end)
00015 {
00016   /* use the mark stack API, which will do more sanity checking. */
00017   GC_push_all(begin, end);
00018   /*
00019   while (begin < end) {
00020     GC_PUSH_ONE_STACK(*(word*)begin, 0);
00021     begin += ALIGNMENT;
00022   }
00023   */
00024 }
00025 
00026 /*
00027        Until a client installs a stack marking routine, this will mark the
00028        current stack. This is crucial to keep data live during program
00029        startup.
00030  */
00031 static void default_mark_all_stacks(GC_mark_range_proc marker)
00032 {
00033 #ifdef STACK_GROWS_DOWN
00034   mark_range(GC_approx_sp(), GC_get_stack_base());
00035 #else
00036   mark_range(GC_get_stack_base(), GC_approx_sp());
00037 #endif
00038 }
00039 
00040 static void default_proc(void* mutex) {}
00041 
00042 GC_generic_mark_all_stacks_proc GC_generic_mark_all_stacks = &default_mark_all_stacks;
00043 void* GC_generic_mutex = NULL;
00044 GC_generic_proc GC_generic_locker = &default_proc;
00045 GC_generic_proc GC_generic_unlocker = &default_proc;
00046 GC_generic_proc GC_generic_stopper = &default_proc;
00047 GC_generic_proc GC_generic_starter = &default_proc;
00048 
00049 void GC_generic_init_threads(GC_generic_mark_all_stacks_proc mark_all_stacks,
00050                           void* mutex,
00051                           GC_generic_proc locker, GC_generic_proc unlocker,
00052                           GC_generic_proc stopper, GC_generic_proc starter)
00053 {
00054   GC_generic_mark_all_stacks = mark_all_stacks;
00055   GC_generic_mutex = mutex;
00056   GC_generic_locker = locker;
00057   GC_generic_unlocker = unlocker;
00058   GC_generic_stopper = stopper;
00059   GC_generic_starter = starter;
00060        
00061   GC_dont_expand = 1;
00062   // GC_set_max_heap_size(20L * 1024L * 1024L);
00063 }
00064 
00065 #if !defined(WIN32_THREADS) && !defined(LINUX_THREADS)
00066 void GC_push_all_stacks()
00067 {
00068   GC_generic_mark_all_stacks(&mark_range);
00069 }
00070 
00071 void GC_stop_world()
00072 {
00073   GC_generic_stopper(GC_generic_mutex);
00074 }
00075 
00076 void GC_start_world()
00077 {
00078   GC_generic_starter(GC_generic_mutex);
00079 }
00080 #endif /* WIN32_THREADS */