add tos_slist.h, rename tos.h to tos_k.h
This commit is contained in:
@@ -15,8 +15,8 @@
|
||||
* within TencentOS.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _TOS_H_
|
||||
#define _TOS_H_
|
||||
#ifndef _TOS_K_H_
|
||||
#define _TOS_K_H_
|
||||
|
||||
#include <tos_compiler.h>
|
||||
#include <tos_err.h>
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <tos_fault.h>
|
||||
#include <tos_klib.h>
|
||||
#include <tos_list.h>
|
||||
#include <tos_slist.h>
|
||||
#include <tos_pend.h>
|
||||
#include <tos_sys.h>
|
||||
#include <tos_ring_queue.h>
|
||||
@@ -59,5 +60,5 @@
|
||||
#include <tos_tickless.h>
|
||||
#include <tos_global.h>
|
||||
|
||||
#endif /* _TOS_H_ */
|
||||
#endif /* _TOS_K_H_ */
|
||||
|
@@ -29,8 +29,8 @@ typedef struct k_list_node_st {
|
||||
#define TOS_LIST_DEFINE(list) \
|
||||
k_list_t list = { &(list), &(list) }
|
||||
|
||||
#define TOS_LIST_ENTRY(list, type, field) \
|
||||
TOS_CONTAINER_OF_FIELD(list, type, field)
|
||||
#define TOS_LIST_ENTRY(node, type, field) \
|
||||
TOS_CONTAINER_OF_FIELD(node, type, field)
|
||||
|
||||
#define TOS_LIST_FIRST_ENTRY(list, type, field) \
|
||||
TOS_LIST_ENTRY((list)->next, type, field)
|
||||
@@ -53,6 +53,28 @@ typedef struct k_list_node_st {
|
||||
curr != (list); \
|
||||
curr = next, next = curr->prev)
|
||||
|
||||
#define TOS_LIST_FOR_EACH_ENTRY(entry, type, field, list) \
|
||||
for (entry = TOS_LIST_ENTRY((list)->next, type, field); \
|
||||
&entry->field != (list); \
|
||||
entry = TOS_LIST_ENTRY(entry->field.next, type, field))
|
||||
|
||||
#define TOS_LIST_FOR_EACH_ENTRY_REVERSE(entry, type, field, list) \
|
||||
for (entry = TOS_LIST_ENTRY((list)->prev, type, field); \
|
||||
&entry->field != (list); \
|
||||
entry = TOS_LIST_ENTRY(entry->field.prev, type, field))
|
||||
|
||||
#define TOS_LIST_FOR_EACH_ENTRY_SAFE(entry, tmp, type, field, list) \
|
||||
for (entry = TOS_LIST_ENTRY((list)->next, type, field), \
|
||||
tmp = TOS_LIST_ENTRY(entry->field.next, type, field); \
|
||||
&entry->field != (list); \
|
||||
entry = tmp, tmp = TOS_LIST_ENTRY(entry->field.next, type, field))
|
||||
|
||||
#define TOS_LIST_FOR_EACH_ENTRY_SAFE_REVERSE(entry, tmp, type, field, list) \
|
||||
for (entry = TOS_LIST_ENTRY((list)->prev, type, field), \
|
||||
tmp = TOS_LIST_ENTRY(entry->field.prev, type, field); \
|
||||
&entry->field != (list); \
|
||||
entry = tmp, tmp = TOS_LIST_ENTRY(entry->field.prev, type, field))
|
||||
|
||||
__STATIC_INLINE__ void _list_add(k_list_t *node, k_list_t *prev, k_list_t *next)
|
||||
{
|
||||
next->prev = node;
|
||||
@@ -67,9 +89,9 @@ __STATIC_INLINE__ void _list_del(k_list_t *prev, k_list_t *next)
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
__STATIC_INLINE__ void _list_del_entry(k_list_t *entry)
|
||||
__STATIC_INLINE__ void _list_del_node(k_list_t *node)
|
||||
{
|
||||
_list_del(entry->prev, entry->next);
|
||||
_list_del(node->prev, node->next);
|
||||
}
|
||||
|
||||
__API__ __STATIC_INLINE__ void tos_list_init(k_list_t *list)
|
||||
@@ -88,26 +110,26 @@ __API__ __STATIC_INLINE__ void tos_list_add_tail(k_list_t *node, k_list_t *list)
|
||||
_list_add(node, list->prev, list);
|
||||
}
|
||||
|
||||
__API__ __STATIC_INLINE__ void tos_list_del(k_list_t *entry)
|
||||
__API__ __STATIC_INLINE__ void tos_list_del(k_list_t *node)
|
||||
{
|
||||
_list_del(entry->prev, entry->next);
|
||||
_list_del(node->prev, node->next);
|
||||
}
|
||||
|
||||
__API__ __STATIC_INLINE__ void tos_list_del_init(k_list_t *entry)
|
||||
__API__ __STATIC_INLINE__ void tos_list_del_init(k_list_t *node)
|
||||
{
|
||||
_list_del_entry(entry);
|
||||
tos_list_init(entry);
|
||||
_list_del_node(node);
|
||||
tos_list_init(node);
|
||||
}
|
||||
|
||||
__API__ __STATIC_INLINE__ void tos_list_move(k_list_t *node, k_list_t *list)
|
||||
{
|
||||
_list_del_entry(node);
|
||||
_list_del_node(node);
|
||||
tos_list_add(node, list);
|
||||
}
|
||||
|
||||
__API__ __STATIC_INLINE__ void tos_list_move_tail(k_list_t *node, k_list_t *list)
|
||||
{
|
||||
_list_del_entry(node);
|
||||
_list_del_node(node);
|
||||
tos_list_add_tail(node, list);
|
||||
}
|
||||
|
||||
|
156
kernel/core/include/tos_slist.h
Normal file
156
kernel/core/include/tos_slist.h
Normal file
@@ -0,0 +1,156 @@
|
||||
#ifndef _TOS_SLIST_H_
|
||||
#define _TOS_SLIST_H_
|
||||
|
||||
typedef struct k_slist_node_st {
|
||||
struct k_slist_node_st *next;
|
||||
} k_slist_t;
|
||||
|
||||
#define TOS_SLIST_NODE(node) \
|
||||
{ K_NULL }
|
||||
|
||||
#define TOS_SLIST_DEFINE(slist) \
|
||||
k_slist_t slist = { K_NULL }
|
||||
|
||||
#define TOS_SLIST_ENTRY(node, type, field) \
|
||||
TOS_CONTAINER_OF_FIELD(node, type, field)
|
||||
|
||||
#define TOS_SLIST_FIRST_ENTRY(slist, type, field) \
|
||||
TOS_SLIST_ENTRY((slist)->next, type, field)
|
||||
|
||||
#define TOS_SLIST_FIRST_ENTRY_OR_NULL(slist, type, field) \
|
||||
(tos_slist_empty(slist) ? K_NULL : TOS_SLIST_FIRST_ENTRY(slist, type, field))
|
||||
|
||||
#define TOS_SLIST_FOR_EACH(curr, slist) \
|
||||
for (curr = (slist)->next; curr; curr = curr->next)
|
||||
|
||||
#define TOS_SLIST_FOR_EACH_SAFE(curr, next, slist) \
|
||||
for (curr = (slist)->next, next = curr->next; curr; \
|
||||
curr = next, next = curr->next)
|
||||
|
||||
#define TOS_SLIST_FOR_EACH_ENTRY(entry, type, field, slist) \
|
||||
for (entry = TOS_SLIST_ENTRY((slist)->next, type, field); \
|
||||
&entry->field; \
|
||||
entry = TOS_SLIST_ENTRY(entry->field.next, type, field))
|
||||
|
||||
#define TOS_SLIST_FOR_EACH_ENTRY_SAFE(entry, tmp, type, field, slist) \
|
||||
for (entry = TOS_SLIST_ENTRY((slist)->next, type, field), \
|
||||
tmp = TOS_SLIST_ENTRY(entry->field.next, type, field); \
|
||||
&entry->field; \
|
||||
entry = tmp, tmp = TOS_SLIST_ENTRY(entry->field.next, type, field))
|
||||
|
||||
__API__ __STATIC_INLINE__ void tos_slist_init(k_slist_t *slist)
|
||||
{
|
||||
slist->next = K_NULL;
|
||||
}
|
||||
|
||||
__API__ __STATIC_INLINE__ k_slist_t *tos_slist_head(k_slist_t *slist)
|
||||
{
|
||||
return slist->next;
|
||||
}
|
||||
|
||||
__API__ __STATIC_INLINE__ k_slist_t *tos_slist_tail(k_slist_t *slist)
|
||||
{
|
||||
if (!slist->next) {
|
||||
return K_NULL;
|
||||
}
|
||||
|
||||
while (slist->next) {
|
||||
slist = slist->next;
|
||||
}
|
||||
|
||||
return slist;
|
||||
}
|
||||
|
||||
__API__ __STATIC_INLINE__ void tos_slist_add_head(k_slist_t *node, k_slist_t *slist)
|
||||
{
|
||||
node->next = slist->next;
|
||||
slist->next = node;
|
||||
}
|
||||
|
||||
__API__ __STATIC_INLINE__ void tos_slist_add_tail(k_slist_t *node, k_slist_t *slist)
|
||||
{
|
||||
node->next = K_NULL;
|
||||
|
||||
while (slist->next) {
|
||||
slist = slist->next;
|
||||
}
|
||||
|
||||
tos_slist_add_head(node, slist);
|
||||
}
|
||||
|
||||
__API__ __STATIC_INLINE__ void tos_slist_insert(k_slist_t *next_node, k_slist_t *new_node, k_slist_t *slist)
|
||||
{
|
||||
if (!next_node) {
|
||||
tos_slist_add_tail(new_node, slist);
|
||||
return;
|
||||
}
|
||||
|
||||
while (slist->next) {
|
||||
if (slist->next == next_node) {
|
||||
slist->next = new_node;
|
||||
new_node->next = next_node;
|
||||
}
|
||||
|
||||
slist = slist->next;
|
||||
}
|
||||
}
|
||||
|
||||
__API__ __STATIC_INLINE__ k_slist_t *tos_slist_del_head(k_slist_t *slist)
|
||||
{
|
||||
k_slist_t *head;
|
||||
|
||||
if (!slist->next) {
|
||||
return K_NULL;
|
||||
}
|
||||
|
||||
head = slist->next;
|
||||
slist->next = head->next;
|
||||
head->next = K_NULL;
|
||||
|
||||
return head;
|
||||
}
|
||||
|
||||
__API__ __STATIC_INLINE__ k_slist_t *tos_slist_del_tail(k_slist_t *slist)
|
||||
{
|
||||
while (slist->next) {
|
||||
if (!slist->next->next) {
|
||||
return tos_slist_del_head(slist);
|
||||
}
|
||||
|
||||
slist = slist->next;
|
||||
}
|
||||
|
||||
return K_NULL;
|
||||
}
|
||||
|
||||
__API__ __STATIC_INLINE__ void tos_slist_del(k_slist_t *node, k_slist_t *slist)
|
||||
{
|
||||
while (slist->next) {
|
||||
if (slist->next == node) {
|
||||
slist->next = node->next;
|
||||
break;
|
||||
}
|
||||
|
||||
slist = slist->next;
|
||||
}
|
||||
}
|
||||
|
||||
__API__ __STATIC_INLINE__ int tos_slist_length(k_slist_t *slist)
|
||||
{
|
||||
int len = 0;
|
||||
k_slist_t *iter;
|
||||
|
||||
TOS_SLIST_FOR_EACH(iter, slist) {
|
||||
++len;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
__API__ __STATIC_INLINE__ int tos_slist_empty(k_slist_t *slist)
|
||||
{
|
||||
return !slist->next;
|
||||
}
|
||||
|
||||
#endif /* _TOS_SLIST_H_ */
|
||||
|
Reference in New Issue
Block a user