mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-24 09:46:44 +00:00
base: replace obj_by_* by lookup_and_lock
Add functionality to lookup an object and lock it. Additional the case is handled that a object may be already in-destruction and the lookup will deny returning the object. The object_pool generalize the lookup and lock functionality of the rpc_server and serve as base for following up patches to fix dangling pointer issues.
This commit is contained in:
committed by
Norman Feske
parent
ca37f26a01
commit
c2d3543e62
@ -56,7 +56,7 @@ void Pager_activation_base::entry()
|
||||
}
|
||||
|
||||
/* lookup referenced object */
|
||||
Pager_object *obj = _ep->obj_by_id(pager.badge());
|
||||
Object_pool<Pager_object>::Guard obj(_ep->lookup_and_lock(pager.badge()));
|
||||
|
||||
/* the pager_object might be destroyed, while we got the message */
|
||||
if (!obj) {
|
||||
@ -165,7 +165,7 @@ void Pager_entrypoint::dissolve(Pager_object *obj)
|
||||
/* cleanup at cap session */
|
||||
_cap_session->free(obj->Object_pool<Pager_object>::Entry::cap());
|
||||
|
||||
remove(obj);
|
||||
remove_locked(obj);
|
||||
}
|
||||
|
||||
|
||||
|
@ -71,22 +71,23 @@ void Rpc_entrypoint::entry()
|
||||
}
|
||||
|
||||
/* atomically lookup and lock referenced object */
|
||||
Object_pool<Rpc_object_base>::Guard curr_obj(lookup_and_lock(srv.badge()));
|
||||
if (!curr_obj)
|
||||
continue;
|
||||
|
||||
{
|
||||
Lock::Guard lock_guard(_curr_obj_lock);
|
||||
|
||||
_curr_obj = obj_by_id(srv.badge());
|
||||
if (!_curr_obj)
|
||||
continue;
|
||||
|
||||
_curr_obj->lock();
|
||||
_curr_obj = curr_obj;
|
||||
}
|
||||
|
||||
/* dispatch request */
|
||||
try { srv.ret(_curr_obj->dispatch(opcode, srv, srv)); }
|
||||
catch (Blocking_canceled) { }
|
||||
|
||||
_curr_obj->unlock();
|
||||
_curr_obj = 0;
|
||||
{
|
||||
Lock::Guard lock_guard(_curr_obj_lock);
|
||||
_curr_obj = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* answer exit call, thereby wake up '~Rpc_entrypoint' */
|
||||
|
@ -40,9 +40,7 @@ void Genode::Cpu_session_component::enable_vcpu(Genode::Thread_capability thread
|
||||
using namespace Genode;
|
||||
using namespace Fiasco;
|
||||
|
||||
Lock::Guard lock_guard(_thread_list_lock);
|
||||
|
||||
Cpu_thread_component *thread = _lookup_thread(thread_cap);
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
if (!thread) return;
|
||||
|
||||
Native_thread tid = thread->platform_thread()->thread().local.dst();
|
||||
@ -58,9 +56,7 @@ Genode::Cpu_session_component::native_cap(Genode::Thread_capability cap)
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
Lock::Guard lock_guard(_thread_list_lock);
|
||||
|
||||
Cpu_thread_component *thread = _lookup_thread(cap);
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(cap));
|
||||
if (!thread) return Native_capability();
|
||||
|
||||
return thread->platform_thread()->thread().local;
|
||||
@ -101,9 +97,7 @@ void Genode::Cpu_session_component::single_step(Genode::Thread_capability thread
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
Lock::Guard lock_guard(_thread_list_lock);
|
||||
|
||||
Cpu_thread_component *thread = _lookup_thread(thread_cap);
|
||||
Object_pool<Cpu_thread_component>::Guard thread(_thread_ep->lookup_and_lock(thread_cap));
|
||||
if (!thread) return;
|
||||
|
||||
Native_thread tid = thread->platform_thread()->thread().local.dst();
|
||||
|
@ -110,16 +110,6 @@ namespace Genode {
|
||||
*/
|
||||
Signal_context_capability _default_exception_handler;
|
||||
|
||||
/**
|
||||
* Lookup thread in CPU session by its capability
|
||||
*
|
||||
* \retval NULL thread capability is invalid or
|
||||
* does not belong to the CPU session
|
||||
*/
|
||||
Cpu_thread_component *_lookup_thread(Thread_capability thread) {
|
||||
return dynamic_cast<Cpu_thread_component *>
|
||||
(_thread_ep->obj_by_cap(thread)); }
|
||||
|
||||
/**
|
||||
* Raw thread-killing functionality
|
||||
*
|
||||
|
Reference in New Issue
Block a user