From c56927b76e4e66365a94bbd2679668a2089513b6 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Fri, 11 Oct 2013 12:29:40 +0200 Subject: [PATCH] hw: differ ID allocators even with same size Previously, if two ID allocators for different kernel objects had the same size, the kernel-object framework managed both objects types through the same allocator instance. This is caused by the use of unsynchronized singletons in the accessor functions and can be avoided by creating new types through inheritance instead of using typedefs. Anyways, this fix is a little bit ugly and should replaced by avoiding the use of unsynchronized singletons in the future. fix #906 --- base-hw/src/core/kernel.cc | 6 +++--- base-hw/src/core/kernel/object.h | 16 ++++++++++------ base-hw/src/core/kernel/pd.h | 6 +++--- base-hw/src/core/kernel/signal_receiver.h | 13 +++++++------ base-hw/src/core/kernel/thread.h | 6 +++--- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/base-hw/src/core/kernel.cc b/base-hw/src/core/kernel.cc index c0cd09a240..ab41e5861e 100644 --- a/base-hw/src/core/kernel.cc +++ b/base-hw/src/core/kernel.cc @@ -102,13 +102,13 @@ namespace Kernel namespace Kernel { class Vm; - typedef Id_allocator Vm_ids; - typedef Object_pool Vm_pool; + class Vm_ids : public Id_allocator { }; + typedef Object_pool Vm_pool; Vm_ids * vm_ids(); Vm_pool * vm_pool(); - class Vm : public Object, + class Vm : public Object, public Execution_context { private: diff --git a/base-hw/src/core/kernel/object.h b/base-hw/src/core/kernel/object.h index 2b2b018c62..407d4bdf2a 100644 --- a/base-hw/src/core/kernel/object.h +++ b/base-hw/src/core/kernel/object.h @@ -52,10 +52,15 @@ namespace Kernel * \param MAX_INSTANCES max amount of coincidently living objects * \param ID_ALLOC accessor function of object-name allocator * \param POOL accessor function of object pool + * + * FIXME: Most of the bother with template parameters regarding ID + * allocator and object pool is caused by the use of + * unsynchronized singletons. By avoiding the use of + * unsynchronized singletons one can at least remove + * ID_ALLOC_T. */ - template * (*ID_ALLOC)(), - Kernel::Object_pool * (* POOL)()> + template * (* POOL)()> class Object; } @@ -198,9 +203,8 @@ class Kernel::Id_allocator } }; -template * (* ID_ALLOC)(), - Kernel::Object_pool * (* POOL)()> +template * (* POOL)()> class Kernel::Object : public Object_pool::Item { diff --git a/base-hw/src/core/kernel/pd.h b/base-hw/src/core/kernel/pd.h index 9f0e2bd3cb..54074f1e92 100644 --- a/base-hw/src/core/kernel/pd.h +++ b/base-hw/src/core/kernel/pd.h @@ -54,8 +54,8 @@ namespace Kernel */ class Pd; - typedef Id_allocator Pd_ids; - typedef Object_pool Pd_pool; + class Pd_ids : public Id_allocator { }; + typedef Object_pool Pd_pool; Pd_ids * pd_ids(); Pd_pool * pd_pool(); @@ -144,7 +144,7 @@ class Kernel::Mode_transition_control } }; -class Kernel::Pd : public Object +class Kernel::Pd : public Object { private: diff --git a/base-hw/src/core/kernel/signal_receiver.h b/base-hw/src/core/kernel/signal_receiver.h index 72d9e51dd0..96c37ae2d5 100644 --- a/base-hw/src/core/kernel/signal_receiver.h +++ b/base-hw/src/core/kernel/signal_receiver.h @@ -49,10 +49,10 @@ namespace Kernel */ class Signal_receiver; - typedef Id_allocator Signal_context_ids; - typedef Object_pool Signal_context_pool; - typedef Id_allocator Signal_receiver_ids; - typedef Object_pool Signal_receiver_pool; + class Signal_context_ids : public Id_allocator { }; + class Signal_receiver_ids : public Id_allocator { }; + typedef Object_pool Signal_context_pool; + typedef Object_pool Signal_receiver_pool; Signal_context_ids * signal_context_ids(); Signal_context_pool * signal_context_pool(); @@ -194,7 +194,7 @@ class Kernel::Signal_receiver_killer class Kernel::Signal_context : public Object + Signal_context_ids, signal_context_ids, signal_context_pool> { friend class Signal_receiver; friend class Signal_context_killer; @@ -313,7 +313,8 @@ class Kernel::Signal_context class Kernel::Signal_receiver : public Object, + Signal_receiver_ids, signal_receiver_ids, + signal_receiver_pool>, public Signal_context_killer { friend class Signal_context; diff --git a/base-hw/src/core/kernel/thread.h b/base-hw/src/core/kernel/thread.h index 04721fd959..d564d821c2 100644 --- a/base-hw/src/core/kernel/thread.h +++ b/base-hw/src/core/kernel/thread.h @@ -58,8 +58,8 @@ namespace Kernel */ class Thread; - typedef Id_allocator Thread_ids; - typedef Object_pool Thread_pool; + class Thread_ids : public Id_allocator { }; + typedef Object_pool Thread_pool; Thread_ids * thread_ids(); Thread_pool * thread_pool(); @@ -91,7 +91,7 @@ class Kernel::Execution_context : public Cpu_scheduler::Item class Kernel::Thread : public Cpu::User_context, - public Object, + public Object, public Execution_context, public Ipc_node, public Irq_receiver,