rt-thread的内核对象管理系统分析(二)
_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)},
#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)},
#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)},
#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)},
#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)},
#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)},
#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)},
#endif
/* 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)},
#endif
};
2 内核对象接口
2.1 内核对象初始化
RTT提供静态和动态两种初始化接口,如下:
静态初始化是将一个已经存在的且占有内存空间的对象初始化,它的接口如下:
[cpp]
/**
* 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) //对象的名字字符串
{
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];
#else
/* get object information */
information = &rt_object_container[type];
#endif
/* initialize object's parameters */
/* set object type to static */
object->type = type | RT_Object_Class_Static;//设置系统对象标志
/* copy name */
rt_strncpy(object->name, name, RT_NAME_MAX);//给名字赋值
RT_OBJECT_HOOK_CALL(rt_objec