mqtt_list.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * @Author: jiejie
  3. * @Github: https://github.com/jiejieTop
  4. * @Date: 2019-12-11 22:46:33
  5. * @LastEditTime: 2020-04-27 23:28:12
  6. * @Description: the following code references TencentOS tiny, please keep the author information and source code according to the license.
  7. */
  8. # include "mqtt_list.h"
  9. static void _mqtt_list_add(mqtt_list_t *node, mqtt_list_t *prev, mqtt_list_t *next)
  10. {
  11. next->prev = node;
  12. node->next = next;
  13. node->prev = prev;
  14. prev->next = node;
  15. }
  16. static void _mqtt_list_del(mqtt_list_t *prev, mqtt_list_t *next)
  17. {
  18. next->prev = prev;
  19. prev->next = next;
  20. }
  21. static void _mqtt_list_del_entry(mqtt_list_t *entry)
  22. {
  23. _mqtt_list_del(entry->prev, entry->next);
  24. }
  25. void mqtt_list_init(mqtt_list_t *list)
  26. {
  27. list->next = list;
  28. list->prev = list;
  29. }
  30. void mqtt_list_add(mqtt_list_t *node, mqtt_list_t *list)
  31. {
  32. _mqtt_list_add(node, list, list->next);
  33. }
  34. void mqtt_list_add_tail(mqtt_list_t *node, mqtt_list_t *list)
  35. {
  36. _mqtt_list_add(node, list->prev, list);
  37. }
  38. void mqtt_list_del(mqtt_list_t *entry)
  39. {
  40. _mqtt_list_del(entry->prev, entry->next);
  41. }
  42. void mqtt_list_del_init(mqtt_list_t *entry)
  43. {
  44. _mqtt_list_del_entry(entry);
  45. mqtt_list_init(entry);
  46. }
  47. void mqtt_list_move(mqtt_list_t *node, mqtt_list_t *list)
  48. {
  49. _mqtt_list_del_entry(node);
  50. mqtt_list_add(node, list);
  51. }
  52. void mqtt_list_move_tail(mqtt_list_t *node, mqtt_list_t *list)
  53. {
  54. _mqtt_list_del_entry(node);
  55. mqtt_list_add_tail(node, list);
  56. }
  57. int mqtt_list_is_empty(mqtt_list_t *list)
  58. {
  59. return list->next == list;
  60. }