bsnes: redump sprite/palette functions
[lsnes.git] / src / library / gc.cpp
blob024133026d8f459c6098641192f595d0ce17c996
1 #include "gc.hpp"
2 #include <list>
3 #include <iostream>
4 #include <set>
6 namespace
8 std::set<garbage_collectable*> gc_items;
11 garbage_collectable::garbage_collectable()
13 gc_items.insert(this);
14 root_count = 1;
17 garbage_collectable::~garbage_collectable()
19 gc_items.erase(this);
22 void garbage_collectable::mark_root()
24 root_count++;
27 void garbage_collectable::unmark_root()
29 if(root_count) root_count--;
32 void garbage_collectable::do_gc()
34 for(auto i : gc_items)
35 i->reachable = false;
36 for(auto i : gc_items) {
37 if(i->root_count) {
38 i->mark();
41 for(auto i = gc_items.begin(); i != gc_items.end();) {
42 if(!(*i)->reachable) {
43 auto ptr = i;
44 i++;
45 delete *ptr;
46 } else
47 i++;
51 void garbage_collectable::mark()
53 bool was_reachable = reachable;
54 reachable = true;
55 if(!was_reachable) {
56 trace();