kservice.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * File : kservice.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2011, 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. */
  16. #ifndef __RT_SERVICE_H__
  17. #define __RT_SERVICE_H__
  18. #include <rtthread.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /**
  23. * @addtogroup KernelService
  24. */
  25. /*@{*/
  26. /**
  27. * @brief initialize a list
  28. *
  29. * @param l list to be initialized
  30. */
  31. rt_inline void rt_list_init(rt_list_t *l)
  32. {
  33. l->next = l->prev = l;
  34. }
  35. /**
  36. * @brief insert a node after a list
  37. *
  38. * @param l list to insert it
  39. * @param n new node to be inserted
  40. */
  41. rt_inline void rt_list_insert_after(rt_list_t *l, rt_list_t *n)
  42. {
  43. l->next->prev = n;
  44. n->next = l->next;
  45. l->next = n;
  46. n->prev = l;
  47. }
  48. /**
  49. * @brief insert a node before a list
  50. *
  51. * @param n new node to be inserted
  52. * @param l list to insert it
  53. */
  54. rt_inline void rt_list_insert_before(rt_list_t *l, rt_list_t *n)
  55. {
  56. l->prev->next = n;
  57. n->prev = l->prev;
  58. l->prev = n;
  59. n->next = l;
  60. }
  61. /**
  62. * @brief remove node from list.
  63. * @param n the node to remove from the list.
  64. */
  65. rt_inline void rt_list_remove(rt_list_t *n)
  66. {
  67. n->next->prev = n->prev;
  68. n->prev->next = n->next;
  69. n->next = n->prev = n;
  70. }
  71. /**
  72. * @brief tests whether a list is empty
  73. * @param l the list to test.
  74. */
  75. rt_inline int rt_list_isempty(const rt_list_t *l)
  76. {
  77. return l->next == l;
  78. }
  79. /**
  80. * @brief get the struct for this entry
  81. * @param node the entry point
  82. * @param type the type of structure
  83. * @param member the name of list in structure
  84. */
  85. #define rt_list_entry(node, type, member) \
  86. ((type *)((char *)(node) - (unsigned long)(&((type *)0)->member)))
  87. /*@}*/
  88. #ifdef __cplusplus
  89. }
  90. #endif
  91. #endif