cs_list.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * cs_list.h
  3. * Copyright (c) 2007-2018 ls
  4. **/
  5. #ifndef _CS_LIST_H_INCLUDED_
  6. #define _CS_LIST_H_INCLUDED_
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. typedef struct cs_list_node_s {
  11. void *data;
  12. struct cs_list_node_s *prev, *next;
  13. } cs_list_node_t;
  14. typedef struct cs_list_s {
  15. cs_list_node_t *head, *tail;
  16. } cs_list_t;
  17. #define cs_list_head(list) (list)->head
  18. #define cs_list_for_each(list, pos) for (\
  19. pos = (list)->head; (pos) != NULL; pos = (pos)->next)
  20. #define cs_list_for_each_safe(list, pos, tmp) for ( \
  21. pos = (list)->head, tmp = pos; (pos) != NULL; pos = (tmp)->next, tmp = pos)
  22. CS_API void cs_list_init(cs_list_t *list);
  23. CS_API void cs_list_add_head(cs_list_t *list, cs_list_node_t *node);
  24. CS_API void cs_list_add_tail(cs_list_t *list, cs_list_node_t *node);
  25. CS_API void cs_list_add_before(
  26. cs_list_t *list, cs_list_node_t *old, cs_list_node_t *node);
  27. CS_API void cs_list_add_after(
  28. cs_list_t *list, cs_list_node_t *old, cs_list_node_t *node);
  29. CS_API void cs_list_del(cs_list_t *list, cs_list_node_t *node);
  30. CS_API cs_list_node_t *cs_list_find_u32(cs_list_t *list, cs_uint_t key);
  31. CS_API cs_list_node_t *cs_list_find_u64(cs_list_t *list, cs_uint64_t key);
  32. #ifdef __cplusplus
  33. }
  34. #endif /* C++ support */
  35. #endif