Merge pull request #2511 from BernardXiong/fix_object
[WIP][Kernel] Add object re-initialization check.
This commit is contained in:
commit
25186f3e19
20
src/object.c
20
src/object.c
|
@ -240,6 +240,7 @@ void rt_object_init(struct rt_object *object,
|
||||||
const char *name)
|
const char *name)
|
||||||
{
|
{
|
||||||
register rt_base_t temp;
|
register rt_base_t temp;
|
||||||
|
struct rt_list_node *node = RT_NULL;
|
||||||
struct rt_object_information *information;
|
struct rt_object_information *information;
|
||||||
#ifdef RT_USING_MODULE
|
#ifdef RT_USING_MODULE
|
||||||
struct rt_dlmodule *module = dlmodule_self();
|
struct rt_dlmodule *module = dlmodule_self();
|
||||||
|
@ -249,11 +250,26 @@ void rt_object_init(struct rt_object *object,
|
||||||
information = rt_object_get_information(type);
|
information = rt_object_get_information(type);
|
||||||
RT_ASSERT(information != RT_NULL);
|
RT_ASSERT(information != RT_NULL);
|
||||||
|
|
||||||
/* initialize object's parameters */
|
/* check object type to avoid re-initialization */
|
||||||
|
|
||||||
|
/* enter critical */
|
||||||
|
rt_enter_critical();
|
||||||
|
/* try to find object */
|
||||||
|
for (node = information->object_list.next;
|
||||||
|
node != &(information->object_list);
|
||||||
|
node = node->next)
|
||||||
|
{
|
||||||
|
struct rt_object *obj;
|
||||||
|
|
||||||
|
obj = rt_list_entry(node, struct rt_object, list);
|
||||||
|
RT_ASSERT(obj != object);
|
||||||
|
}
|
||||||
|
/* leave critical */
|
||||||
|
rt_exit_critical();
|
||||||
|
|
||||||
|
/* initialize object's parameters */
|
||||||
/* set object type to static */
|
/* set object type to static */
|
||||||
object->type = type | RT_Object_Class_Static;
|
object->type = type | RT_Object_Class_Static;
|
||||||
|
|
||||||
/* copy name */
|
/* copy name */
|
||||||
rt_strncpy(object->name, name, RT_NAME_MAX);
|
rt_strncpy(object->name, name, RT_NAME_MAX);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue