You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.3 KiB

2 years ago
  1. /**
  2. @file
  3. util.h
  4. @brief
  5. This file provides the definitions, and declares some common APIs for list-algorithm.
  6. */
  7. #ifndef _UTILS_H_
  8. #define _UTILS_H_
  9. #include <stddef.h>
  10. #include <glob.h>
  11. struct listnode
  12. {
  13. struct listnode *next;
  14. struct listnode *prev;
  15. };
  16. #define node_to_item(node, container, member) \
  17. (container *) (((char*) (node)) - offsetof(container, member))
  18. #define list_declare(name) \
  19. struct listnode name = { \
  20. .next = &name, \
  21. .prev = &name, \
  22. }
  23. #define list_for_each(node, list) \
  24. for (node = (list)->next; node != (list); node = node->next)
  25. #define list_for_each_reverse(node, list) \
  26. for (node = (list)->prev; node != (list); node = node->prev)
  27. void list_init(struct listnode *list);
  28. void list_add_tail(struct listnode *list, struct listnode *item);
  29. void list_add_head(struct listnode *head, struct listnode *item);
  30. void list_remove(struct listnode *item);
  31. #define list_empty(list) ((list) == (list)->next)
  32. #define list_head(list) ((list)->next)
  33. #define list_tail(list) ((list)->prev)
  34. int epoll_register(int epoll_fd, int fd, unsigned int events);
  35. int epoll_deregister(int epoll_fd, int fd);
  36. const char * get_time(void);
  37. unsigned long clock_msec(void);
  38. pid_t getpid_by_pdp(int, const char*);
  39. #endif