2009-07-03 06:48:23 +08:00
|
|
|
/*
|
|
|
|
* File : object.c
|
|
|
|
* This file is part of RT-Thread RTOS
|
2012-03-17 14:43:49 +08:00
|
|
|
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
|
2009-07-03 06:48:23 +08:00
|
|
|
*
|
|
|
|
* The license and distribution terms for this file may be
|
|
|
|
* found in the file LICENSE in this distribution or at
|
2009-12-25 20:18:53 +08:00
|
|
|
* http://www.rt-thread.org/license/LICENSE
|
2009-07-03 06:48:23 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2006-03-14 Bernard the first version
|
|
|
|
* 2006-04-21 Bernard change the scheduler lock to interrupt lock
|
|
|
|
* 2006-05-18 Bernard fix the object init bug
|
|
|
|
* 2006-08-03 Bernard add hook support
|
|
|
|
* 2007-01-28 Bernard rename RT_OBJECT_Class_Static to RT_Object_Class_Static
|
2010-10-28 09:21:47 +08:00
|
|
|
* 2010-10-26 yi.qiu add module support in rt_object_allocate and rt_object_free
|
2009-07-03 06:48:23 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include <rthw.h>
|
|
|
|
|
2010-03-03 17:11:00 +08:00
|
|
|
#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] =
|
|
|
|
{
|
2010-11-29 08:04:55 +08:00
|
|
|
/* initialize object container - thread */
|
2010-03-03 17:11:00 +08:00
|
|
|
{RT_Object_Class_Thread, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Thread), sizeof(struct rt_thread)},
|
|
|
|
#ifdef RT_USING_SEMAPHORE
|
2010-11-29 08:04:55 +08:00
|
|
|
/* initialize object container - semaphore */
|
2010-03-03 17:11:00 +08:00
|
|
|
{RT_Object_Class_Semaphore, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Semaphore), sizeof(struct rt_semaphore)},
|
|
|
|
#endif
|
|
|
|
#ifdef RT_USING_MUTEX
|
2010-11-29 08:04:55 +08:00
|
|
|
/* initialize object container - mutex */
|
2010-03-03 17:11:00 +08:00
|
|
|
{RT_Object_Class_Mutex, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Mutex), sizeof(struct rt_mutex)},
|
|
|
|
#endif
|
|
|
|
#ifdef RT_USING_EVENT
|
2010-11-29 08:04:55 +08:00
|
|
|
/* initialize object container - event */
|
2010-03-03 17:11:00 +08:00
|
|
|
{RT_Object_Class_Event, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Event), sizeof(struct rt_event)},
|
|
|
|
#endif
|
|
|
|
#ifdef RT_USING_MAILBOX
|
2010-11-29 08:04:55 +08:00
|
|
|
/* initialize object container - mailbox */
|
2010-03-03 17:11:00 +08:00
|
|
|
{RT_Object_Class_MailBox, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MailBox), sizeof(struct rt_mailbox)},
|
|
|
|
#endif
|
|
|
|
#ifdef RT_USING_MESSAGEQUEUE
|
2010-11-29 08:04:55 +08:00
|
|
|
/* initialize object container - message queue */
|
2010-03-03 17:11:00 +08:00
|
|
|
{RT_Object_Class_MessageQueue, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MessageQueue), sizeof(struct rt_messagequeue)},
|
|
|
|
#endif
|
2012-04-14 11:52:56 +08:00
|
|
|
#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)},
|
|
|
|
#endif
|
2010-03-03 17:11:00 +08:00
|
|
|
#ifdef RT_USING_MEMPOOL
|
2010-11-29 08:04:55 +08:00
|
|
|
/* initialize object container - memory pool */
|
2010-03-03 17:11:00 +08:00
|
|
|
{RT_Object_Class_MemPool, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_MemPool), sizeof(struct rt_mempool)},
|
|
|
|
#endif
|
|
|
|
#ifdef RT_USING_DEVICE
|
2010-11-29 08:04:55 +08:00
|
|
|
/* initialize object container - device */
|
2010-03-03 17:11:00 +08:00
|
|
|
{RT_Object_Class_Device, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Device), sizeof(struct rt_device)},
|
|
|
|
#endif
|
2010-11-29 08:04:55 +08:00
|
|
|
/* initialize object container - timer */
|
2010-03-03 17:11:00 +08:00
|
|
|
{RT_Object_Class_Timer, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Timer), sizeof(struct rt_timer)},
|
|
|
|
#ifdef RT_USING_MODULE
|
2010-11-29 08:04:55 +08:00
|
|
|
/* initialize object container - module */
|
2010-03-03 17:11:00 +08:00
|
|
|
{RT_Object_Class_Module, _OBJ_CONTAINER_LIST_INIT(RT_Object_Class_Module), sizeof(struct rt_module)},
|
|
|
|
#endif
|
|
|
|
};
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
#ifdef RT_USING_HOOK
|
2011-09-21 11:56:42 +08:00
|
|
|
static void (*rt_object_attach_hook)(struct rt_object *object);
|
|
|
|
static void (*rt_object_detach_hook)(struct rt_object *object);
|
|
|
|
void (*rt_object_trytake_hook)(struct rt_object *object);
|
|
|
|
void (*rt_object_take_hook)(struct rt_object *object);
|
|
|
|
void (*rt_object_put_hook)(struct rt_object *object);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup Hook
|
|
|
|
*/
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/*@{*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will set a hook function, which will be invoked when object
|
|
|
|
* attaches to kernel object system.
|
2009-09-14 07:34:52 +08:00
|
|
|
*
|
2009-07-03 06:48:23 +08:00
|
|
|
* @param hook the hook function
|
|
|
|
*/
|
2011-09-21 11:56:42 +08:00
|
|
|
void rt_object_attach_sethook(void (*hook)(struct rt_object *object))
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
|
|
|
rt_object_attach_hook = hook;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will set a hook function, which will be invoked when object
|
|
|
|
* detaches from kernel object system.
|
2009-09-14 07:34:52 +08:00
|
|
|
*
|
2009-07-03 06:48:23 +08:00
|
|
|
* @param hook the hook function
|
|
|
|
*/
|
2011-09-21 11:56:42 +08:00
|
|
|
void rt_object_detach_sethook(void (*hook)(struct rt_object *object))
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
|
|
|
rt_object_detach_hook = hook;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will set a hook function, which will be invoked when object
|
|
|
|
* is taken from kernel object system.
|
2009-09-14 07:34:52 +08:00
|
|
|
*
|
2010-11-29 08:04:55 +08:00
|
|
|
* The object is taken means:
|
2009-07-03 06:48:23 +08:00
|
|
|
* semaphore - semaphore is taken by thread
|
|
|
|
* mutex - mutex is taken by thread
|
2009-09-14 07:34:52 +08:00
|
|
|
* event - event is received by thread
|
2009-07-03 06:48:23 +08:00
|
|
|
* mailbox - mail is received by thread
|
|
|
|
* message queue - message is received by thread
|
2009-09-14 07:34:52 +08:00
|
|
|
*
|
2009-07-03 06:48:23 +08:00
|
|
|
* @param hook the hook function
|
|
|
|
*/
|
2011-09-21 11:56:42 +08:00
|
|
|
void rt_object_trytake_sethook(void (*hook)(struct rt_object *object))
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
|
|
|
rt_object_trytake_hook = hook;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will set a hook function, which will be invoked when object
|
|
|
|
* have been taken from kernel object system.
|
2009-09-14 07:34:52 +08:00
|
|
|
*
|
2010-11-29 08:04:55 +08:00
|
|
|
* The object have been taken means:
|
2009-07-03 06:48:23 +08:00
|
|
|
* semaphore - semaphore have been taken by thread
|
|
|
|
* mutex - mutex have been taken by thread
|
2009-09-14 07:34:52 +08:00
|
|
|
* event - event have been received by thread
|
2009-07-03 06:48:23 +08:00
|
|
|
* mailbox - mail have been received by thread
|
|
|
|
* message queue - message have been received by thread
|
|
|
|
* timer - timer is started
|
2009-09-14 07:34:52 +08:00
|
|
|
*
|
2009-07-03 06:48:23 +08:00
|
|
|
* @param hook the hook function
|
|
|
|
*/
|
2011-09-21 11:56:42 +08:00
|
|
|
void rt_object_take_sethook(void (*hook)(struct rt_object *object))
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
|
|
|
rt_object_take_hook = hook;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will set a hook function, which will be invoked when object
|
|
|
|
* is put to kernel object system.
|
2009-09-14 07:34:52 +08:00
|
|
|
*
|
2009-07-03 06:48:23 +08:00
|
|
|
* @param hook the hook function
|
|
|
|
*/
|
2011-09-21 11:56:42 +08:00
|
|
|
void rt_object_put_sethook(void (*hook)(struct rt_object *object))
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
|
|
|
rt_object_put_hook = hook;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*@}*/
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup SystemInit
|
|
|
|
*
|
2010-11-29 08:04:55 +08:00
|
|
|
* This function will initialize system object management.
|
2009-07-03 06:48:23 +08:00
|
|
|
*
|
2010-11-29 08:04:55 +08:00
|
|
|
* @deprecated since 0.3.0, this function does not need to be invoked
|
|
|
|
* in the system initialization.
|
2009-07-03 06:48:23 +08:00
|
|
|
*/
|
|
|
|
void rt_system_object_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup KernelObject
|
|
|
|
*/
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/*@{*/
|
|
|
|
|
2011-06-15 07:59:42 +08:00
|
|
|
/**
|
|
|
|
* This function will return the specified type of object information.
|
|
|
|
*
|
|
|
|
* @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)
|
|
|
|
{
|
|
|
|
return &rt_object_container[type];
|
|
|
|
}
|
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/**
|
2010-11-29 08:04:55 +08:00
|
|
|
* This function will initialize an object and add it to object system management.
|
2009-07-03 06:48:23 +08:00
|
|
|
*
|
|
|
|
* @param object the specified object to be initialized.
|
|
|
|
* @param type the object type.
|
2010-11-29 08:04:55 +08:00
|
|
|
* @param name the object name. In system, the object's name must be unique.
|
2009-07-03 06:48:23 +08:00
|
|
|
*/
|
2011-09-21 11:56:42 +08:00
|
|
|
void rt_object_init(struct rt_object *object, enum rt_object_class_type type, const char *name)
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
|
|
|
register rt_base_t temp;
|
2011-09-23 13:57:31 +08:00
|
|
|
struct rt_object_information *information;
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2010-04-22 00:59:06 +08:00
|
|
|
#ifdef RT_USING_MODULE
|
|
|
|
/* get module object information */
|
2010-09-20 07:43:48 +08:00
|
|
|
information = (rt_module_self() != RT_NULL) ?
|
|
|
|
&rt_module_self()->module_object[type] : &rt_object_container[type];
|
2010-04-22 00:59:06 +08:00
|
|
|
#else
|
2009-07-03 06:48:23 +08:00
|
|
|
/* get object information */
|
|
|
|
information = &rt_object_container[type];
|
2010-04-22 00:59:06 +08:00
|
|
|
#endif
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2010-11-29 08:04:55 +08:00
|
|
|
/* initialize object's parameters */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
/* set object type to static */
|
|
|
|
object->type = type | RT_Object_Class_Static;
|
|
|
|
|
|
|
|
/* copy name */
|
2011-11-08 12:06:12 +08:00
|
|
|
rt_strncpy(object->name, name, RT_NAME_MAX);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2011-06-15 07:59:42 +08:00
|
|
|
RT_OBJECT_HOOK_CALL(rt_object_attach_hook, (object));
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
/* lock interrupt */
|
|
|
|
temp = rt_hw_interrupt_disable();
|
|
|
|
|
|
|
|
/* insert object into information object list */
|
|
|
|
rt_list_insert_after(&(information->object_list), &(object->list));
|
|
|
|
|
|
|
|
/* unlock interrupt */
|
|
|
|
rt_hw_interrupt_enable(temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will detach a static object from object system,
|
|
|
|
* and the memory of static object is not freed.
|
|
|
|
*
|
|
|
|
* @param object the specified object to be detached.
|
|
|
|
*/
|
|
|
|
void rt_object_detach(rt_object_t object)
|
|
|
|
{
|
|
|
|
register rt_base_t temp;
|
|
|
|
|
|
|
|
/* object check */
|
|
|
|
RT_ASSERT(object != RT_NULL);
|
|
|
|
|
2011-06-15 07:59:42 +08:00
|
|
|
RT_OBJECT_HOOK_CALL(rt_object_detach_hook, (object));
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
/* lock interrupt */
|
|
|
|
temp = rt_hw_interrupt_disable();
|
|
|
|
|
|
|
|
/* remove from old list */
|
|
|
|
rt_list_remove(&(object->list));
|
|
|
|
|
|
|
|
/* unlock interrupt */
|
|
|
|
rt_hw_interrupt_enable(temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RT_USING_HEAP
|
|
|
|
/**
|
|
|
|
* This function will allocate an object from object system
|
|
|
|
*
|
|
|
|
* @param type the type of object
|
|
|
|
* @param name the object name. In system, the object's name must be unique.
|
|
|
|
*
|
|
|
|
* @return object
|
|
|
|
*/
|
2011-09-21 11:56:42 +08:00
|
|
|
rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name)
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
2011-09-21 11:56:42 +08:00
|
|
|
struct rt_object *object;
|
2009-07-03 06:48:23 +08:00
|
|
|
register rt_base_t temp;
|
2011-09-21 11:56:42 +08:00
|
|
|
struct rt_object_information *information;
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2011-06-15 07:59:42 +08:00
|
|
|
RT_DEBUG_NOT_IN_INTERRUPT;
|
2011-06-12 18:01:48 +08:00
|
|
|
|
2010-04-13 01:37:37 +08:00
|
|
|
#ifdef RT_USING_MODULE
|
2010-11-24 09:27:45 +08:00
|
|
|
/* get module object information, module object should be managed by kernel object container */
|
|
|
|
information = (rt_module_self() != RT_NULL && (type != RT_Object_Class_Module)) ?
|
2010-09-20 08:02:11 +08:00
|
|
|
&rt_module_self()->module_object[type] : &rt_object_container[type];
|
2010-04-13 01:37:37 +08:00
|
|
|
#else
|
2009-07-03 06:48:23 +08:00
|
|
|
/* get object information */
|
2010-09-20 08:02:11 +08:00
|
|
|
information = &rt_object_container[type];
|
2010-04-13 01:37:37 +08:00
|
|
|
#endif
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2011-09-21 11:56:42 +08:00
|
|
|
object = (struct rt_object *)rt_malloc(information->object_size);
|
2009-07-03 06:48:23 +08:00
|
|
|
if (object == RT_NULL)
|
|
|
|
{
|
|
|
|
/* no memory can be allocated */
|
|
|
|
return RT_NULL;
|
|
|
|
}
|
2010-10-28 09:21:47 +08:00
|
|
|
|
2010-11-29 08:04:55 +08:00
|
|
|
/* initialize object's parameters */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
/* set object type */
|
|
|
|
object->type = type;
|
|
|
|
|
2010-10-28 09:21:47 +08:00
|
|
|
/* set object flag */
|
|
|
|
object->flag = 0;
|
|
|
|
|
|
|
|
#ifdef RT_USING_MODULE
|
2011-09-21 11:56:42 +08:00
|
|
|
if (rt_module_self() != RT_NULL)
|
2010-10-28 09:21:47 +08:00
|
|
|
{
|
|
|
|
object->flag |= RT_OBJECT_FLAG_MODULE;
|
2010-11-18 00:17:07 +08:00
|
|
|
}
|
2011-09-21 11:56:42 +08:00
|
|
|
object->module_id = (void *)rt_module_self();
|
2010-10-28 09:21:47 +08:00
|
|
|
#endif
|
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/* copy name */
|
2011-11-08 12:06:12 +08:00
|
|
|
rt_strncpy(object->name, name, RT_NAME_MAX);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2011-06-15 07:59:42 +08:00
|
|
|
RT_OBJECT_HOOK_CALL(rt_object_attach_hook, (object));
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
/* lock interrupt */
|
|
|
|
temp = rt_hw_interrupt_disable();
|
|
|
|
|
|
|
|
/* insert object into information object list */
|
|
|
|
rt_list_insert_after(&(information->object_list), &(object->list));
|
|
|
|
|
|
|
|
/* unlock interrupt */
|
|
|
|
rt_hw_interrupt_enable(temp);
|
|
|
|
|
|
|
|
/* return object */
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will delete an object and release object memory.
|
|
|
|
*
|
|
|
|
* @param object the specified object to be deleted.
|
|
|
|
*/
|
|
|
|
void rt_object_delete(rt_object_t object)
|
|
|
|
{
|
|
|
|
register rt_base_t temp;
|
|
|
|
|
|
|
|
/* object check */
|
|
|
|
RT_ASSERT(object != RT_NULL);
|
|
|
|
RT_ASSERT(!(object->type & RT_Object_Class_Static));
|
|
|
|
|
2011-06-15 07:59:42 +08:00
|
|
|
RT_OBJECT_HOOK_CALL(rt_object_detach_hook, (object));
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
/* lock interrupt */
|
|
|
|
temp = rt_hw_interrupt_disable();
|
|
|
|
|
|
|
|
/* remove from old list */
|
|
|
|
rt_list_remove(&(object->list));
|
|
|
|
|
|
|
|
/* unlock interrupt */
|
|
|
|
rt_hw_interrupt_enable(temp);
|
|
|
|
|
2011-07-05 07:48:07 +08:00
|
|
|
#if defined(RT_USING_MODULE) && defined(RT_USING_SLAB)
|
2011-09-21 11:56:42 +08:00
|
|
|
if (object->flag & RT_OBJECT_FLAG_MODULE)
|
2010-10-28 09:21:47 +08:00
|
|
|
rt_module_free((rt_module_t)object->module_id, object);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/* free the memory of object */
|
|
|
|
rt_free(object);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will judge the object is system object or not.
|
|
|
|
* Normally, the system object is a static object and the type
|
|
|
|
* of object set to RT_Object_Class_Static.
|
|
|
|
*
|
|
|
|
* @param object the specified object to be judged.
|
|
|
|
*
|
2012-06-02 17:20:19 +08:00
|
|
|
* @return RT_TRUE if a system object, RT_FALSE for others.
|
2009-07-03 06:48:23 +08:00
|
|
|
*/
|
2012-06-02 17:20:19 +08:00
|
|
|
rt_bool_t rt_object_is_systemobject(rt_object_t object)
|
2009-07-03 06:48:23 +08:00
|
|
|
{
|
|
|
|
/* object check */
|
|
|
|
RT_ASSERT(object != RT_NULL);
|
|
|
|
|
2012-03-17 14:43:49 +08:00
|
|
|
if (object->type & RT_Object_Class_Static)
|
2012-06-02 17:20:19 +08:00
|
|
|
return RT_TRUE;
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2012-06-02 17:20:19 +08:00
|
|
|
return RT_FALSE;
|
2009-07-03 06:48:23 +08:00
|
|
|
}
|
|
|
|
|
2010-11-22 07:57:33 +08:00
|
|
|
/**
|
|
|
|
* This function will find specified name object from object
|
|
|
|
* container.
|
|
|
|
*
|
|
|
|
* @param name the specified name of object.
|
|
|
|
* @param type the type of object
|
|
|
|
*
|
|
|
|
* @return the found object or RT_NULL if there is no this object
|
|
|
|
* in object container.
|
|
|
|
*
|
2010-11-29 08:04:55 +08:00
|
|
|
* @note this function shall not be invoked in interrupt status.
|
2010-11-22 07:57:33 +08:00
|
|
|
*/
|
2011-09-21 11:56:42 +08:00
|
|
|
rt_object_t rt_object_find(const char *name, rt_uint8_t type)
|
2010-11-22 07:57:33 +08:00
|
|
|
{
|
2011-09-21 11:56:42 +08:00
|
|
|
struct rt_object *object;
|
|
|
|
struct rt_list_node *node;
|
2010-11-22 07:57:33 +08:00
|
|
|
struct rt_object_information *information;
|
|
|
|
extern volatile rt_uint8_t rt_interrupt_nest;
|
|
|
|
|
|
|
|
/* parameter check */
|
2011-09-21 11:56:42 +08:00
|
|
|
if ((name == RT_NULL) || (type > RT_Object_Class_Unknown))
|
2010-11-22 07:57:33 +08:00
|
|
|
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();
|
|
|
|
|
2012-08-01 09:23:55 +08:00
|
|
|
return object;
|
2010-11-22 07:57:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* leave critical */
|
|
|
|
rt_exit_critical();
|
|
|
|
|
|
|
|
return RT_NULL;
|
|
|
|
}
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/*@}*/
|