PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/Chapter_07_Threads/00_Start/lib/list.h

https://github.com/l30nard0/os4ec
C Header | 72 lines | 27 code | 8 blank | 37 comment | 0 complexity | 5f7ecd279753488e1f2173d5d4ff00f2 MD5 | raw file
  1. /*! List manipulation functions
  2. *
  3. * Double linked lists are used
  4. * List header points to first and last list element
  5. *
  6. */
  7. #pragma once
  8. /*! List element pointers */
  9. typedef struct _list_h_
  10. {
  11. struct _list_h_ *prev; /* pointer to previous list element */
  12. struct _list_h_ *next; /* pointer to next list element */
  13. void *object; /* pointer to object start */
  14. }
  15. list_h;
  16. /*! list header type */
  17. typedef struct _list_
  18. {
  19. list_h *first;
  20. list_h *last;
  21. }
  22. list_t;
  23. /*
  24. List element must be included in object that we want to put in list. Place and
  25. variable name is unimportant, but must be used when calling list functions.
  26. Simple list width only two elements will look like:
  27. struct some_object {
  28. int something;
  29. ...
  30. list_h le1; // list element 1 for list1
  31. ...
  32. } object1, object2;
  33. list_t some_list1;
  34. --when list is formed and both object are in list, data will lool like:
  35. some_list1.first = &object1.le1
  36. some_list1.last = &object2.le1
  37. object1.le1.prev = NULL; object2.le1.prev = &object2.le1;
  38. object1.le1.next = &object2.le1; object2.le1.next = NULL;
  39. object1.le1.object = &object1 object2.le1.object = &object2;
  40. Same object can be in multiple list simultaneously if it have multiple list
  41. element data member (e.g. le2, le3).
  42. */
  43. /* for static list elements initialization */
  44. #define LIST_H_NULL { NULL, NULL, NULL }
  45. /* for static list initialization (empty list) */
  46. #define LIST_T_NULL { NULL, NULL }
  47. #define FIRST 0 /* get first or last list element */
  48. #define LAST 1
  49. void list_init ( list_t *list );
  50. void list_append ( list_t *list, void *object, list_h *hdr );
  51. void list_prepend ( list_t *list, void *object, list_h *hdr );
  52. void list_sort_add ( list_t *list, void *object, list_h *hdr,
  53. int (*cmp) ( void *, void * ) );
  54. void *list_get ( list_t *list, unsigned int flags );
  55. void *list_remove ( list_t *list, unsigned int flags, list_h *ref );
  56. void *list_find_and_remove ( list_t *list, list_h *ref );
  57. void *list_get_next ( list_h *hdr );