starpu_task_list_inline.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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_INLINE_H
  17. #define __STARPU_TASK_LIST_INLINE_H
  18. #include <starpu.h>
  19. #ifndef STARPU_INLINE
  20. #ifdef __GNUC_GNU_INLINE__
  21. #define STARPU_INLINE extern inline
  22. #else
  23. #define STARPU_INLINE inline
  24. #endif
  25. #endif
  26. STARPU_INLINE
  27. void starpu_task_list_init(struct starpu_task_list *list)
  28. {
  29. list->head = NULL;
  30. list->tail = NULL;
  31. }
  32. STARPU_INLINE
  33. void starpu_task_list_push_front(struct starpu_task_list *list,
  34. struct starpu_task *task)
  35. {
  36. if (list->tail == NULL)
  37. {
  38. list->tail = task;
  39. }
  40. else
  41. {
  42. list->head->prev = task;
  43. }
  44. task->prev = NULL;
  45. task->next = list->head;
  46. list->head = task;
  47. }
  48. STARPU_INLINE
  49. void starpu_task_list_push_back(struct starpu_task_list *list,
  50. struct starpu_task *task)
  51. {
  52. if (list->head == NULL)
  53. {
  54. list->head = task;
  55. }
  56. else
  57. {
  58. list->tail->next = task;
  59. }
  60. task->next = NULL;
  61. task->prev = list->tail;
  62. list->tail = task;
  63. }
  64. STARPU_INLINE
  65. struct starpu_task *starpu_task_list_front(struct starpu_task_list *list)
  66. {
  67. return list->head;
  68. }
  69. STARPU_INLINE
  70. struct starpu_task *starpu_task_list_back(struct starpu_task_list *list)
  71. {
  72. return list->tail;
  73. }
  74. STARPU_INLINE
  75. int starpu_task_list_empty(struct starpu_task_list *list)
  76. {
  77. return (list->head == NULL);
  78. }
  79. STARPU_INLINE
  80. void starpu_task_list_erase(struct starpu_task_list *list,
  81. 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. 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. 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. STARPU_INLINE
  120. struct starpu_task *starpu_task_list_begin(struct starpu_task_list *list)
  121. {
  122. return list->head;
  123. }
  124. STARPU_INLINE
  125. struct starpu_task *starpu_task_list_end(struct starpu_task_list *list __attribute__ ((unused)))
  126. {
  127. return NULL;
  128. }
  129. STARPU_INLINE
  130. struct starpu_task *starpu_task_list_next(struct starpu_task *task)
  131. {
  132. return task->next;
  133. }
  134. #endif /* __STARPU_TASK_LIST_INLINE_H */