1 #include "server_obj.h" 2 #include "globals.h" 3 4 static Moe::Null_handler null_handler; 5 ~Server_object()6Moe::Server_object::~Server_object() 7 { 8 _weak_ptrs.reset(); 9 10 if (_weak_cap) 11 object_pool.cap_alloc()->free(_weak_cap); 12 13 if (obj_cap().is_valid()) 14 { 15 object_pool.cap_alloc()->free(obj_cap(), L4_FP_ALL_SPACES | L4_FP_DELETE_OBJ); 16 17 L4::Thread::Modify_senders todo; 18 todo.add(~3UL, 19 reinterpret_cast<l4_umword_t>(static_cast<L4::Epiface *>(this)), 20 ~0UL, 21 reinterpret_cast<l4_umword_t>(static_cast<L4::Epiface *>(&null_handler))); 22 L4::Cap<L4::Thread>(L4_BASE_THREAD_CAP)->modify_senders(todo); 23 } 24 } 25 26 void add_weak_ref(cxx::Weak_ref_base * obj) const27Moe::Server_object::add_weak_ref(cxx::Weak_ref_base *obj) const 28 { 29 if (_weak_ptrs.empty() && obj_cap()) 30 { 31 _weak_cap = object_pool.cap_alloc()->alloc<L4::Kobject>(); 32 // get a reference counted copy of the capability, 33 // so that it does not disappear when all caps are released in user land 34 _weak_cap.copy(obj_cap()); 35 } 36 37 _weak_ptrs.add(obj); 38 } 39 40 void remove_weak_ref(cxx::Weak_ref_base * obj) const41Moe::Server_object::remove_weak_ref(cxx::Weak_ref_base *obj) const 42 { 43 _weak_ptrs.remove(obj); 44 45 if (_weak_ptrs.empty() && _weak_cap) 46 { 47 object_pool.cap_alloc()->free(_weak_cap); 48 _weak_cap.invalidate(); 49 } 50 } 51 52 53