RT-Thread RTOS  1.2.0
An open source embedded real-time operating system
Kernel Object Management
+ Collaboration diagram for Kernel Object Management:

Data Structures

struct  rt_object
 
struct  rt_object_information
 

Macros

#define RT_OBJECT_FLAG_MODULE   0x80
 
#define _RT_OBJECT_HOOK_CALL(func, argv)   __ON_HOOK_ARGS(func, argv)
 

Typedefs

typedef struct rt_objectrt_object_t
 
typedef rt_err_t(* rt_object_iter_t) (rt_object_t object, void *data)
 

Enumerations

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
}
 

Functions

struct rt_object_informationrt_object_get_information (enum rt_object_class_type type)
 
int rt_object_get_length (enum rt_object_class_type type)
 
int rt_object_get_pointers (enum rt_object_class_type type, rt_object_t *pointers, int maxlen)
 
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)
 

Detailed Description

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:

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.

Macro Definition Documentation

◆ RT_OBJECT_FLAG_MODULE

#define RT_OBJECT_FLAG_MODULE   0x80

is module object.

◆ _RT_OBJECT_HOOK_CALL

#define _RT_OBJECT_HOOK_CALL (   func,
  argv 
)    __ON_HOOK_ARGS(func, argv)

Add hook point in the routines.

The hook function call macro

Note
Usage: void foo() { do_something();

RT_OBJECT_HOOK_CALL(foo);

do_other_things(); }

Typedef Documentation

◆ rt_object_t

typedef struct rt_object* rt_object_t

Type for kernel objects.

◆ rt_object_iter_t

typedef rt_err_t(* rt_object_iter_t) (rt_object_t object, void *data)

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.

Enumeration Type Documentation

◆ 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
Enumerator
RT_Object_Class_Null 

The object is not used.

RT_Object_Class_Thread 

The object is a thread.

RT_Object_Class_Semaphore 

The object is a semaphore.

RT_Object_Class_Mutex 

The object is a mutex.

RT_Object_Class_Event 

The object is a event.

RT_Object_Class_MailBox 

The object is a mail box.

RT_Object_Class_MessageQueue 

The object is a message queue.

RT_Object_Class_MemHeap 

The object is a memory heap.

RT_Object_Class_MemPool 

The object is a memory pool.

RT_Object_Class_Device 

The object is a device.

RT_Object_Class_Timer 

The object is a timer.

RT_Object_Class_Module 

The object is a module.

RT_Object_Class_Memory 

The object is a memory.

RT_Object_Class_Channel 

The object is a channel

RT_Object_Class_ProcessGroup 

The object is a process group

RT_Object_Class_Session 

The object is a session

RT_Object_Class_Custom 

The object is a custom object

RT_Object_Class_Unknown 

The object is unknown.

RT_Object_Class_Static 

The object is a static object.

Function Documentation

◆ rt_object_get_information()

struct rt_object_information * rt_object_get_information ( enum rt_object_class_type  type)

This function will return the specified type of object information.

Parameters
typeis the type of object, which can be RT_Object_Class_Thread/Semaphore/Mutex... etc
Returns
the object type information or RT_NULL

◆ rt_object_get_length()

int rt_object_get_length ( enum rt_object_class_type  type)

This function will return the length of object list in object container.

Parameters
typeis the type of object, which can be RT_Object_Class_Thread/Semaphore/Mutex... etc
Returns
the length of object list

◆ rt_object_get_pointers()

int rt_object_get_pointers ( enum rt_object_class_type  type,
rt_object_t pointers,
int  maxlen 
)

This function will copy the object pointer of the specified type, with the maximum size specified by maxlen.

Parameters
typeis the type of object, which can be RT_Object_Class_Thread/Semaphore/Mutex... etc
pointersis the pointer will be saved to.
maxlenis the maximum number of pointers can be saved.
Returns
the copied number of object pointers.

◆ rt_object_init()

void rt_object_init ( struct rt_object object,
enum rt_object_class_type  type,
const char *  name 
)

This function will initialize an object and add it to object system management.

Parameters
objectis the specified object to be initialized.
typeis the object type.
nameis the object name. In system, the object's name must be unique.

◆ rt_object_detach()

void rt_object_detach ( rt_object_t  object)

This function will detach a static object from object system, and the memory of static object is not freed.

Parameters
objectthe specified object to be detached.

◆ rt_object_allocate()

rt_object_t rt_object_allocate ( enum rt_object_class_type  type,
const char *  name 
)

This function will allocate an object from object system.

Parameters
typeis the type of object.
nameis the object name. In system, the object's name must be unique.
Returns
object

◆ rt_object_delete()

void rt_object_delete ( rt_object_t  object)

This function will delete an object and release object memory.

Parameters
objectis the specified object to be deleted.

◆ rt_object_is_systemobject()

rt_bool_t rt_object_is_systemobject ( rt_object_t  object)

This function will judge the object is system object or not.

Note
Normally, the system object is a static object and the type of object set to RT_Object_Class_Static.
Parameters
objectis the specified object to be judged.
Returns
RT_TRUE if a system object, RT_FALSE for others.

◆ rt_object_get_type()

rt_uint8_t rt_object_get_type ( rt_object_t  object)

This function will return the type of object without RT_Object_Class_Static flag.

Parameters
objectis the specified object to be get type.
Returns
the type of object.

◆ rt_object_for_each()

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.

Parameters
typeis the type of object
iteris the iterator
datais the specified data passed to iterator
Returns
RT_EOK on succeed, otherwise the error from iter
Note
this function shall not be invoked in interrupt status.

◆ rt_object_find()

rt_object_t rt_object_find ( const char *  name,
rt_uint8_t  type 
)

This function will find specified name object from object container.

Parameters
nameis the specified name of object.
typeis the type of object
Returns
the found object or RT_NULL if there is no this object in object container.
Note
this function shall not be invoked in interrupt status.

◆ rt_object_get_name()

rt_err_t rt_object_get_name ( rt_object_t  object,
char *  name,
rt_uint8_t  name_size 
)

This function will return the name of the specified object container.

Parameters
objectthe specified object to be get name
namebuffer to store the object name string
name_sizemaximum size of the buffer to store object name
Returns
-RT_EINVAL if any parameter is invalid or RT_EOK if the operation is successfully executed
Note
this function shall not be invoked in interrupt status

◆ rt_custom_object_create()

rt_object_t rt_custom_object_create ( const char *  name,
void *  data,
rt_err_t(*)(void *)  data_destroy 
)

This function will create a custom object container.

Parameters
namethe specified name of object.
datathe custom data
data_destroythe custom object destroy callback
Returns
the found object or RT_NULL if there is no this object in object container.
Note
this function shall not be invoked in interrupt status.

◆ rt_custom_object_destroy()

rt_err_t rt_custom_object_destroy ( rt_object_t  obj)

This function will destroy a custom object container.

Parameters
objthe specified name of object.
Note
this function shall not be invoked in interrupt status.