3 * (c) 2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
12 _______ ______ _____ ____ ___ __ __ _____ _ _ _____ _ _
13 | ____\ \/ / _ \| ____| _ \|_ _| \/ | ____| \ | |_ _|/ \ | |
14 | _| \ /| |_) | _| | |_) || || |\/| | _| | \| | | | / _ \ | |
15 | |___ / \| __/| |___| _ < | || | | | |___| |\ | | |/ ___ \| |___
16 |_____/_/\_\_| |_____|_| \_\___|_| |_|_____|_| \_| |_/_/ \_\_____|
21 #include <l4/re/util/object_registry>
24 namespace L4Re { namespace Util {
26 class Object_registry_gc : public Object_registry
29 Object_registry_gc(L4::Cap<L4::Thread> server, L4::Cap<L4::Factory> factory)
30 : Object_registry(server, factory)
33 L4::Cap<void> register_obj_with_gc(L4::Server_object *o, int refcnt)
35 int idx = get_free_slot();
37 return L4::Cap<void>::Invalid;
39 L4::Cap<void> c = Object_registry::register_obj(o);
45 ref_cnt[idx] = refcnt;
50 void gc_run(unsigned int min_delta_in_ms)
52 l4_cpu_time_t now = l4re_kip()->clock;
54 if (last_gc_run + (min_delta_in_ms * 1000) > now)
59 for (int i = 0; i < SLOTS; ++i)
63 L4Re::Env::env()->task()->cap_has_child(objs[i]->obj_cap());
64 if (!tag.label() && ref_cnt[i] == 0)
66 printf("Deleting %d %lx\n", i, objs[i]->obj_cap().cap());
67 delete objs[i]; // XXX: wrong because we do not create the object at open time
73 void ref_cnt_add(L4::Server_object *o, int d)
76 if ((idx = find_obj(o)) != -1)
82 L4::Server_object *objs[SLOTS];
84 l4_cpu_time_t last_gc_run;
88 for (int i = 0; i < SLOTS; ++i)
94 int find_obj(L4::Server_object *o)
96 for (int i = 0; i < SLOTS; ++i)