summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2017-10-19 16:33:07 +0800
committerGitHub <[email protected]>2017-10-19 16:33:07 +0800
commite448ecc6ad805109480ecc191f0e2d786216a297 (patch)
treeeee6696b3bb24065679a5afec00827cc0998ef63 /include
parent6e2260dae665b9d90a48fba3f41ad201deab21d7 (diff)
parentd3ac388846f8e8ba0592c25e3171fa6562c8f2b2 (diff)
Merge pull request #882 from armink/fix_rtservice
[rtservice] Add `rt_list_len` and `rt_slist_len` to rtservice.h .
Diffstat (limited to 'include')
-rw-r--r--include/rtservice.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/include/rtservice.h b/include/rtservice.h
index 0ace555cdc..2c6682076d 100644
--- a/include/rtservice.h
+++ b/include/rtservice.h
@@ -105,6 +105,23 @@ rt_inline int rt_list_isempty(const rt_list_t *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
* @param type the type of structure
@@ -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