diff options
| author | Bernard Xiong <[email protected]> | 2018-09-12 10:03:46 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-09-12 10:03:46 +0800 |
| commit | e4bdcef4af5f708b5d4346a5cd75a5b8b226e011 (patch) | |
| tree | df39dec0396502fb00c058539c20057bba4aff7b /include | |
| parent | b1bbf434a658dac17d984fd3373d63c7f151be99 (diff) | |
| parent | a969b7096fc8e8f2519851ab5023da3854191287 (diff) | |
Merge pull request #1797 from armink/fix_slist
[slist] Add rt_slist_tail and rt_slist_tail_entry for slist.
Diffstat (limited to 'include')
| -rw-r--r-- | include/rtservice.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/rtservice.h b/include/rtservice.h index 0bfa424338..77a21d1f97 100644 --- a/include/rtservice.h +++ b/include/rtservice.h @@ -253,6 +253,13 @@ rt_inline rt_slist_t *rt_slist_first(rt_slist_t *l) return l->next; } +rt_inline rt_slist_t *rt_slist_tail(rt_slist_t *l) +{ + while (l->next) l = l->next; + + return l; +} + rt_inline rt_slist_t *rt_slist_next(rt_slist_t *n) { return n->next; @@ -302,6 +309,17 @@ rt_inline int rt_slist_isempty(rt_slist_t *l) #define rt_slist_first_entry(ptr, type, member) \ rt_slist_entry((ptr)->next, type, member) +/** + * rt_slist_tail_entry - get the tail element from a slist + * @ptr: the slist head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the name of the slist_struct within the struct. + * + * Note, that slist is expected to be not empty. + */ +#define rt_slist_tail_entry(ptr, type, member) \ + rt_slist_entry(rt_slist_tail(ptr), type, member) + /*@}*/ #ifdef __cplusplus |
