当前位置:网站首页>RT thread analysis - object container implementation and function
RT thread analysis - object container implementation and function
2022-07-06 04:49:00 【Just think Quiet】
Catalog
2) Container definition _object_container[]
2.3 Object container link graph
3 Get object container rt_object_get_information()
4 Object initialization rt_object_init()
5 Object delete rt_object_delete()
6 Look for objects rt_object_find()
1 Preface
In kernel , All data structures are treated as one object , Include : Threads 、 Semaphore 、 The mutex 、 event 、 mailbox 、 Message queue 、 Memory heap 、 Memory pool 、 Equipment and timers . For the convenience of management , When the user or kernel creates an object , The object will be put into the container . The container is a global array in the kernel , Record the information of all objects .
2 Relevant data structure
2.1 object
1) type
enum rt_object_class_type
{
RT_Object_Class_Null = 0x00, /**< The object is not used. */
RT_Object_Class_Thread = 0x01, /**< The object is a thread. */
RT_Object_Class_Semaphore = 0x02, /**< The object is a semaphore. */
RT_Object_Class_Mutex = 0x03, /**< The object is a mutex. */
RT_Object_Class_Event = 0x04, /**< The object is a event. */
RT_Object_Class_MailBox = 0x05, /**< The object is a mail box. */
RT_Object_Class_MessageQueue = 0x06, /**< The object is a message queue. */
RT_Object_Class_MemHeap = 0x07, /**< The object is a memory heap. */
RT_Object_Class_MemPool = 0x08, /**< The object is a memory pool. */
RT_Object_Class_Device = 0x09, /**< The object is a device. */
RT_Object_Class_Timer = 0x0a, /**< The object is a timer. */
RT_Object_Class_Module = 0x0b, /**< The object is a module. */
RT_Object_Class_Unknown = 0x0c, /**< The object is unknown. */
RT_Object_Class_Static = 0x80 /**< The object is a static object. */
};
2) data structure
struct rt_object
{
// Object name , Use string representation , Length from RT_NAME_MAX decision
char name[RT_NAME_MAX];
// object type
rt_uint8_t type;
// Object state
rt_uint8_t flag;
// Intrusive linked list , Link the object to the container
rt_list_t list;
};
typedef struct rt_object *rt_object_t;
2.3 Containers
The global structure array is used in the kernel (rt_object_information _object_container[]) To define the container . Each container holds objects of the same type , Save its information , Use a linked list to link all objects for easy management .
1) data structure
struct rt_object_information
{
// The object type under the container
enum rt_object_class_type type;
// Link all objects under the container
rt_list_t object_list;
// Its object size
rt_size_t object_size;
};
2) Container definition _object_container[]
//2.1) Containers are represented by arrays , The following is to define the sequence numbers of different objects in the array
enum rt_object_info_type
{
RT_Object_Info_Thread = 0, /**< The object is a thread. */
#ifdef RT_USING_SEMAPHORE
RT_Object_Info_Semaphore, /**< The object is a semaphore. */
#endif
#ifdef RT_USING_MUTEX
RT_Object_Info_Mutex, /**< The object is a mutex. */
#endif
#ifdef RT_USING_EVENT
RT_Object_Info_Event, /**< The object is a event. */
#endif
#ifdef RT_USING_MAILBOX
RT_Object_Info_MailBox, /**< The object is a mail box. */
#endif
#ifdef RT_USING_MESSAGEQUEUE
RT_Object_Info_MessageQueue, /**< The object is a message queue. */
#endif
#ifdef RT_USING_MEMHEAP
RT_Object_Info_MemHeap, /**< The object is a memory heap */
#endif
#ifdef RT_USING_MEMPOOL
RT_Object_Info_MemPool, /**< The object is a memory pool. */
#endif
#ifdef RT_USING_DEVICE
RT_Object_Info_Device, /**< The object is a device */
#endif
RT_Object_Info_Timer, /**< The object is a timer. */
#ifdef RT_USING_MODULE
RT_Object_Info_Module, /**< The object is a module. */
#endif
RT_Object_Info_Unknown, /**< The object is unknown. */
};
//2.2) Each container holds objects of the same type , such as _object_container[0] Are storage objects RT_Object_Class_Thread, Then use the linked list object_list Link all objects
#define _OBJ_CONTAINER_LIST_INIT(c) \
{&(_object_container[c].object_list), &(_object_container[c].object_list)}
static struct rt_object_information _object_container[RT_Object_Info_Unknown] =
{
/* initialize object container - thread */
{RT_Object_Class_Thread, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_Thread), sizeof(struct rt_thread)},
#ifdef RT_USING_SEMAPHORE
/* initialize object container - semaphore */
{RT_Object_Class_Semaphore, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_Semaphore), sizeof(struct rt_semaphore)},
#endif
#ifdef RT_USING_MUTEX
/* initialize object container - mutex */
{RT_Object_Class_Mutex, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_Mutex), sizeof(struct rt_mutex)},
#endif
#ifdef RT_USING_EVENT
/* initialize object container - event */
{RT_Object_Class_Event, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_Event), sizeof(struct rt_event)},
#endif
#ifdef RT_USING_MAILBOX
/* initialize object container - mailbox */
{RT_Object_Class_MailBox, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_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_Info_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_Info_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_Info_MemPool), sizeof(struct rt_mempool)},
#endif
#ifdef RT_USING_DEVICE
/* initialize object container - device */
{RT_Object_Class_Device, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_Device), sizeof(struct rt_device)},
#endif
/* initialize object container - timer */
{RT_Object_Class_Timer, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_Timer), sizeof(struct rt_timer)},
#ifdef RT_USING_MODULE
/* initialize object container - module */
{RT_Object_Class_Module, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_Module), sizeof(struct rt_dlmodule)},
#endif
};
2.3 Object container link graph
3 Get object container rt_object_get_information()
struct rt_object_information* rt_object_get_information(enum rt_object_class_type type)
{
int index;
// Traverse container array _object_container[], Find the object container by type
for (index = 0; index < RT_Object_Info_Unknown; index ++)
if (_object_container[index].type == type)
return &_object_container[index];
return RT_NULL;
}
4 Object initialization rt_object_init()
void rt_object_init(struct rt_object *object,
enum rt_object_class_type type,
const char *name)
{
//1 By object type , Find the container
information = rt_object_get_information(type);
//2 Traverse all objects under the container , If it is consistent with the object to be initialized , Enter assertion
//PS: The function of this error check ???
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);
if (obj) /* skip warning when disable debug */
{
RT_ASSERT(obj != object);
}
}
//3 Set static tags
object->type = type | RT_Object_Class_Static;
//4 Set object name
rt_strncpy(object->name, name, RT_NAME_MAX);
//5 Insert the object into the end of the container list
rt_list_insert_after(&(information->object_list), &(object->list));
}
5 Object delete rt_object_delete()
void rt_object_delete(rt_object_t object)
{
//1 Reset object type
object->type = RT_Object_Class_Null;
//2 Remove objects from the container list
rt_list_remove(&(object->list));
//3 Free object memory
RT_KERNEL_FREE(object);
}
6 Look for objects rt_object_find()
rt_object_t rt_object_find(const char *name, rt_uint8_t type)
{
//1 Find the corresponding container by type
information = rt_object_get_information((enum rt_object_class_type)type);
//2 Context detection , This function is not allowed to call
RT_DEBUG_NOT_IN_INTERRUPT;
}
7 summary
- Every data structure in the kernel is abstracted as an object rt_object, Include : Threads 、 Semaphore 、 The mutex 、 event 、 mailbox 、 Message queue 、 Memory heap 、 Memory pool 、 Equipment and timers .
- In actual use , Object properties can be inherited
- The kernel maintains containers using global struct arrays , Each member of the array manages all objects of the same type , It is convenient to query the information of each object at any time
边栏推荐
- 2021RoboCom机器人开发者大赛(初赛)
- Yolov5 tensorrt acceleration
- Fuzzy -- basic application method of AFL
- Flody的应用
- ISP learning (2)
- Visio draw fan
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- 比尔·盖茨晒18岁个人简历,48年前期望年薪1.2万美元
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Can Flink SQL read multiple topics at the same time. How to write in with
猜你喜欢
11. Intranet penetration and automatic refresh
canal同步mysql数据变化到kafka(centos部署)
[数学建模] 微分方程--捕鱼业的持续发展
麦斯克电子IPO被终止:曾拟募资8亿 河南资产是股东
Is the mode of education together - on campus + off campus reliable
ETCD数据库源码分析——etcdserver bootstrap初始化存储
ue5 小知识点 开启lumen的设置
yolov5 tensorrt加速
[lgr-109] Luogu may race II & windy round 6
English Vocabulary - life scene memory method
随机推荐
Platformio create libopencm3 + FreeRTOS project
Postman关联
[HBZ sharing] how to locate slow queries in cloud database
word封面下划线
Request (request object) and response (response object)
Visio draws Tai Chi
ORM aggregate query and native database operation
Database - MySQL storage engine (deadlock)
L'introduction en bourse de MSK Electronics a pris fin: 800 millions de RMB d'actifs de Henan étaient des actionnaires
Dynamic programming (tree DP)
Redis 排查大 key 的4种方法,优化必备
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
acwing周赛58
ETCD数据库源码分析——etcdserver bootstrap初始化存储
Biscuits (examination version)
Flink kakfa data read and write to Hudi
What are the advantages of the industry private network over the public network? What specific requirements can be met?
ue5 小知识点 开启lumen的设置
Postman pre script - global variables and environment variables
The video in win10 computer system does not display thumbnails