|
enum | rt_object_class_type {
RT_Object_Class_Null = 0x00
, RT_Object_Class_Thread = 0x01
, RT_Object_Class_Semaphore = 0x02
, RT_Object_Class_Mutex = 0x03
,
RT_Object_Class_Event = 0x04
, RT_Object_Class_MailBox = 0x05
, RT_Object_Class_MessageQueue = 0x06
, RT_Object_Class_MemHeap = 0x07
,
RT_Object_Class_MemPool = 0x08
, RT_Object_Class_Device = 0x09
, RT_Object_Class_Timer = 0x0a
, RT_Object_Class_Module = 0x0b
,
RT_Object_Class_Memory = 0x0c
, RT_Object_Class_Channel = 0x0d
, RT_Object_Class_ProcessGroup = 0x0e
, RT_Object_Class_Session = 0x0f
,
RT_Object_Class_Custom = 0x10
, RT_Object_Class_Unknown = 0x11
, RT_Object_Class_Static = 0x80
} |
|
|
struct rt_object_information * | rt_object_get_information (enum rt_object_class_type type) |
|
| RTM_EXPORT (rt_object_get_information) |
|
int | rt_object_get_length (enum rt_object_class_type type) |
|
| RTM_EXPORT (rt_object_get_length) |
|
int | rt_object_get_pointers (enum rt_object_class_type type, rt_object_t *pointers, int maxlen) |
|
| RTM_EXPORT (rt_object_get_pointers) |
|
void | rt_object_init (struct rt_object *object, enum rt_object_class_type type, const char *name) |
|
void | rt_object_detach (rt_object_t object) |
|
rt_object_t | rt_object_allocate (enum rt_object_class_type type, const char *name) |
|
void | rt_object_delete (rt_object_t object) |
|
rt_bool_t | rt_object_is_systemobject (rt_object_t object) |
|
rt_uint8_t | rt_object_get_type (rt_object_t object) |
|
rt_err_t | rt_object_for_each (rt_uint8_t type, rt_object_iter_t iter, void *data) |
|
rt_object_t | rt_object_find (const char *name, rt_uint8_t type) |
|
rt_err_t | rt_object_get_name (rt_object_t object, char *name, rt_uint8_t name_size) |
|
rt_object_t | rt_custom_object_create (const char *name, void *data, rt_err_t(*data_destroy)(void *)) |
|
rt_err_t | rt_custom_object_destroy (rt_object_t obj) |
|
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_trytake_sethook (void(*hook)(struct rt_object *object)) |
|
void | rt_object_take_sethook (void(*hook)(struct rt_object *object)) |
|
void | rt_object_put_sethook (void(*hook)(struct rt_object *object)) |
|
kernel object management
The Kernel object system can access and manage all of the kernel objects.
Kernel objects include most of the facilities in the kernel:
- thread
- semaphore and mutex
- event/fast event, mailbox, messagequeue
- memory pool
- timer
Figure 2: Kernel Object
Kernel objects can be static objects, whose memory is allocated in compiling. It can be dynamic objects as well, whose memory is allocated from system heaps in runtime.
◆ RT_OBJECT_FLAG_MODULE
#define RT_OBJECT_FLAG_MODULE 0x80 |
◆ _RT_OBJECT_HOOK_CALL
#define _RT_OBJECT_HOOK_CALL |
( |
| func, |
|
|
| argv ) |
值:
#define __ON_HOOK_ARGS(__hook, argv)
Add hook point in the routines
The hook function call macro
- 注解
- Usage: void foo() { do_something();
RT_OBJECT_HOOK_CALL(foo);
do_other_things(); }
在文件 rtdef.h 第 381 行定义.
◆ RT_OBJECT_HOOK_CALL
#define RT_OBJECT_HOOK_CALL |
( |
| func, |
|
|
| argv ) |
值:
#define _RT_OBJECT_HOOK_CALL(func, argv)
Add hook point in the routines
在文件 rtdef.h 第 382 行定义.
◆ __ON_HOOK_ARGS
#define __ON_HOOK_ARGS |
( |
| __hook, |
|
|
| argv ) |
◆ RT_OBJECT_HOOKLIST_DECLARE
#define RT_OBJECT_HOOKLIST_DECLARE |
( |
| handler_type, |
|
|
| name ) |
◆ RT_OBJECT_HOOKLIST_DEFINE_NODE
#define RT_OBJECT_HOOKLIST_DEFINE_NODE |
( |
| hookname, |
|
|
| nodename, |
|
|
| hooker_handler ) |
◆ RT_OBJECT_HOOKLIST_DEFINE
#define RT_OBJECT_HOOKLIST_DEFINE |
( |
| name | ) |
|
◆ RT_OBJECT_HOOKLIST_CALL
#define RT_OBJECT_HOOKLIST_CALL |
( |
| name, |
|
|
| argv ) |
◆ rt_object_t
◆ rt_object_iter_t
iterator of rt_object_for_each()
data is the data passing in to rt_object_for_each(). iterator can return RT_EOK to continue the iteration; or any positive value to break the loop successfully; or any negative errno to break the loop on failure.
在文件 rtdef.h 第 309 行定义.
◆ rt_object_class_type
The object type can be one of the follows with specific macros enabled:
- Thread
- Semaphore
- Mutex
- Event
- MailBox
- MessageQueue
- MemHeap
- MemPool
- Device
- Timer
- Module
- Unknown
- Static
枚举值 |
---|
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_Memory | 0x0c | The object is a memory.
|
RT_Object_Class_Channel | 0x0d | The object is a channel
|
RT_Object_Class_ProcessGroup | 0x0e | The object is a process group
|
RT_Object_Class_Session | 0x0f | The object is a session
|
RT_Object_Class_Custom | 0x10 | The object is a custom object
|
RT_Object_Class_Unknown | 0x11 | The object is unknown.
|
RT_Object_Class_Static | 0x80 | The object is a static object.
|
在文件 rtdef.h 第 328 行定义.
329{
349};
@ RT_Object_Class_MemHeap
@ RT_Object_Class_MessageQueue
@ RT_Object_Class_ProcessGroup
@ RT_Object_Class_MemPool
@ RT_Object_Class_MailBox
@ RT_Object_Class_Unknown
@ RT_Object_Class_Channel
@ RT_Object_Class_Semaphore
@ RT_Object_Class_Session
◆ rt_object_get_information()
This function will return the specified type of object information.
- 参数
-
type | is the type of object, which can be RT_Object_Class_Thread/Semaphore/Mutex... etc |
- 返回
- the object type information or RT_NULL
在文件 object.c 第 248 行定义.
249{
250 int index;
251
253
255 if (_object_container[index].type == type) return &_object_container[index];
256
258}
引用了 RT_NULL, RT_Object_Class_Static , 以及 RT_Object_Info_Unknown.
◆ RTM_EXPORT() [1/3]
◆ rt_object_get_length()
This function will return the length of object list in object container.
- 参数
-
type | is the type of object, which can be RT_Object_Class_Thread/Semaphore/Mutex... etc |
- 返回
- the length of object list
在文件 object.c 第 269 行定义.
270{
271 int count = 0;
275
277 if (information ==
RT_NULL)
return 0;
278
281 {
282 count ++;
283 }
285
286 return count;
287}
rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock)
This function will disable the local interrupt and then lock the spinlock, will lock the thread sched...
void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level)
This function will unlock the spinlock and then restore current cpu interrupt status,...
struct rt_object_information * rt_object_get_information(enum rt_object_class_type type)
This function will return the specified type of object information.
#define rt_list_for_each(pos, head)
引用了 rt_object_information::object_list, rt_list_for_each, RT_NULL, rt_object_get_information(), rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore() , 以及 rt_object_information::spinlock.
◆ RTM_EXPORT() [2/3]
◆ rt_object_get_pointers()
This function will copy the object pointer of the specified type, with the maximum size specified by maxlen.
- 参数
-
type | is the type of object, which can be RT_Object_Class_Thread/Semaphore/Mutex... etc |
pointers | is the pointer will be saved to. |
maxlen | is the maximum number of pointers can be saved. |
- 返回
- the copied number of object pointers.
在文件 object.c 第 303 行定义.
304{
305 int index = 0;
307
311
312 if (maxlen <= 0) return 0;
313
315 if (information ==
RT_NULL)
return 0;
316
318
320 {
322
323 pointers[index] = object;
324 index ++;
325
326 if (index >= maxlen) break;
327 }
329
330 return index;
331}
#define rt_list_entry(node, type, member)
get the struct for this entry
引用了 rt_object_information::object_list, rt_list_entry, rt_list_for_each, RT_NULL, rt_object_get_information(), rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore() , 以及 rt_object_information::spinlock.
◆ RTM_EXPORT() [3/3]
◆ rt_object_init()
This function will initialize an object and add it to object system management.
- 参数
-
object | is the specified object to be initialized. |
type | is the object type. |
name | is the object name. In system, the object's name must be unique. |
在文件 object.c 第 344 行定义.
347{
349#ifdef RT_DEBUGING_ASSERT
351#endif
353#ifdef RT_USING_MODULE
354 struct rt_dlmodule *module = dlmodule_self();
355#endif
356
357
360
361#ifdef RT_DEBUGING_ASSERT
362
363
364
366
370 {
372
375 }
376
378#endif
379
380
381
383#if RT_NAME_MAX > 0
384 rt_strncpy(object->
name,
name, RT_NAME_MAX);
385#else
387#endif
388
390
392
393#ifdef RT_USING_MODULE
394 if (module)
395 {
397 object->module_id = (void *)module;
398 }
399 else
400#endif
401 {
402
404 }
406}
#define RT_OBJECT_HOOK_CALL(func, argv)
rt_inline void rt_list_insert_after(rt_list_t *l, rt_list_t *n)
insert a node after a list
struct rt_list_node * next
引用了 rt_object::list, rt_object::name, rt_list_node::next, rt_object_information::object_list, RT_ASSERT, rt_list_entry, rt_list_insert_after(), RT_NULL, RT_Object_Class_Static, rt_object_get_information(), RT_OBJECT_HOOK_CALL, rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore() , 以及 rt_object_information::spinlock.
◆ rt_object_detach()
This function will detach a static object from object system, and the memory of static object is not freed.
- 参数
-
object | the specified object to be detached. |
在文件 object.c 第 414 行定义.
415{
418
419
421
423
426
428
431
433}
rt_inline void rt_list_remove(rt_list_t *n)
remove node from list.
引用了 rt_object::list, RT_ASSERT, rt_list_remove(), RT_NULL, RT_Object_Class_Null, rt_object_get_information(), RT_OBJECT_HOOK_CALL, rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore(), rt_object_information::spinlock , 以及 rt_object::type.
◆ rt_object_allocate()
This function will allocate an object from object system.
- 参数
-
type | is the type of object. |
name | is the object name. In system, the object's name must be unique. |
- 返回
- object
在文件 object.c 第 445 行定义.
446{
450#ifdef RT_USING_MODULE
451 struct rt_dlmodule *module = dlmodule_self();
452#endif
453
455
456
459
462 {
463
465 }
466
467
469
470
471
472
474
475
476 object->flag = 0;
477
478#if RT_NAME_MAX > 0
479 rt_strncpy(object->
name,
name, RT_NAME_MAX - 1);
480#else
482#endif
483
485
487
488#ifdef RT_USING_MODULE
489 if (module)
490 {
492 object->module_id = (void *)module;
493 }
494 else
495#endif
496 {
497
499 }
501
502 return object;
503}
#define RT_DEBUG_NOT_IN_INTERRUPT
#define RT_KERNEL_MALLOC(sz)
引用了 rt_object::list, rt_object::name, rt_object_information::object_list, rt_object_information::object_size, RT_ASSERT, RT_DEBUG_NOT_IN_INTERRUPT, RT_KERNEL_MALLOC, rt_list_insert_after(), RT_NULL, rt_object_get_information(), RT_OBJECT_HOOK_CALL, rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore() , 以及 rt_object_information::spinlock.
◆ rt_object_delete()
This function will delete an object and release object memory.
- 参数
-
object | is the specified object to be deleted. |
在文件 object.c 第 510 行定义.
511{
514
515
518
520
521
524
526
527
529
531
532
534
535
537}
#define RT_KERNEL_FREE(ptr)
引用了 rt_object::list, RT_ASSERT, RT_KERNEL_FREE, rt_list_remove(), RT_NULL, RT_Object_Class_Null, RT_Object_Class_Static, rt_object_get_information(), RT_OBJECT_HOOK_CALL, rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore(), rt_object_information::spinlock , 以及 rt_object::type.
◆ rt_object_is_systemobject()
◆ rt_object_get_type()
◆ rt_object_for_each()
This function will iterate through each object from object container.
- 参数
-
type | is the type of object |
iter | is the iterator |
data | is the specified data passed to iterator |
- 返回
- RT_EOK on succeed, otherwise the error from
iter
- 注解
- this function shall not be invoked in interrupt status.
在文件 object.c 第 589 行定义.
590{
596
598
599
601 {
602 return -RT_EINVAL;
603 }
604
605
607
608
610
611
613 {
615 if ((error = iter(object, data)) != RT_EOK)
616 {
618
619 return error >= 0 ? RT_EOK : error;
620 }
621 }
622
624
625 return RT_EOK;
626}
引用了 rt_object_information::object_list, RT_DEBUG_NOT_IN_INTERRUPT, rt_list_entry, rt_list_for_each, RT_NULL, rt_object_get_information(), rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore() , 以及 rt_object_information::spinlock.
◆ rt_object_find()
This function will find specified name object from object container.
- 参数
-
name | is the specified name of object. |
type | is the type of object |
- 返回
- the found object or RT_NULL if there is no this object in object container.
- 注解
- this function shall not be invoked in interrupt status.
在文件 object.c 第 662 行定义.
663{
664 struct _obj_find_param param =
665 {
666 .match_name = name,
668 };
669
670
672
673
675
677 return param.matched_obj;
678}
rt_err_t rt_object_for_each(rt_uint8_t type, rt_object_iter_t iter, void *data)
This function will iterate through each object from object container.
引用了 RT_DEBUG_NOT_IN_INTERRUPT, RT_NULL , 以及 rt_object_for_each().
◆ rt_object_get_name()
This function will return the name of the specified object container
- 参数
-
object | the specified object to be get name |
name | buffer to store the object name string |
name_size | maximum size of the buffer to store object name |
- 返回
- -RT_EINVAL if any parameter is invalid or RT_EOK if the operation is successfully executed
- 注解
- this function shall not be invoked in interrupt status
在文件 object.c 第 691 行定义.
692{
694 if ((
object !=
RT_NULL) && (name !=
RT_NULL) && (name_size != 0U))
695 {
696 const char *obj_name = object->name;
697 (void) rt_strncpy(name, obj_name, (
rt_size_t)name_size);
698 result = RT_EOK;
699 }
700
701 return result;
702}
引用了 RT_NULL.
◆ rt_custom_object_create()
rt_object_t rt_custom_object_create |
( |
const char * | name, |
|
|
void * | data, |
|
|
rt_err_t(* | data_destroy )(void *) ) |
This function will create a custom object container.
- 参数
-
name | the specified name of object. |
data | the custom data |
data_destroy | the custom object destroy callback |
- 返回
- the found object or RT_NULL if there is no this object in object container.
- 注解
- this function shall not be invoked in interrupt status.
在文件 object.c 第 719 行定义.
720{
721 struct rt_custom_object *cobj =
RT_NULL;
722
724 if (!cobj)
725 {
727 }
728 cobj->destroy = data_destroy;
729 cobj->data = data;
731}
rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name)
This function will allocate an object from object system.
引用了 RT_NULL, rt_object_allocate() , 以及 RT_Object_Class_Custom.
◆ rt_custom_object_destroy()
This function will destroy a custom object container.
- 参数
-
obj | the specified name of object. |
- 注解
- this function shall not be invoked in interrupt status.
在文件 object.c 第 741 行定义.
742{
744
745 struct rt_custom_object *cobj = (struct rt_custom_object *)obj;
746
748 {
749 if (cobj->destroy)
750 {
751 ret = cobj->destroy(cobj->data);
752 }
754 }
755 return ret;
756}
void rt_object_delete(rt_object_t object)
This function will delete an object and release object memory.
引用了 RT_Object_Class_Custom, rt_object_delete() , 以及 rt_object::type.
◆ rt_object_attach_sethook()
void rt_object_attach_sethook |
( |
void(* | hook )(struct rt_object *object) | ) |
|
◆ rt_object_detach_sethook()
void rt_object_detach_sethook |
( |
void(* | hook )(struct rt_object *object) | ) |
|
◆ rt_object_trytake_sethook()
void rt_object_trytake_sethook |
( |
void(* | hook )(struct rt_object *object) | ) |
|
◆ rt_object_take_sethook()
void rt_object_take_sethook |
( |
void(* | hook )(struct rt_object *object) | ) |
|
◆ rt_object_put_sethook()
void rt_object_put_sethook |
( |
void(* | hook )(struct rt_object *object) | ) |
|