提交 a6b44406 编写于 作者: D dzzxzz@gmail.com

fixed the coding style in object.c

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2521 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 1cffb60c
...@@ -20,49 +20,49 @@ ...@@ -20,49 +20,49 @@
#include <rtthread.h> #include <rtthread.h>
#include <rthw.h> #include <rthw.h>
#define _OBJ_CONTAINER_LIST_INIT(c) \ #define _OBJ_CONTAINER_LIST_INIT(c) \
{&(rt_object_container[c].object_list), &(rt_object_container[c].object_list)} {&(rt_object_container[c].object_list), &(rt_object_container[c].object_list)}
struct rt_object_information rt_object_container[RT_Object_Class_Unknown] = struct rt_object_information rt_object_container[RT_Object_Class_Unknown] =
{ {
/* initialize object container - thread */ /* initialize object container - thread */
{RT_Object_Class_Thread, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Thread), sizeof(struct rt_thread)}, {RT_Object_Class_Thread, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Thread), sizeof(struct rt_thread)},
#ifdef RT_USING_SEMAPHORE #ifdef RT_USING_SEMAPHORE
/* initialize object container - semaphore */ /* initialize object container - semaphore */
{RT_Object_Class_Semaphore, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Semaphore), sizeof(struct rt_semaphore)}, {RT_Object_Class_Semaphore, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Semaphore), sizeof(struct rt_semaphore)},
#endif #endif
#ifdef RT_USING_MUTEX #ifdef RT_USING_MUTEX
/* initialize object container - mutex */ /* initialize object container - mutex */
{RT_Object_Class_Mutex, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Mutex), sizeof(struct rt_mutex)}, {RT_Object_Class_Mutex, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Mutex), sizeof(struct rt_mutex)},
#endif #endif
#ifdef RT_USING_EVENT #ifdef RT_USING_EVENT
/* initialize object container - event */ /* initialize object container - event */
{RT_Object_Class_Event, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Event), sizeof(struct rt_event)}, {RT_Object_Class_Event, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Event), sizeof(struct rt_event)},
#endif #endif
#ifdef RT_USING_MAILBOX #ifdef RT_USING_MAILBOX
/* initialize object container - mailbox */ /* initialize object container - mailbox */
{RT_Object_Class_MailBox, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MailBox), sizeof(struct rt_mailbox)}, {RT_Object_Class_MailBox, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MailBox), sizeof(struct rt_mailbox)},
#endif #endif
#ifdef RT_USING_MESSAGEQUEUE #ifdef RT_USING_MESSAGEQUEUE
/* initialize object container - message queue */ /* initialize object container - message queue */
{RT_Object_Class_MessageQueue, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MessageQueue), sizeof(struct rt_messagequeue)}, {RT_Object_Class_MessageQueue, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MessageQueue), sizeof(struct rt_messagequeue)},
#endif #endif
#ifdef RT_USING_MEMHEAP #ifdef RT_USING_MEMHEAP
/* initialize object container - memory heap */ /* initialize object container - memory heap */
{RT_Object_Class_MemHeap, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MemHeap), sizeof(struct rt_memheap)}, {RT_Object_Class_MemHeap, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MemHeap), sizeof(struct rt_memheap)},
#endif #endif
#ifdef RT_USING_MEMPOOL #ifdef RT_USING_MEMPOOL
/* initialize object container - memory pool */ /* initialize object container - memory pool */
{RT_Object_Class_MemPool, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MemPool), sizeof(struct rt_mempool)}, {RT_Object_Class_MemPool, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MemPool), sizeof(struct rt_mempool)},
#endif #endif
#ifdef RT_USING_DEVICE #ifdef RT_USING_DEVICE
/* initialize object container - device */ /* initialize object container - device */
{RT_Object_Class_Device, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Device), sizeof(struct rt_device)}, {RT_Object_Class_Device, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Device), sizeof(struct rt_device)},
#endif #endif
/* initialize object container - timer */ /* initialize object container - timer */
{RT_Object_Class_Timer, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Timer), sizeof(struct rt_timer)}, {RT_Object_Class_Timer, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Timer), sizeof(struct rt_timer)},
#ifdef RT_USING_MODULE #ifdef RT_USING_MODULE
/* initialize object container - module */ /* initialize object container - module */
{RT_Object_Class_Module, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Module), sizeof(struct rt_module)}, {RT_Object_Class_Module, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Module), sizeof(struct rt_module)},
#endif #endif
}; };
...@@ -87,7 +87,7 @@ void (*rt_object_put_hook)(struct rt_object *object); ...@@ -87,7 +87,7 @@ void (*rt_object_put_hook)(struct rt_object *object);
*/ */
void rt_object_attach_sethook(void (*hook)(struct rt_object *object)) void rt_object_attach_sethook(void (*hook)(struct rt_object *object))
{ {
rt_object_attach_hook = hook; rt_object_attach_hook = hook;
} }
/** /**
...@@ -98,7 +98,7 @@ void rt_object_attach_sethook(void (*hook)(struct rt_object *object)) ...@@ -98,7 +98,7 @@ void rt_object_attach_sethook(void (*hook)(struct rt_object *object))
*/ */
void rt_object_detach_sethook(void (*hook)(struct rt_object *object)) void rt_object_detach_sethook(void (*hook)(struct rt_object *object))
{ {
rt_object_detach_hook = hook; rt_object_detach_hook = hook;
} }
/** /**
...@@ -116,7 +116,7 @@ void rt_object_detach_sethook(void (*hook)(struct rt_object *object)) ...@@ -116,7 +116,7 @@ void rt_object_detach_sethook(void (*hook)(struct rt_object *object))
*/ */
void rt_object_trytake_sethook(void (*hook)(struct rt_object *object)) void rt_object_trytake_sethook(void (*hook)(struct rt_object *object))
{ {
rt_object_trytake_hook = hook; rt_object_trytake_hook = hook;
} }
/** /**
...@@ -135,7 +135,7 @@ void rt_object_trytake_sethook(void (*hook)(struct rt_object *object)) ...@@ -135,7 +135,7 @@ void rt_object_trytake_sethook(void (*hook)(struct rt_object *object))
*/ */
void rt_object_take_sethook(void (*hook)(struct rt_object *object)) void rt_object_take_sethook(void (*hook)(struct rt_object *object))
{ {
rt_object_take_hook = hook; rt_object_take_hook = hook;
} }
/** /**
...@@ -146,7 +146,7 @@ void rt_object_take_sethook(void (*hook)(struct rt_object *object)) ...@@ -146,7 +146,7 @@ void rt_object_take_sethook(void (*hook)(struct rt_object *object))
*/ */
void rt_object_put_sethook(void (*hook)(struct rt_object *object)) void rt_object_put_sethook(void (*hook)(struct rt_object *object))
{ {
rt_object_put_hook = hook; rt_object_put_hook = hook;
} }
/*@}*/ /*@}*/
...@@ -176,51 +176,55 @@ void rt_system_object_init(void) ...@@ -176,51 +176,55 @@ void rt_system_object_init(void)
* @param type the type of object * @param type the type of object
* @return the object type information or RT_NULL * @return the object type information or RT_NULL
*/ */
struct rt_object_information *rt_object_get_information(enum rt_object_class_type type) struct rt_object_information *
rt_object_get_information(enum rt_object_class_type type)
{ {
return &rt_object_container[type]; return &rt_object_container[type];
} }
RTM_EXPORT(rt_object_get_information); RTM_EXPORT(rt_object_get_information);
/** /**
* This function will initialize an object and add it to object system management. * This function will initialize an object and add it to object system
* management.
* *
* @param object the specified object to be initialized. * @param object the specified object to be initialized.
* @param type the object type. * @param type the object type.
* @param name the object name. In system, the object's name must be unique. * @param name the object name. In system, the object's name must be unique.
*/ */
void rt_object_init(struct rt_object *object, enum rt_object_class_type type, const char *name) void rt_object_init(struct rt_object *object,
enum rt_object_class_type type,
const char *name)
{ {
register rt_base_t temp; register rt_base_t temp;
struct rt_object_information *information; struct rt_object_information *information;
#ifdef RT_USING_MODULE #ifdef RT_USING_MODULE
/* get module object information */ /* get module object information */
information = (rt_module_self() != RT_NULL) ? information = (rt_module_self() != RT_NULL) ?
&rt_module_self()->module_object[type] : &rt_object_container[type]; &rt_module_self()->module_object[type] : &rt_object_container[type];
#else #else
/* get object information */ /* get object information */
information = &rt_object_container[type]; information = &rt_object_container[type];
#endif #endif
/* initialize object's parameters */ /* 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);
RT_OBJECT_HOOK_CALL(rt_object_attach_hook, (object)); RT_OBJECT_HOOK_CALL(rt_object_attach_hook, (object));
/* lock interrupt */ /* lock interrupt */
temp = rt_hw_interrupt_disable(); temp = rt_hw_interrupt_disable();
/* insert object into information object list */ /* insert object into information object list */
rt_list_insert_after(&(information->object_list), &(object->list)); rt_list_insert_after(&(information->object_list), &(object->list));
/* unlock interrupt */ /* unlock interrupt */
rt_hw_interrupt_enable(temp); rt_hw_interrupt_enable(temp);
} }
/** /**
...@@ -231,21 +235,21 @@ void rt_object_init(struct rt_object *object, enum rt_object_class_type type, co ...@@ -231,21 +235,21 @@ void rt_object_init(struct rt_object *object, enum rt_object_class_type type, co
*/ */
void rt_object_detach(rt_object_t object) void rt_object_detach(rt_object_t object)
{ {
register rt_base_t temp; register rt_base_t temp;
/* object check */ /* object check */
RT_ASSERT(object != RT_NULL); RT_ASSERT(object != RT_NULL);
RT_OBJECT_HOOK_CALL(rt_object_detach_hook, (object)); RT_OBJECT_HOOK_CALL(rt_object_detach_hook, (object));
/* lock interrupt */ /* lock interrupt */
temp = rt_hw_interrupt_disable(); temp = rt_hw_interrupt_disable();
/* remove from old list */ /* remove from old list */
rt_list_remove(&(object->list)); rt_list_remove(&(object->list));
/* unlock interrupt */ /* unlock interrupt */
rt_hw_interrupt_enable(temp); rt_hw_interrupt_enable(temp);
} }
#ifdef RT_USING_HEAP #ifdef RT_USING_HEAP
...@@ -259,60 +263,63 @@ void rt_object_detach(rt_object_t object) ...@@ -259,60 +263,63 @@ void rt_object_detach(rt_object_t object)
*/ */
rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name) rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name)
{ {
struct rt_object *object; struct rt_object *object;
register rt_base_t temp; register rt_base_t temp;
struct rt_object_information *information; struct rt_object_information *information;
RT_DEBUG_NOT_IN_INTERRUPT; RT_DEBUG_NOT_IN_INTERRUPT;
#ifdef RT_USING_MODULE #ifdef RT_USING_MODULE
/* get module object information, module object should be managed by kernel object container */ /*
information = (rt_module_self() != RT_NULL && (type != RT_Object_Class_Module)) ? * get module object information,
&rt_module_self()->module_object[type] : &rt_object_container[type]; * module object should be managed by kernel object container
*/
information = (rt_module_self() != RT_NULL && (type != RT_Object_Class_Module)) ?
&rt_module_self()->module_object[type] : &rt_object_container[type];
#else #else
/* get object information */ /* get object information */
information = &rt_object_container[type]; information = &rt_object_container[type];
#endif #endif
object = (struct rt_object *)rt_malloc(information->object_size); object = (struct rt_object *)rt_malloc(information->object_size);
if (object == RT_NULL) if (object == RT_NULL)
{ {
/* no memory can be allocated */ /* no memory can be allocated */
return RT_NULL; return RT_NULL;
} }
/* initialize object's parameters */ /* initialize object's parameters */
/* set object type */ /* set object type */
object->type = type; object->type = type;
/* set object flag */ /* set object flag */
object->flag = 0; object->flag = 0;
#ifdef RT_USING_MODULE #ifdef RT_USING_MODULE
if (rt_module_self() != RT_NULL) if (rt_module_self() != RT_NULL)
{ {
object->flag |= RT_OBJECT_FLAG_MODULE; object->flag |= RT_OBJECT_FLAG_MODULE;
} }
object->module_id = (void *)rt_module_self(); object->module_id = (void *)rt_module_self();
#endif #endif
/* copy name */ /* copy name */
rt_strncpy(object->name, name, RT_NAME_MAX); rt_strncpy(object->name, name, RT_NAME_MAX);
RT_OBJECT_HOOK_CALL(rt_object_attach_hook, (object)); RT_OBJECT_HOOK_CALL(rt_object_attach_hook, (object));
/* lock interrupt */ /* lock interrupt */
temp = rt_hw_interrupt_disable(); temp = rt_hw_interrupt_disable();
/* insert object into information object list */ /* insert object into information object list */
rt_list_insert_after(&(information->object_list), &(object->list)); rt_list_insert_after(&(information->object_list), &(object->list));
/* unlock interrupt */ /* unlock interrupt */
rt_hw_interrupt_enable(temp); rt_hw_interrupt_enable(temp);
/* return object */ /* return object */
return object; return object;
} }
/** /**
...@@ -322,31 +329,31 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name) ...@@ -322,31 +329,31 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name)
*/ */
void rt_object_delete(rt_object_t object) void rt_object_delete(rt_object_t object)
{ {
register rt_base_t temp; register rt_base_t temp;
/* object check */ /* object check */
RT_ASSERT(object != RT_NULL); RT_ASSERT(object != RT_NULL);
RT_ASSERT(!(object->type & RT_Object_Class_Static)); RT_ASSERT(!(object->type & RT_Object_Class_Static));
RT_OBJECT_HOOK_CALL(rt_object_detach_hook, (object)); RT_OBJECT_HOOK_CALL(rt_object_detach_hook, (object));
/* lock interrupt */ /* lock interrupt */
temp = rt_hw_interrupt_disable(); temp = rt_hw_interrupt_disable();
/* remove from old list */ /* remove from old list */
rt_list_remove(&(object->list)); rt_list_remove(&(object->list));
/* unlock interrupt */ /* unlock interrupt */
rt_hw_interrupt_enable(temp); rt_hw_interrupt_enable(temp);
#if defined(RT_USING_MODULE) && defined(RT_USING_SLAB) #if defined(RT_USING_MODULE) && defined(RT_USING_SLAB)
if (object->flag & RT_OBJECT_FLAG_MODULE) if (object->flag & RT_OBJECT_FLAG_MODULE)
rt_module_free((rt_module_t)object->module_id, object); rt_module_free((rt_module_t)object->module_id, object);
else else
#endif #endif
/* free the memory of object */ /* free the memory of object */
rt_free(object); rt_free(object);
} }
#endif #endif
...@@ -361,13 +368,13 @@ void rt_object_delete(rt_object_t object) ...@@ -361,13 +368,13 @@ void rt_object_delete(rt_object_t object)
*/ */
rt_bool_t rt_object_is_systemobject(rt_object_t object) rt_bool_t rt_object_is_systemobject(rt_object_t object)
{ {
/* object check */ /* object check */
RT_ASSERT(object != RT_NULL); RT_ASSERT(object != RT_NULL);
if (object->type & RT_Object_Class_Static) if (object->type & RT_Object_Class_Static)
return RT_TRUE; return RT_TRUE;
return RT_FALSE; return RT_FALSE;
} }
/** /**
...@@ -384,40 +391,42 @@ rt_bool_t rt_object_is_systemobject(rt_object_t object) ...@@ -384,40 +391,42 @@ rt_bool_t rt_object_is_systemobject(rt_object_t object)
*/ */
rt_object_t rt_object_find(const char *name, rt_uint8_t type) rt_object_t rt_object_find(const char *name, rt_uint8_t type)
{ {
struct rt_object *object; struct rt_object *object;
struct rt_list_node *node; struct rt_list_node *node;
struct rt_object_information *information; struct rt_object_information *information;
extern volatile rt_uint8_t rt_interrupt_nest; extern volatile rt_uint8_t rt_interrupt_nest;
/* parameter check */ /* parameter check */
if ((name == RT_NULL) || (type > RT_Object_Class_Unknown)) if ((name == RT_NULL) || (type > RT_Object_Class_Unknown))
return RT_NULL; return RT_NULL;
/* which is invoke in interrupt status */ /* which is invoke in interrupt status */
if (rt_interrupt_nest != 0) if (rt_interrupt_nest != 0)
RT_ASSERT(0); RT_ASSERT(0);
/* enter critical */ /* enter critical */
rt_enter_critical(); rt_enter_critical();
/* try to find object */ /* try to find object */
information = &rt_object_container[type]; information = &rt_object_container[type];
for (node = information->object_list.next; node != &(information->object_list); node = node->next) for (node = information->object_list.next;
{ node != &(information->object_list);
object = rt_list_entry(node, struct rt_object, list); node = node->next)
if (rt_strncmp(object->name, name, RT_NAME_MAX) == 0) {
{ object = rt_list_entry(node, struct rt_object, list);
/* leave critical */ if (rt_strncmp(object->name, name, RT_NAME_MAX) == 0)
rt_exit_critical(); {
/* leave critical */
return object; rt_exit_critical();
}
} return object;
}
/* leave critical */ }
rt_exit_critical();
/* leave critical */
return RT_NULL; rt_exit_critical();
return RT_NULL;
} }
/*@}*/ /*@}*/
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册