starpu_task_list.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2012 Université de Bordeaux 1
  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,
  37. struct starpu_task *task)
  38. {
  39. if (list->tail == NULL)
  40. {
  41. list->tail = task;
  42. }
  43. else
  44. {
  45. list->head->prev = task;
  46. }
  47. task->prev = NULL;
  48. task->next = list->head;
  49. list->head = task;
  50. }
  51. static STARPU_INLINE
  52. void starpu_task_list_push_back(struct starpu_task_list *list,
  53. struct starpu_task *task)
  54. {
  55. if (list->head == NULL)
  56. {
  57. list->head = task;
  58. }
  59. else
  60. {
  61. list->tail->next = task;
  62. }
  63. task->next = NULL;
  64. task->prev = list->tail;
  65. list->tail = task;
  66. }
  67. static STARPU_INLINE
  68. struct starpu_task *starpu_task_list_front(struct starpu_task_list *list)
  69. {
  70. return list->head;
  71. }
  72. static STARPU_INLINE
  73. struct starpu_task *starpu_task_list_back(struct starpu_task_list *list)
  74. {
  75. return list->tail;
  76. }
  77. static STARPU_INLINE
  78. int starpu_task_list_empty(struct starpu_task_list *list)
  79. {
  80. return (list->head == NULL);
  81. }
  82. static STARPU_INLINE
  83. void starpu_task_list_erase(struct starpu_task_list *list,
  84. struct starpu_task *task)
  85. {
  86. struct starpu_task *p = task->prev;
  87. if (p)
  88. {
  89. p->next = task->next;
  90. }
  91. else
  92. {
  93. list->head = task->next;
  94. }
  95. if (task->next)
  96. {
  97. task->next->prev = p;
  98. }
  99. else
  100. {
  101. list->tail = p;
  102. }
  103. task->prev = NULL;
  104. task->next = NULL;
  105. }
  106. static STARPU_INLINE
  107. struct starpu_task *starpu_task_list_pop_front(struct starpu_task_list *list)
  108. {
  109. struct starpu_task *task = list->head;
  110. if (task)
  111. starpu_task_list_erase(list, task);
  112. return task;
  113. }
  114. static STARPU_INLINE
  115. struct starpu_task *starpu_task_list_pop_back(struct starpu_task_list *list)
  116. {
  117. struct starpu_task *task = list->tail;
  118. if (task)
  119. starpu_task_list_erase(list, task);
  120. return task;
  121. }
  122. static STARPU_INLINE
  123. struct starpu_task *starpu_task_list_begin(struct starpu_task_list *list)
  124. {
  125. return list->head;
  126. }
  127. static STARPU_INLINE
  128. struct starpu_task *starpu_task_list_end(struct starpu_task_list *list STARPU_ATTRIBUTE_UNUSED)
  129. {
  130. return NULL;
  131. }
  132. static STARPU_INLINE
  133. struct starpu_task *starpu_task_list_next(struct starpu_task *task)
  134. {
  135. return task->next;
  136. }
  137. #ifdef __cplusplus
  138. }
  139. #endif
  140. #endif /* __STARPU_TASK_LIST_H__ */