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
This commit is contained in:
Martin Stein 2013-10-11 12:29:40 +02:00 committed by Christian Helmuth
parent a9651d1728
commit c56927b76e
5 changed files with 26 additions and 21 deletions

View File

@ -102,13 +102,13 @@ namespace Kernel
namespace Kernel namespace Kernel
{ {
class Vm; class Vm;
typedef Id_allocator<MAX_VMS> Vm_ids; class Vm_ids : public Id_allocator<MAX_VMS> { };
typedef Object_pool<Vm> Vm_pool; typedef Object_pool<Vm> Vm_pool;
Vm_ids * vm_ids(); Vm_ids * vm_ids();
Vm_pool * vm_pool(); Vm_pool * vm_pool();
class Vm : public Object<Vm, MAX_VMS, vm_ids, vm_pool>, class Vm : public Object<Vm, MAX_VMS, Vm_ids, vm_ids, vm_pool>,
public Execution_context public Execution_context
{ {
private: private:

View File

@ -52,10 +52,15 @@ namespace Kernel
* \param MAX_INSTANCES max amount of coincidently living objects * \param MAX_INSTANCES max amount of coincidently living objects
* \param ID_ALLOC accessor function of object-name allocator * \param ID_ALLOC accessor function of object-name allocator
* \param POOL accessor function of object pool * \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 <typename T, unsigned MAX_INSTANCES, template <typename T, unsigned MAX_INSTANCES, typename ID_ALLOC_T,
Id_allocator<MAX_INSTANCES> * (*ID_ALLOC)(), ID_ALLOC_T * (*ID_ALLOC)(), Kernel::Object_pool<T> * (* POOL)()>
Kernel::Object_pool<T> * (* POOL)()>
class Object; class Object;
} }
@ -198,9 +203,8 @@ class Kernel::Id_allocator
} }
}; };
template <typename T, unsigned MAX_INSTANCES, template <typename T, unsigned MAX_INSTANCES, typename ID_ALLOC_T,
Kernel::Id_allocator<MAX_INSTANCES> * (* ID_ALLOC)(), ID_ALLOC_T * (* ID_ALLOC)(), Kernel::Object_pool<T> * (* POOL)()>
Kernel::Object_pool<T> * (* POOL)()>
class Kernel::Object : public Object_pool<T>::Item class Kernel::Object : public Object_pool<T>::Item
{ {

View File

@ -54,7 +54,7 @@ namespace Kernel
*/ */
class Pd; class Pd;
typedef Id_allocator<MAX_PDS> Pd_ids; class Pd_ids : public Id_allocator<MAX_PDS> { };
typedef Object_pool<Pd> Pd_pool; typedef Object_pool<Pd> Pd_pool;
Pd_ids * pd_ids(); Pd_ids * pd_ids();
@ -144,7 +144,7 @@ class Kernel::Mode_transition_control
} }
}; };
class Kernel::Pd : public Object<Pd, MAX_PDS, pd_ids, pd_pool> class Kernel::Pd : public Object<Pd, MAX_PDS, Pd_ids, pd_ids, pd_pool>
{ {
private: private:

View File

@ -49,9 +49,9 @@ namespace Kernel
*/ */
class Signal_receiver; class Signal_receiver;
typedef Id_allocator<MAX_SIGNAL_CONTEXTS> Signal_context_ids; class Signal_context_ids : public Id_allocator<MAX_SIGNAL_CONTEXTS> { };
class Signal_receiver_ids : public Id_allocator<MAX_SIGNAL_RECEIVERS> { };
typedef Object_pool<Signal_context> Signal_context_pool; typedef Object_pool<Signal_context> Signal_context_pool;
typedef Id_allocator<MAX_SIGNAL_RECEIVERS> Signal_receiver_ids;
typedef Object_pool<Signal_receiver> Signal_receiver_pool; typedef Object_pool<Signal_receiver> Signal_receiver_pool;
Signal_context_ids * signal_context_ids(); Signal_context_ids * signal_context_ids();
@ -194,7 +194,7 @@ class Kernel::Signal_receiver_killer
class Kernel::Signal_context class Kernel::Signal_context
: :
public Object<Signal_context, MAX_SIGNAL_CONTEXTS, public Object<Signal_context, MAX_SIGNAL_CONTEXTS,
signal_context_ids, signal_context_pool> Signal_context_ids, signal_context_ids, signal_context_pool>
{ {
friend class Signal_receiver; friend class Signal_receiver;
friend class Signal_context_killer; friend class Signal_context_killer;
@ -313,7 +313,8 @@ class Kernel::Signal_context
class Kernel::Signal_receiver class Kernel::Signal_receiver
: :
public Object<Signal_receiver, MAX_SIGNAL_RECEIVERS, public Object<Signal_receiver, MAX_SIGNAL_RECEIVERS,
signal_receiver_ids, signal_receiver_pool>, Signal_receiver_ids, signal_receiver_ids,
signal_receiver_pool>,
public Signal_context_killer public Signal_context_killer
{ {
friend class Signal_context; friend class Signal_context;

View File

@ -58,7 +58,7 @@ namespace Kernel
*/ */
class Thread; class Thread;
typedef Id_allocator<MAX_THREADS> Thread_ids; class Thread_ids : public Id_allocator<MAX_THREADS> { };
typedef Object_pool<Thread> Thread_pool; typedef Object_pool<Thread> Thread_pool;
Thread_ids * thread_ids(); Thread_ids * thread_ids();
@ -91,7 +91,7 @@ class Kernel::Execution_context : public Cpu_scheduler::Item
class Kernel::Thread class Kernel::Thread
: :
public Cpu::User_context, public Cpu::User_context,
public Object<Thread, MAX_THREADS, thread_ids, thread_pool>, public Object<Thread, MAX_THREADS, Thread_ids, thread_ids, thread_pool>,
public Execution_context, public Execution_context,
public Ipc_node, public Ipc_node,
public Irq_receiver, public Irq_receiver,