klist.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* vccd/include/klist.h
  2. *
  3. * This file is part of vccd.
  4. *
  5. * vccd is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * vccd is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with vccd. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #ifndef __KLIST_H
  19. #define __KLIST_H
  20. #include <vcc/vcc.h>
  21. /* before, i think using a 'container_of' in things we did in kernel
  22. * is silly, but now i realize that, i'm the stupid one, there are
  23. * too many things in the structure. */
  24. struct klist_node {
  25. long value;
  26. union {
  27. void *data;
  28. int nusers;
  29. };
  30. union {
  31. char *usrname;
  32. struct klist_node *connection;
  33. };
  34. union {
  35. struct klist_node *sending;
  36. struct klist_node *session;
  37. };
  38. struct klist_node *next, *prev;
  39. };
  40. struct klist_node *klist_find_value(struct klist_node *head, int value);
  41. void klist_init(struct klist_node *head);
  42. void klist_add(struct klist_node *head, struct klist_node *new);
  43. void klist_del(struct klist_node *head, struct klist_node *will_del);
  44. #define klist_empty(list) ((list)->next == (list))
  45. #define KLIST_NODE_INIT(__x) { \
  46. .value = 0, \
  47. .data = NULL, \
  48. .sending = NULL, \
  49. .usrname = NULL, \
  50. .next = __x, \
  51. .prev = __x, \
  52. }
  53. #endif