mirror of https://github.com/RT-Thread/rt-thread
commit
05cd6eaad7
|
@ -128,21 +128,21 @@ rt_inline unsigned int rt_list_len(const rt_list_t *l)
|
|||
|
||||
/**
|
||||
* rt_list_for_each - iterate over a list
|
||||
* @pos: the rt_list_t * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @pos: the rt_list_t * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define rt_list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); pos = pos->next)
|
||||
|
||||
/**
|
||||
* rt_list_for_each_safe - iterate over a list safe against removal of list entry
|
||||
* @pos: the rt_list_t * to use as a loop cursor.
|
||||
* @n: another rt_list_t * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @pos: the rt_list_t * to use as a loop cursor.
|
||||
* @n: another rt_list_t * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define rt_list_for_each_safe(pos, n, head) \
|
||||
for (pos = (head)->next, n = pos->next; pos != (head); \
|
||||
pos = n, n = pos->next)
|
||||
for (pos = (head)->next, n = pos->next; pos != (head); \
|
||||
pos = n, n = pos->next)
|
||||
|
||||
/**
|
||||
* rt_list_for_each_entry - iterate over list of given type
|
||||
|
|
|
@ -41,6 +41,9 @@ extern "C" {
|
|||
void rt_system_object_init(void);
|
||||
struct rt_object_information *
|
||||
rt_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);
|
||||
|
|
87
src/object.c
87
src/object.c
|
@ -212,7 +212,9 @@ void rt_system_object_init(void)
|
|||
/**
|
||||
* This function will return the specified type of object information.
|
||||
*
|
||||
* @param type the type of object
|
||||
* @param type the type of object, which can be
|
||||
* RT_Object_Class_Thread/Semaphore/Mutex... etc
|
||||
*
|
||||
* @return the object type information or RT_NULL
|
||||
*/
|
||||
struct rt_object_information *
|
||||
|
@ -227,6 +229,75 @@ rt_object_get_information(enum rt_object_class_type type)
|
|||
}
|
||||
RTM_EXPORT(rt_object_get_information);
|
||||
|
||||
/**
|
||||
* This function will return the length of object list in object container.
|
||||
*
|
||||
* @param type the type of object, which can be
|
||||
* RT_Object_Class_Thread/Semaphore/Mutex... etc
|
||||
* @return the length of object list
|
||||
*/
|
||||
int rt_object_get_length(enum rt_object_class_type type)
|
||||
{
|
||||
int count = 0;
|
||||
rt_ubase_t level;
|
||||
struct rt_list_node *node = RT_NULL;
|
||||
struct rt_object_information *information = RT_NULL;
|
||||
|
||||
information = rt_object_get_information((enum rt_object_class_type)type);
|
||||
if (information == RT_NULL) return 0;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
/* get the count of objects */
|
||||
rt_list_for_each(node, &(information->object_list))
|
||||
{
|
||||
count ++;
|
||||
}
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
return count;
|
||||
}
|
||||
RTM_EXPORT(rt_object_get_length);
|
||||
|
||||
/**
|
||||
* This function will copy the object pointer of the specified type,
|
||||
* with the maximum size specified by maxlen.
|
||||
*
|
||||
* @param type the type of object, which can be
|
||||
* RT_Object_Class_Thread/Semaphore/Mutex... etc
|
||||
* @param pointers the pointers will be saved to
|
||||
* @param maxlen the maximum number of pointers can be saved
|
||||
*
|
||||
* @return the copied number of object pointers
|
||||
*/
|
||||
int rt_object_get_pointers(enum rt_object_class_type type, rt_object_t *pointers, int maxlen)
|
||||
{
|
||||
int index = 0;
|
||||
rt_ubase_t level;
|
||||
|
||||
struct rt_object *object;
|
||||
struct rt_list_node *node = RT_NULL;
|
||||
struct rt_object_information *information = RT_NULL;
|
||||
|
||||
if (maxlen <= 0) return 0;
|
||||
|
||||
information = rt_object_get_information((enum rt_object_class_type)type);
|
||||
if (information == RT_NULL) return 0;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
/* retrieve pointer of object */
|
||||
rt_list_for_each(node, &(information->object_list))
|
||||
{
|
||||
object = rt_list_entry(node, struct rt_object, list);
|
||||
|
||||
pointers[index] = object;
|
||||
index ++;
|
||||
}
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
return index;
|
||||
}
|
||||
RTM_EXPORT(rt_object_get_pointers);
|
||||
|
||||
/**
|
||||
* This function will initialize an object and add it to object system
|
||||
* management.
|
||||
|
@ -482,9 +553,10 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type)
|
|||
struct rt_list_node *node = RT_NULL;
|
||||
struct rt_object_information *information = RT_NULL;
|
||||
|
||||
information = rt_object_get_information((enum rt_object_class_type)type);
|
||||
|
||||
/* parameter check */
|
||||
if ((name == RT_NULL) || (type > RT_Object_Class_Unknown))
|
||||
return RT_NULL;
|
||||
if ((name == RT_NULL) || (information == RT_NULL)) return RT_NULL;
|
||||
|
||||
/* which is invoke in interrupt status */
|
||||
RT_DEBUG_NOT_IN_INTERRUPT;
|
||||
|
@ -493,14 +565,7 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type)
|
|||
rt_enter_critical();
|
||||
|
||||
/* try to find object */
|
||||
if (information == RT_NULL)
|
||||
{
|
||||
information = rt_object_get_information((enum rt_object_class_type)type);
|
||||
RT_ASSERT(information != RT_NULL);
|
||||
}
|
||||
for (node = information->object_list.next;
|
||||
node != &(information->object_list);
|
||||
node = node->next)
|
||||
rt_list_for_each(node, &(information->object_list))
|
||||
{
|
||||
object = rt_list_entry(node, struct rt_object, list);
|
||||
if (rt_strncmp(object->name, name, RT_NAME_MAX) == 0)
|
||||
|
|
|
@ -488,7 +488,7 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg)
|
|||
case RT_TIMER_CTRL_SET_PERIODIC:
|
||||
timer->parent.flag |= RT_TIMER_FLAG_PERIODIC;
|
||||
break;
|
||||
/* zhaoshimin 20191204 add query the timer state */
|
||||
|
||||
case RT_TIMER_CTRL_GET_STATE:
|
||||
if(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue