slist.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. *********************************************************************************************************
  3. * uC/Common
  4. * Common Features for Micrium Stacks
  5. *
  6. * Copyright 2013-2020 Silicon Laboratories Inc. www.silabs.com
  7. *
  8. * SPDX-License-Identifier: APACHE-2.0
  9. *
  10. * This software is subject to an open source license and is distributed by
  11. * Silicon Laboratories Inc. pursuant to the terms of the Apache License,
  12. * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
  13. *
  14. *********************************************************************************************************
  15. */
  16. /*
  17. *********************************************************************************************************
  18. *
  19. * uC/Common - Singly-linked Lists (SList)
  20. *
  21. * Filename : slist.h
  22. * Version : V1.02.00
  23. *********************************************************************************************************
  24. */
  25. /*
  26. *********************************************************************************************************
  27. *********************************************************************************************************
  28. * MODULE
  29. *
  30. * Note(s) : (1) This library header file is protected from multiple pre-processor inclusion through
  31. * use of the library module present pre-processor macro definition.
  32. *********************************************************************************************************
  33. *********************************************************************************************************
  34. */
  35. #ifndef COLL_SLIST_MODULE_PRESENT /* See Note #1. */
  36. #define COLL_SLIST_MODULE_PRESENT
  37. /*
  38. *********************************************************************************************************
  39. *********************************************************************************************************
  40. * INCLUDE FILES
  41. *********************************************************************************************************
  42. *********************************************************************************************************
  43. */
  44. #include <cpu.h>
  45. /*
  46. *********************************************************************************************************
  47. *********************************************************************************************************
  48. * DATA TYPES
  49. *********************************************************************************************************
  50. *********************************************************************************************************
  51. */
  52. typedef struct slist_member SLIST_MEMBER;
  53. struct slist_member {
  54. SLIST_MEMBER *p_next;
  55. };
  56. /*
  57. *********************************************************************************************************
  58. *********************************************************************************************************
  59. * MACROS
  60. *********************************************************************************************************
  61. *********************************************************************************************************
  62. */
  63. #define OFFSET_OF(type, member) ((CPU_SIZE_T)&(((type *)0)->member))
  64. #define CONTAINER_OF(p_member, parent_type, member) (parent_type *)((CPU_ADDR)(p_member) - ((CPU_ADDR)(&((parent_type *)0)->member)))
  65. #define SLIST_FOR_EACH(list_head, iterator) for ((iterator) = (list_head); (iterator) != DEF_NULL; (iterator) = (iterator)->p_next)
  66. #define SLIST_FOR_EACH_ENTRY(list_head, entry, type, member) for ( (entry) = SLIST_ENTRY(list_head, type, member); \
  67. &((entry)->member.p_next) != DEF_NULL; \
  68. (entry) = SLIST_ENTRY((entry)->member.p_next, type, member))
  69. #define SLIST_ENTRY CONTAINER_OF
  70. /*
  71. *********************************************************************************************************
  72. *********************************************************************************************************
  73. * FUNCTION PROTOTYPES
  74. *********************************************************************************************************
  75. *********************************************************************************************************
  76. */
  77. void SList_Init (SLIST_MEMBER **p_head_ptr);
  78. void SList_Push (SLIST_MEMBER **p_head_ptr,
  79. SLIST_MEMBER *p_item);
  80. void SList_PushBack (SLIST_MEMBER **p_head_ptr,
  81. SLIST_MEMBER *p_item);
  82. SLIST_MEMBER *SList_Pop (SLIST_MEMBER **p_head_ptr);
  83. void SList_Add (SLIST_MEMBER *p_item,
  84. SLIST_MEMBER *p_pos);
  85. void SList_Rem (SLIST_MEMBER **p_head_ptr,
  86. SLIST_MEMBER *p_item);
  87. void SList_Sort (SLIST_MEMBER **p_head_ptr,
  88. CPU_BOOLEAN (*cmp_fnct)(SLIST_MEMBER *p_item_l, SLIST_MEMBER *p_item_r));
  89. #endif /* COLL_SLIST_MODULE_PRESENT */