mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-01-18 11:53:53 +08:00
Merge pull request #882 from armink/fix_rtservice
[rtservice] Add `rt_list_len` and `rt_slist_len` to rtservice.h .
This commit is contained in:
commit
e448ecc6ad
@ -49,19 +49,6 @@
|
||||
#include <rtthread.h>
|
||||
#include "finsh.h"
|
||||
|
||||
rt_inline unsigned int rt_list_len(const rt_list_t *l)
|
||||
{
|
||||
unsigned int len = 0;
|
||||
const rt_list_t *p = l;
|
||||
while (p->next != l)
|
||||
{
|
||||
p = p->next;
|
||||
len ++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
long hello(void)
|
||||
{
|
||||
rt_kprintf("Hello RT-Thread!\n");
|
||||
|
@ -104,6 +104,23 @@ rt_inline int rt_list_isempty(const rt_list_t *l)
|
||||
return l->next == l;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the list length
|
||||
* @param l the list to get.
|
||||
*/
|
||||
rt_inline unsigned int rt_list_len(const rt_list_t *l)
|
||||
{
|
||||
unsigned int len = 0;
|
||||
const rt_list_t *p = l;
|
||||
while (p->next != l)
|
||||
{
|
||||
p = p->next;
|
||||
len ++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the struct for this entry
|
||||
* @param node the entry point
|
||||
@ -177,6 +194,19 @@ rt_inline rt_slist_t *rt_slist_remove(rt_slist_t *l, rt_slist_t *n)
|
||||
return l;
|
||||
}
|
||||
|
||||
rt_inline unsigned int rt_slist_len(const rt_slist_t *l)
|
||||
{
|
||||
unsigned int len = 0;
|
||||
const rt_slist_t *list = l->next;
|
||||
while (list != RT_NULL)
|
||||
{
|
||||
list = list->next;
|
||||
len ++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the struct for this single list node
|
||||
* @param node the entry point
|
||||
|
Loading…
x
Reference in New Issue
Block a user