api_list.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef _API_LIST_H
  2. #define _API_LIST_H
  3. typedef struct list_hdr {
  4. struct list_hdr *next;
  5. } list_hdr_t;
  6. typedef struct {
  7. struct list_hdr *first;
  8. struct list_hdr *last;
  9. } list_t;
  10. /**
  11. * @brief Initialize a list of free element in target pool.
  12. * @param list: Pointer to the list.
  13. * @param pool: Pointer to the free pool.
  14. * @param elt_size: Size of each element of the free pool.
  15. * @param elt_cnt: Count of elements in free pool.
  16. * @retval None.
  17. */
  18. void list_pool_init(list_t *list, void *pool, size_t elt_size, uint32_t elt_cnt);
  19. /**
  20. * @brief Push an element into target list rear.
  21. * @param list: Pointer to the list.
  22. * @param list_hdr: Pointer to the target element.
  23. * @retval None.
  24. */
  25. void list_push_back(list_t *list, list_hdr_t *list_hdr);
  26. /**
  27. * @brief Pop first element from target list.
  28. * @param list: Pointer to the list.
  29. * @retval List element head pointer.
  30. */
  31. list_hdr_t *list_pop_front(list_t *list);
  32. /**
  33. * @brief Statistic the element counts in list.
  34. * @param list: Pointer to the list.
  35. * @retval Counts of element in list.
  36. */
  37. uint16_t list_size(list_t *list);
  38. #endif // _API_LIST_H