#include <gc.hh>
Static Public Member Functions | |
| static ulint | live_roots (void) |
| Returns number of live root pointers. | |
| static ulint | live_keystones (void) |
| Returns number of live keystones. | |
| static void | run (void) |
| Runs garbage collection. | |
Private Member Functions | |
| gc (const gc &) | |
| Hides copy constructor. | |
| gc & | operator= (const gc &) |
| Hides assignment operator. | |
Static Private Member Functions | |
| static void | init (void) |
| Initializes static variables. | |
| static void | cleanup (void) |
| Performs cleanup of static variables. | |
Static Private Attributes | |
| static ulint | initialized = 0 |
| Guard flag to prevent multiple initialization. | |
| static root_pointer * | roots |
| Doubly linked list of all root pointers. | |
| static keystone * | keystones |
| Singly linked list of all keystones. | |
| static keystone * | marked |
| Singly linked list of marked keystones. | |
Friends | |
| class | init_gc |
| Initializer accesses gc private methods. | |
| class | root_pointer |
| Root pointer accesses gc private fields for speed. | |
| class | keystone |
| Keystone accesses gc private fields for speed. | |
Provides garbage collector functionality.
Definition at line 78 of file gc.hh.
| lestes::std::mem::gc::gc | ( | const gc & | ) | [private] |
Hides copy constructor.
| ulint lestes::std::mem::gc::live_roots | ( | void | ) | [static] |
Returns number of live root pointers.
Counts live root pointers.
Definition at line 114 of file gc.cc.
References lestes::std::mem::root_pointer::next, and roots.
Referenced by lestes::std::mem::gc_test().
00115 { 00116 ulint cnt = 0; 00117 for (root_pointer *p = roots->next; p != roots; p = p->next) { 00118 cnt++; 00119 } 00120 return cnt; 00121 }
| ulint lestes::std::mem::gc::live_keystones | ( | void | ) | [static] |
Returns number of live keystones.
Counts live keysones.
Definition at line 127 of file gc.cc.
References keystones, and lestes::std::mem::keystone::keystones_next.
Referenced by lestes::std::mem::gc_test().
00128 { 00129 ulint cnt = 0; 00130 for (keystone *p = keystones; p != NULL; p = p->keystones_next) { 00131 cnt++; 00132 } 00133 return cnt; 00134 }
| void lestes::std::mem::gc::run | ( | void | ) | [static] |
Runs garbage collection.
Runs garbage collection, invoked in new_handler. Should be invoked explicitly after completing task.
Definition at line 140 of file gc.cc.
References lestes::std::mem::keystone::enqueue(), lestes::std::mem::keystone::gc_mark(), keystones, lestes::std::mem::keystone::keystones_next, marked, lestes::std::mem::keystone::marked_next, lestes::std::mem::root_pointer::next, roots, and lestes::std::mem::keystone::sweep().
Referenced by cleanup().
00141 { 00142 // initialize the global marked list 00143 marked = NULL; 00144 // walk through all root pointers and 00145 // insert keystones into marked list 00146 for (root_pointer *p = roots->next; p != roots; p = p->next) { 00147 keystone *key = p->pointer_get(); 00148 if (key) key->enqueue(); 00149 } 00150 00151 // mark all levels of keystones 00152 while (marked != NULL) { 00153 keystone *old = marked; 00154 // initialize the global list for new marking 00155 marked = NULL; 00156 while (old) { 00157 // mark directly reachable keystones 00158 old->gc_mark(); 00159 old = old->marked_next; 00160 } 00161 } 00162 00163 keystone *key = keystones; 00164 00165 // initialize the linked list before new connecting 00166 keystones = NULL; 00167 00168 // walk through all keystones and sweep unmarked 00169 while (key != NULL) { 00170 // save the pointer to next 00171 keystone *tmp = key->keystones_next; 00172 // after sweep_object, obj may be invalid 00173 key->sweep(); 00174 // restore pointer to next 00175 key = tmp; 00176 } 00177 }
| void lestes::std::mem::gc::init | ( | void | ) | [static, private] |
Initializes static variables.
Initializes static fields of gc class. Prevents multiple initialization.
Definition at line 71 of file gc.cc.
References initialized, keystones, marked, root_pointer, and roots.
Referenced by lestes::std::mem::init_gc::init_gc().
00072 { 00073 if (initialized++) return; 00074 // create head of linked list 00075 roots = new root_pointer(false); 00076 keystones = NULL; 00077 marked = NULL; 00078 }
| void lestes::std::mem::gc::cleanup | ( | void | ) | [static, private] |
Performs cleanup of static variables.
Performs cleanup of static fields of gc class.
TMA: also cleans all remaining objects.
Definition at line 85 of file gc.cc.
References initialized, roots, and run().
Referenced by lestes::std::mem::init_gc::~init_gc().
00086 { 00087 if (--initialized) return; 00088 run(); 00089 delete roots; 00090 }
friend class init_gc [friend] |
friend class root_pointer [friend] |
friend class keystone [friend] |
ulint lestes::std::mem::gc::initialized = 0 [static, private] |
root_pointer * lestes::std::mem::gc::roots [static, private] |
Doubly linked list of all root pointers.
Start of doubly linked list of all root pointers. Initialized to point to the fake head entry.
Definition at line 100 of file gc.hh.
Referenced by cleanup(), init(), live_roots(), lestes::std::mem::root_pointer::root_pointer(), and run().
keystone * lestes::std::mem::gc::keystones [static, private] |
Singly linked list of all keystones.
Start of singly linked list of all keystones. Initially the list is empty.
Definition at line 102 of file gc.hh.
Referenced by init(), lestes::std::mem::keystone::keystone(), live_keystones(), run(), and lestes::std::mem::keystone::sweep().
keystone * lestes::std::mem::gc::marked [static, private] |
1.5.1-20070107