diff options
| author | bernard <[email protected]> | 2017-10-15 22:30:05 +0800 |
|---|---|---|
| committer | bernard <[email protected]> | 2017-10-15 22:30:05 +0800 |
| commit | cd215b25455bf06dfeb8885fe4d8f5b30174a8c3 (patch) | |
| tree | d8fd2bac165526449fb9eccc004d5563374a722d /include/rtservice.h | |
| parent | 8bdf993bfc38f9b652a7af60cb071c708ad7dea6 (diff) | |
[Kernel] header files
1. Remove components.h file;
2. Add libc_* files for standard libc definitions;
3. Add rtdbg.h file for simple debug log;
4. Add single list implementation;
5. Change the 'rt_uint8_t' type of cmd to 'int'.
Diffstat (limited to 'include/rtservice.h')
| -rw-r--r-- | include/rtservice.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/include/rtservice.h b/include/rtservice.h index 99ad033280..0ace555cdc 100644 --- a/include/rtservice.h +++ b/include/rtservice.h @@ -134,6 +134,73 @@ rt_inline int rt_list_isempty(const rt_list_t *l) */ #define rt_list_first_entry(ptr, type, member) \ rt_list_entry((ptr)->next, type, member) + +#define RT_SLIST_OBJECT_INIT(object) { RT_NULL } + +/** + * @brief initialize a single list + * + * @param l the single list to be initialized + */ +rt_inline void rt_slist_init(rt_slist_t *l) +{ + l->next = RT_NULL; +} + +rt_inline void rt_slist_append(rt_slist_t *l, rt_slist_t *n) +{ + struct rt_slist_node *node; + + node = l; + while (node->next) node = node->next; + + /* append the node to the tail */ + node->next = n; + n->next = RT_NULL; +} + +rt_inline void rt_slist_insert(rt_slist_t *l, rt_slist_t *n) +{ + n->next = l->next; + l->next = n; +} + +rt_inline rt_slist_t *rt_slist_remove(rt_slist_t *l, rt_slist_t *n) +{ + /* remove slist head */ + struct rt_slist_node *node = l; + while (node->next && node->next != n) node = node->next; + + /* remove node */ + if (node->next != (rt_slist_t *)0) node->next = node->next->next; + + return l; +} + +/** + * @brief get the struct for this single list node + * @param node the entry point + * @param type the type of structure + * @param member the name of list in structure + */ +#define rt_slist_entry(node, type, member) \ + ((type *)((char*)(node)-(unsigned long)(&((type *)0)->member))) + +/** + * rt_slist_for_each_entry - iterate over single list of given type + * @node: the type * to use as a loop cursor. + * @list: the head for your single list. + */ +#define rt_slist_foreach(node, list) \ + for ((node) = (list)->next; (node) != RT_NULL; (node) = (node)->next) + +/** + * rt_container_of - return the member address of ptr, if the type of ptr is the + * struct type. + */ +#define rt_container_of(ptr, type, member) \ + ((type *)((char *)(ptr) - (unsigned long)(&((type *)0)->member))) + /*@}*/ #ifdef __cplusplus |
