mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-03 16:10:59 +00:00
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:
parent
e6ddffb93c
commit
b8cc468f02
@ -368,11 +368,9 @@ struct Genode::Locked_ptr : Genode::Locked_ptr_base
|
|||||||
|
|
||||||
void Genode::Weak_ptr_base::_adopt(Genode::Weak_object_base *obj)
|
void Genode::Weak_ptr_base::_adopt(Genode::Weak_object_base *obj)
|
||||||
{
|
{
|
||||||
if (!obj)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_obj = obj;
|
_obj = obj;
|
||||||
|
|
||||||
|
if (_obj)
|
||||||
{
|
{
|
||||||
Lock::Guard guard(_obj->_list_lock);
|
Lock::Guard guard(_obj->_list_lock);
|
||||||
_obj->_list.insert(this);
|
_obj->_list.insert(this);
|
||||||
|
@ -121,6 +121,22 @@ static void test_weak_pointer_tracking(Genode::Heap & heap)
|
|||||||
log("test: assign weak pointer to another");
|
log("test: assign weak pointer to another");
|
||||||
Weak_ptr<Object> ptr_3 = ptr_2;
|
Weak_ptr<Object> ptr_3 = ptr_2;
|
||||||
assert_weak_ptr_cnt(obj, 3);
|
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");
|
log("test: destruct weak pointer");
|
||||||
/* 'ptr_3' gets destructed when leaving the scope */
|
/* 'ptr_3' gets destructed when leaving the scope */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user