base: support assignment of invalid weak_ptr

This fixes the region-map component implementation in core, which uses a
'Genode::Weak_ptr<Genode::Region_map_component> _faulting_region_map'
member. This member is assigned a valid weak_ptr or an invalid weak_ptr
according to the state machine.

Fixes #3012
This commit is contained in:
Alexander Boettcher 2018-10-10 21:04:23 +02:00 committed by Christian Helmuth
parent e6ddffb93c
commit b8cc468f02
2 changed files with 17 additions and 3 deletions

View File

@ -368,11 +368,9 @@ struct Genode::Locked_ptr : Genode::Locked_ptr_base
void Genode::Weak_ptr_base::_adopt(Genode::Weak_object_base *obj)
{
if (!obj)
return;
_obj = obj;
if (_obj)
{
Lock::Guard guard(_obj->_list_lock);
_obj->_list.insert(this);

View File

@ -121,6 +121,22 @@ static void test_weak_pointer_tracking(Genode::Heap & heap)
log("test: assign weak pointer to another");
Weak_ptr<Object> ptr_3 = ptr_2;
assert_weak_ptr_cnt(obj, 3);
assert_weak_ptr_valid(ptr_3, true);
log("test: destruct weak pointer");
/* 'ptr_3' gets destructed when leaving the scope */
}
assert_weak_ptr_cnt(obj, 2);
{
log("test: assign invalid weak pointer to another");
Weak_ptr<Object> ptr_3 = ptr_2;
assert_weak_ptr_cnt(obj, 3);
assert_weak_ptr_valid(ptr_3, true);
ptr_3 = Weak_ptr<Object>();
assert_weak_ptr_cnt(obj, 2);
assert_weak_ptr_valid(ptr_3, false);
log("test: destruct weak pointer");
/* 'ptr_3' gets destructed when leaving the scope */