Files | |
file | gc.c |
plint garbage collection. | |
file | gc.h |
plint garbage collection. | |
Data Structures | |
struct | _plint_refs |
a list of the references to a node. More... | |
struct | _plint_cycles |
a list of GC cycles. More... | |
struct | _plint_gc_link |
the brick of gc mechanism. More... | |
struct | _plint_gc_cycle |
a cycle. More... | |
struct | _plint_gc_chunk |
Defines | |
#define | gc_lock() ++gc_lock_flag, gc_dirty_flag = !0 |
locks the triggering of gc. More... | |
#define | gc_unlock() --gc_lock_flag |
unlocks the triggering of gc. More... | |
#define | force_gc_collect() |
forces triggering of the collection algorithm. More... | |
#define | PLINT_GC_CHUNK_INIT(__p__) |
initializes the gc chunk of a node. More... | |
Typedefs | |
typedef _plint_refs * | plint_refs_t |
typedef _plint_cycles * | plint_cycles_t |
typedef _plint_gc_link * | plint_gc_link_t |
typedef _plint_gc_cycle * | plint_gc_cycle_t |
Functions | |
void | gc_collect () |
the actual garbage collection algorithm. More... | |
void | plint_gc_init () |
initialise the Garbage Collection engine. | |
void | plint_gc_finish () |
finalize the Garbage Collection engine. | |
int | plint_gc_empty () |
test if GCP is empty. | |
void | plint_cycle_detect (plint_mem_t MEMORY, plint_ref_t REFERENCE) |
Variables | |
unsigned int | gc_lock_flag |
a lock to prevent auto-triggering of gc. | |
int | gc_dirty_flag |
a variable used in auto-triggered-alarm-time-estimation. |
|
locks the triggering of gc.
Definition at line 74 of file gc.h. Referenced by plint_data_type_finish, plint_gc_finish, plint_ptr_fre, and plint_var_fre. |
|
unlocks the triggering of gc.
Definition at line 75 of file gc.h. Referenced by plint_ptr_fre, and plint_var_fre. |
|
Value: { \ extern void gc_collect(); \ gc_lock(); \ gc_collect(); \ gc_unlock(); \ }
Definition at line 79 of file gc.h. Referenced by plint_type_finish, and plint_type_unregister. |
|
Value: (__p__)->ref = 0; \ (__p__)->cycles_ref = 0; \ (__p__)->refs_ref = 0; \ (__p__)->cycles_head = 0; \ (__p__)->refs_head = 0; \ (__p__)->mark = 0
|
|
the actual garbage collection algorithm.
Definition at line 636 of file gc.c. References _plint_gc_cycle::cycle, gc_dirty_flag, _plint_gc_cycle::next, and _plint_gc_cycle::skip.
00637 { 00638 size_t i, m; 00639 plint_gc_cycle_t * p; 00640 plint_gc_cycle_t q; 00641 00642 #ifndef PLINT_DOGC_LAST 00643 int r = getpriority(PRIO_PROCESS, 0); 00644 sigset_t lock_ss, old_ss; 00645 sigfillset(&lock_ss); 00646 sigprocmask(SIG_SETMASK, &lock_ss, &old_ss); 00647 setpriority(PRIO_PROCESS, 0, -20); 00648 #endif 00649 00650 for (n = 1; n <= ncycles; ++n) 00651 for (p = acycles+n-1; (q = *p); ) 00652 { 00653 for (i = 0; i < n; ++i) 00654 if (0 /* cycle has opened due to a ... */ 00655 || plint_ref_var(plint_mrv_ref(q->cycle[i])) != plint_mrv_var(q->cycle[i]) /* ... PLINT_ASG_REF assignment */ 00656 || plint_var_mem(plint_mrv_var(q->cycle[i])) != plint_mrv_mem(q->cycle[(i+1)%n])) /* ... PLINT_ASG_VAL assignment */ 00657 break; 00658 if (i < n) 00659 collect(p, q, !0); 00660 else 00661 p = &q->next; 00662 } 00663 00664 for (n = 1; n <= ncycles; ++n) 00665 for (q = acycles[n-1]; q; q = q->next) 00666 if (!q->skip) 00667 for (i = 0; i < n; ++i) 00668 if (0 /* reference count sum equation */ 00669 || plint_mrv_var(q->cycle[i])->_gc.ref > plint_mrv_var(q->cycle[i])->_gc.cycles_ref + plint_mrv_var(q->cycle[i])->_gc.refs_ref 00670 || plint_mrv_mem(q->cycle[i])->_gc.ref > plint_mrv_mem(q->cycle[i])->_gc.cycles_ref + plint_mrv_mem(q->cycle[i])->_gc.refs_ref 00671 ) 00672 { 00673 skip(q, n); 00674 break; 00675 } 00676 00677 for (m = 0, n = 1; n <= ncycles; (acycles[n-1] ? 0 : ++m), ++n) 00678 for (p = acycles+n-1; (q = *p); ) 00679 if (q->skip) 00680 { 00681 q->skip = 0; 00682 p = &q->next; 00683 } 00684 else 00685 collect(p, q, 0); 00686 00687 if (m == ncycles) 00688 { 00689 free(acycles); 00690 acycles = 0; 00691 ncycles = 0; 00692 } 00693 00694 #ifndef PLINT_DOGC_LAST 00695 gc_dirty_flag = 0; 00696 setpriority(PRIO_PROCESS, 0, r); 00697 sigprocmask(SIG_SETMASK, &old_ss, 0); 00698 #endif 00699 00700 } |