Sony PlayStation2 Study
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.

59 lines
1.4 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. # _____ ___ ____ ___ ____
  3. # ____| | ____| | | |____|
  4. # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
  5. #-----------------------------------------------------------------------
  6. # Copyright (c) 2003 Marcus R. Brown <mrbrown@0xd6.org>
  7. # Licenced under Academic Free License version 2.0
  8. # Review ps2sdk README & LICENSE files for further details.
  9. */
  10. /**
  11. * @file
  12. * Simple list support.
  13. */
  14. #ifndef __LIST_H__
  15. #define __LIST_H__
  16. typedef struct _list {
  17. struct _list *next;
  18. struct _list *prev;
  19. } list_t;
  20. #define LIST_INIT(name) { &(name), &(name) }
  21. static inline int list_empty(void *l)
  22. {
  23. list_t *list = (list_t *)l;
  24. return list->next == list && list->prev == list;
  25. }
  26. /** Insert an item after the given list. */
  27. static inline void list_insert(void *l, void *i)
  28. {
  29. list_t *list = (list_t *)l, *item = (list_t *)i;
  30. item->prev = list;
  31. item->next = list->next;
  32. list->next->prev = item;
  33. list->next = item;
  34. }
  35. /** Remove the item from the list and return the item. */
  36. static inline list_t *list_remove(void *i)
  37. {
  38. list_t *item = (list_t *)i;
  39. item->prev->next = item->next;
  40. item->next->prev = item->prev;
  41. return item;
  42. }
  43. /** Iterate over a list. Dir is 'next' to iterate forward and 'prev' to iterate in reverse. */
  44. #define list_for_each(dir, pos, head) \
  45. for (pos = (head)->dir; pos != (head); pos = pos->dir)
  46. #endif /* __LIST_H__ */