Browse Source

fixed the coding style in object.c

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2521 bbd45198-f89e-11dd-88c7-29a3b14d5316
dzzxzz@gmail.com 12 years ago
parent
commit
a6b4440643
1 changed files with 163 additions and 154 deletions
  1. 163 154
      src/object.c

+ 163 - 154
src/object.c

@@ -20,49 +20,49 @@
 #include <rtthread.h>
 #include <rthw.h>
 
-#define _OBJ_CONTAINER_LIST_INIT(c) 	\
-	{&(rt_object_container[c].object_list), &(rt_object_container[c].object_list)}
+#define _OBJ_CONTAINER_LIST_INIT(c)     \
+    {&(rt_object_container[c].object_list), &(rt_object_container[c].object_list)}
 struct rt_object_information rt_object_container[RT_Object_Class_Unknown] =
 {
-	/* initialize object container - thread */
-	{RT_Object_Class_Thread, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Thread), sizeof(struct rt_thread)},
+    /* initialize object container - thread */
+    {RT_Object_Class_Thread, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Thread), sizeof(struct rt_thread)},
 #ifdef RT_USING_SEMAPHORE
-	/* initialize object container - semaphore */
-	{RT_Object_Class_Semaphore, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Semaphore), sizeof(struct rt_semaphore)},
+    /* initialize object container - semaphore */
+    {RT_Object_Class_Semaphore, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Semaphore), sizeof(struct rt_semaphore)},
 #endif
 #ifdef RT_USING_MUTEX
-	/* initialize object container - mutex */
-	{RT_Object_Class_Mutex, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Mutex), sizeof(struct rt_mutex)},
+    /* initialize object container - mutex */
+    {RT_Object_Class_Mutex, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Mutex), sizeof(struct rt_mutex)},
 #endif
 #ifdef RT_USING_EVENT
-	/* initialize object container - event */
-	{RT_Object_Class_Event, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Event), sizeof(struct rt_event)},
+    /* initialize object container - event */
+    {RT_Object_Class_Event, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Event), sizeof(struct rt_event)},
 #endif
 #ifdef RT_USING_MAILBOX
-	/* initialize object container - mailbox */
-	{RT_Object_Class_MailBox, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MailBox), sizeof(struct rt_mailbox)},
+    /* initialize object container - mailbox */
+    {RT_Object_Class_MailBox, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MailBox), sizeof(struct rt_mailbox)},
 #endif
 #ifdef RT_USING_MESSAGEQUEUE
-	/* initialize object container - message queue */
-	{RT_Object_Class_MessageQueue, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MessageQueue), sizeof(struct rt_messagequeue)},
+    /* initialize object container - message queue */
+    {RT_Object_Class_MessageQueue, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MessageQueue), sizeof(struct rt_messagequeue)},
 #endif
 #ifdef RT_USING_MEMHEAP
-	/* initialize object container - memory heap */
-	{RT_Object_Class_MemHeap, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MemHeap), sizeof(struct rt_memheap)},
+    /* initialize object container - memory heap */
+    {RT_Object_Class_MemHeap, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MemHeap), sizeof(struct rt_memheap)},
 #endif
 #ifdef RT_USING_MEMPOOL
-	/* initialize object container - memory pool */
-	{RT_Object_Class_MemPool, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MemPool), sizeof(struct rt_mempool)},
+    /* initialize object container - memory pool */
+    {RT_Object_Class_MemPool, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MemPool), sizeof(struct rt_mempool)},
 #endif
 #ifdef RT_USING_DEVICE
-	/* initialize object container - device */
-	{RT_Object_Class_Device, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Device), sizeof(struct rt_device)},
+    /* initialize object container - device */
+    {RT_Object_Class_Device, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Device), sizeof(struct rt_device)},
 #endif
-	/* initialize object container - timer */
-	{RT_Object_Class_Timer, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Timer), sizeof(struct rt_timer)},
+    /* initialize object container - timer */
+    {RT_Object_Class_Timer, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Timer), sizeof(struct rt_timer)},
 #ifdef RT_USING_MODULE
-	/* initialize object container - module */
-	{RT_Object_Class_Module, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Module), sizeof(struct rt_module)},
+    /* initialize object container - module */
+    {RT_Object_Class_Module, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Module), sizeof(struct rt_module)},
 #endif
 };
 
@@ -87,7 +87,7 @@ void (*rt_object_put_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))
  */
 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))
  */
 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))
  */
 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))
  */
 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)
  * @param type the type of object
  * @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);
 
 /**
- * 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 type the object type.
  * @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;
-	struct rt_object_information *information;
+    register rt_base_t temp;
+    struct rt_object_information *information;
 
 #ifdef RT_USING_MODULE
-	/* get module object information */
-	information = (rt_module_self() != RT_NULL) ? 
-		&rt_module_self()->module_object[type] : &rt_object_container[type];
+    /* get module object information */
+    information = (rt_module_self() != RT_NULL) ? 
+        &rt_module_self()->module_object[type] : &rt_object_container[type];
 #else
-	/* get object information */
-	information = &rt_object_container[type];
+    /* get object information */
+    information = &rt_object_container[type];
 #endif
 
-	/* initialize object's parameters */
+    /* initialize object's parameters */
 
-	/* set object type to static */
-	object->type = type | RT_Object_Class_Static;
+    /* set object type to static */
+    object->type = type | RT_Object_Class_Static;
 
-	/* copy name */
-	rt_strncpy(object->name, name, RT_NAME_MAX);
+    /* copy name */
+    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 */
-	temp = rt_hw_interrupt_disable();
+    /* lock interrupt */
+    temp = rt_hw_interrupt_disable();
 
-	/* insert object into information object list */
-	rt_list_insert_after(&(information->object_list), &(object->list));
+    /* insert object into information object list */
+    rt_list_insert_after(&(information->object_list), &(object->list));
 
-	/* unlock interrupt */
-	rt_hw_interrupt_enable(temp);
+    /* unlock interrupt */
+    rt_hw_interrupt_enable(temp);
 }
 
 /**
@@ -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)
 {
-	register rt_base_t temp;
+    register rt_base_t temp;
 
-	/* object check */
-	RT_ASSERT(object != RT_NULL);
+    /* object check */
+    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 */
-	temp = rt_hw_interrupt_disable();
+    /* lock interrupt */
+    temp = rt_hw_interrupt_disable();
 
-	/* remove from old list */
-	rt_list_remove(&(object->list));
+    /* remove from old list */
+    rt_list_remove(&(object->list));
 
-	/* unlock interrupt */
-	rt_hw_interrupt_enable(temp);
+    /* unlock interrupt */
+    rt_hw_interrupt_enable(temp);
 }
 
 #ifdef RT_USING_HEAP
@@ -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)
 {
-	struct rt_object *object;
-	register rt_base_t temp;
-	struct rt_object_information *information;
+    struct rt_object *object;
+    register rt_base_t temp;
+    struct rt_object_information *information;
 
-	RT_DEBUG_NOT_IN_INTERRUPT;
+    RT_DEBUG_NOT_IN_INTERRUPT;
 
 #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)) ? 
-		&rt_module_self()->module_object[type] : &rt_object_container[type];
+    /*
+     * get module object information,
+     * 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
-	/* get object information */
-	information = &rt_object_container[type];
+    /* get object information */
+    information = &rt_object_container[type];
 #endif
 
-	object = (struct rt_object *)rt_malloc(information->object_size);
-	if (object == RT_NULL)
-	{
-		/* no memory can be allocated */
-		return RT_NULL;
-	}
-	
-	/* initialize object's parameters */
+    object = (struct rt_object *)rt_malloc(information->object_size);
+    if (object == RT_NULL)
+    {
+        /* no memory can be allocated */
+        return RT_NULL;
+    }
+    
+    /* initialize object's parameters */
 
-	/* set object type */
-	object->type = type;
+    /* set object type */
+    object->type = type;
 
-	/* set object flag */
-	object->flag = 0;
+    /* set object flag */
+    object->flag = 0;
 
 #ifdef RT_USING_MODULE
-	if (rt_module_self() != RT_NULL)
-	{
-		object->flag |= RT_OBJECT_FLAG_MODULE;
-	}
-	object->module_id = (void *)rt_module_self();
+    if (rt_module_self() != RT_NULL)
+    {
+        object->flag |= RT_OBJECT_FLAG_MODULE;
+    }
+    object->module_id = (void *)rt_module_self();
 #endif
 
-	/* copy name */
-	rt_strncpy(object->name, name, RT_NAME_MAX);
+    /* copy name */
+    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 */
-	temp = rt_hw_interrupt_disable();
+    /* lock interrupt */
+    temp = rt_hw_interrupt_disable();
 
-	/* insert object into information object list */
-	rt_list_insert_after(&(information->object_list), &(object->list));
+    /* insert object into information object list */
+    rt_list_insert_after(&(information->object_list), &(object->list));
 
-	/* unlock interrupt */
-	rt_hw_interrupt_enable(temp);
+    /* unlock interrupt */
+    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)
  */
 void rt_object_delete(rt_object_t object)
 {
-	register rt_base_t temp;
+    register rt_base_t temp;
 
-	/* object check */
-	RT_ASSERT(object != RT_NULL);
-	RT_ASSERT(!(object->type & RT_Object_Class_Static));
+    /* object check */
+    RT_ASSERT(object != RT_NULL);
+    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 */
-	temp = rt_hw_interrupt_disable();
+    /* lock interrupt */
+    temp = rt_hw_interrupt_disable();
 
-	/* remove from old list */
-	rt_list_remove(&(object->list));
+    /* remove from old list */
+    rt_list_remove(&(object->list));
 
-	/* unlock interrupt */
-	rt_hw_interrupt_enable(temp);
+    /* unlock interrupt */
+    rt_hw_interrupt_enable(temp);
 
 #if defined(RT_USING_MODULE) && defined(RT_USING_SLAB)
-	if (object->flag & RT_OBJECT_FLAG_MODULE) 
-		rt_module_free((rt_module_t)object->module_id, object);
-	else
+    if (object->flag & RT_OBJECT_FLAG_MODULE) 
+        rt_module_free((rt_module_t)object->module_id, object);
+    else
 #endif
 
-	/* free the memory of object */
-	rt_free(object);
+    /* free the memory of object */
+    rt_free(object);
 }
 #endif
 
@@ -361,13 +368,13 @@ void rt_object_delete(rt_object_t object)
  */
 rt_bool_t rt_object_is_systemobject(rt_object_t object)
 {
-	/* object check */
-	RT_ASSERT(object != RT_NULL);
+    /* object check */
+    RT_ASSERT(object != RT_NULL);
 
-	if (object->type & RT_Object_Class_Static)
-		return RT_TRUE;
+    if (object->type & RT_Object_Class_Static)
+        return RT_TRUE;
 
-	return RT_FALSE;
+    return RT_FALSE;
 }
 
 /**
@@ -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)
 {
-	struct rt_object *object;
-	struct rt_list_node *node;
-	struct rt_object_information *information;
-	extern volatile rt_uint8_t rt_interrupt_nest;
-
-	/* parameter check */
-	if ((name == RT_NULL) || (type > RT_Object_Class_Unknown))
-		return RT_NULL;
-
-	/* which is invoke in interrupt status */
-	if (rt_interrupt_nest != 0)
-		RT_ASSERT(0);
-
-	/* enter critical */
-	rt_enter_critical();
-
-	/* try to find object */
-	information = &rt_object_container[type];
-	for (node = information->object_list.next; node != &(information->object_list); node = node->next)
-	{
-		object = rt_list_entry(node, struct rt_object, list);
-		if (rt_strncmp(object->name, name, RT_NAME_MAX) == 0)
-		{
-			/* leave critical */
-			rt_exit_critical();
-
-			return object;
-		}
-	}
-
-	/* leave critical */
-	rt_exit_critical();
-
-	return RT_NULL;
+    struct rt_object *object;
+    struct rt_list_node *node;
+    struct rt_object_information *information;
+    extern volatile rt_uint8_t rt_interrupt_nest;
+
+    /* parameter check */
+    if ((name == RT_NULL) || (type > RT_Object_Class_Unknown))
+        return RT_NULL;
+
+    /* which is invoke in interrupt status */
+    if (rt_interrupt_nest != 0)
+        RT_ASSERT(0);
+
+    /* enter critical */
+    rt_enter_critical();
+
+    /* try to find object */
+    information = &rt_object_container[type];
+    for (node  = information->object_list.next;
+         node != &(information->object_list);
+         node  = node->next)
+    {
+        object = rt_list_entry(node, struct rt_object, list);
+        if (rt_strncmp(object->name, name, RT_NAME_MAX) == 0)
+        {
+            /* leave critical */
+            rt_exit_critical();
+
+            return object;
+        }
+    }
+
+    /* leave critical */
+    rt_exit_critical();
+
+    return RT_NULL;
 }
 
 /*@}*/