rtservice.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * File : rtservice.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2006-03-16 Bernard the first version
  13. * 2006-09-07 Bernard move the kservice APIs to rtthread.h
  14. * 2007-06-27 Bernard fix the rt_list_remove bug
  15. * 2012-03-22 Bernard rename kservice.h to rtservice.h
  16. */
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * @addtogroup KernelService
  22. */
  23. /*@{*/
  24. /**
  25. * @brief initialize a list
  26. *
  27. * @param l list to be initialized
  28. */
  29. rt_inline void rt_list_init(rt_list_t *l)
  30. {
  31. l->next = l->prev = l;
  32. }
  33. /**
  34. * @brief insert a node after a list
  35. *
  36. * @param l list to insert it
  37. * @param n new node to be inserted
  38. */
  39. rt_inline void rt_list_insert_after(rt_list_t *l, rt_list_t *n)
  40. {
  41. l->next->prev = n;
  42. n->next = l->next;
  43. l->next = n;
  44. n->prev = l;
  45. }
  46. /**
  47. * @brief insert a node before a list
  48. *
  49. * @param n new node to be inserted
  50. * @param l list to insert it
  51. */
  52. rt_inline void rt_list_insert_before(rt_list_t *l, rt_list_t *n)
  53. {
  54. l->prev->next = n;
  55. n->prev = l->prev;
  56. l->prev = n;
  57. n->next = l;
  58. }
  59. /**
  60. * @brief remove node from list.
  61. * @param n the node to remove from the list.
  62. */
  63. rt_inline void rt_list_remove(rt_list_t *n)
  64. {
  65. n->next->prev = n->prev;
  66. n->prev->next = n->next;
  67. n->next = n->prev = n;
  68. }
  69. /**
  70. * @brief tests whether a list is empty
  71. * @param l the list to test.
  72. */
  73. rt_inline int rt_list_isempty(const rt_list_t *l)
  74. {
  75. return l->next == l;
  76. }
  77. /**
  78. * @brief get the struct for this entry
  79. * @param node the entry point
  80. * @param type the type of structure
  81. * @param member the name of list in structure
  82. */
  83. #define rt_list_entry(node, type, member) \
  84. ((type *)((char *)(node) - (unsigned long)(&((type *)0)->member)))
  85. /*@}*/
  86. #ifdef __cplusplus
  87. }
  88. #endif