starpu_task_list.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2012, 2016 Université de Bordeaux
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #ifndef __STARPU_TASK_LIST_H__
  17. #define __STARPU_TASK_LIST_H__
  18. #include <starpu_task.h>
  19. #include <starpu_util.h>
  20. #ifdef __cplusplus
  21. extern "C"
  22. {
  23. #endif
  24. struct starpu_task_list
  25. {
  26. struct starpu_task *head;
  27. struct starpu_task *tail;
  28. };
  29. static STARPU_INLINE
  30. void starpu_task_list_init(struct starpu_task_list *list)
  31. {
  32. list->head = NULL;
  33. list->tail = NULL;
  34. }
  35. static STARPU_INLINE
  36. void starpu_task_list_push_front(struct starpu_task_list *list, struct starpu_task *task)
  37. {
  38. if (list->tail == NULL)
  39. {
  40. list->tail = task;
  41. }
  42. else
  43. {
  44. list->head->prev = task;
  45. }
  46. task->prev = NULL;
  47. task->next = list->head;
  48. list->head = task;
  49. }
  50. static STARPU_INLINE
  51. void starpu_task_list_push_back(struct starpu_task_list *list, struct starpu_task *task)
  52. {
  53. if (list->head == NULL)
  54. {
  55. list->head = task;
  56. }
  57. else
  58. {
  59. list->tail->next = task;
  60. }
  61. task->next = NULL;
  62. task->prev = list->tail;
  63. list->tail = task;
  64. }
  65. static STARPU_INLINE
  66. struct starpu_task *starpu_task_list_front(struct starpu_task_list *list)
  67. {
  68. return list->head;
  69. }
  70. static STARPU_INLINE
  71. struct starpu_task *starpu_task_list_back(struct starpu_task_list *list)
  72. {
  73. return list->tail;
  74. }
  75. static STARPU_INLINE
  76. int starpu_task_list_empty(struct starpu_task_list *list)
  77. {
  78. return (list->head == NULL);
  79. }
  80. static STARPU_INLINE
  81. void starpu_task_list_erase(struct starpu_task_list *list, struct starpu_task *task)
  82. {
  83. struct starpu_task *p = task->prev;
  84. if (p)
  85. {
  86. p->next = task->next;
  87. }
  88. else
  89. {
  90. list->head = task->next;
  91. }
  92. if (task->next)
  93. {
  94. task->next->prev = p;
  95. }
  96. else
  97. {
  98. list->tail = p;
  99. }
  100. task->prev = NULL;
  101. task->next = NULL;
  102. }
  103. static STARPU_INLINE
  104. struct starpu_task *starpu_task_list_pop_front(struct starpu_task_list *list)
  105. {
  106. struct starpu_task *task = list->head;
  107. if (task)
  108. starpu_task_list_erase(list, task);
  109. return task;
  110. }
  111. static STARPU_INLINE
  112. struct starpu_task *starpu_task_list_pop_back(struct starpu_task_list *list)
  113. {
  114. struct starpu_task *task = list->tail;
  115. if (task)
  116. starpu_task_list_erase(list, task);
  117. return task;
  118. }
  119. static STARPU_INLINE
  120. struct starpu_task *starpu_task_list_begin(struct starpu_task_list *list)
  121. {
  122. return list->head;
  123. }
  124. static STARPU_INLINE
  125. struct starpu_task *starpu_task_list_end(struct starpu_task_list *list STARPU_ATTRIBUTE_UNUSED)
  126. {
  127. return NULL;
  128. }
  129. static STARPU_INLINE
  130. struct starpu_task *starpu_task_list_next(struct starpu_task *task)
  131. {
  132. return task->next;
  133. }
  134. static STARPU_INLINE
  135. int starpu_task_list_ismember(struct starpu_task_list *list, struct starpu_task *look)
  136. {
  137. struct starpu_task *task;
  138. for (task = list->head; task != NULL; task = task->next)
  139. if (task == look)
  140. return 1;
  141. return 0;
  142. }
  143. #ifdef __cplusplus
  144. }
  145. #endif
  146. #endif /* __STARPU_TASK_LIST_H__ */