starpu_task_list.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2011 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. #include <starpu.h>
  17. void starpu_task_list_init(struct starpu_task_list *list)
  18. {
  19. list->head = NULL;
  20. list->tail = NULL;
  21. }
  22. void starpu_task_list_push_front(struct starpu_task_list *list,
  23. struct starpu_task *task)
  24. {
  25. if (list->tail == NULL)
  26. {
  27. list->tail = task;
  28. }
  29. else
  30. {
  31. list->head->prev = task;
  32. }
  33. task->prev = NULL;
  34. task->next = list->head;
  35. list->head = task;
  36. }
  37. void starpu_task_list_push_back(struct starpu_task_list *list,
  38. struct starpu_task *task)
  39. {
  40. if (list->head == NULL)
  41. {
  42. list->head = task;
  43. }
  44. else
  45. {
  46. list->tail->next = task;
  47. }
  48. task->next = NULL;
  49. task->prev = list->tail;
  50. list->tail = task;
  51. }
  52. struct starpu_task *starpu_task_list_front(struct starpu_task_list *list)
  53. {
  54. return list->head;
  55. }
  56. struct starpu_task *starpu_task_list_back(struct starpu_task_list *list)
  57. {
  58. return list->tail;
  59. }
  60. int starpu_task_list_empty(struct starpu_task_list *list)
  61. {
  62. return (list->head == NULL);
  63. }
  64. void starpu_task_list_erase(struct starpu_task_list *list,
  65. struct starpu_task *task)
  66. {
  67. struct starpu_task *p = task->prev;
  68. if (p)
  69. {
  70. p->next = task->next;
  71. }
  72. else
  73. {
  74. list->head = task->next;
  75. }
  76. if (task->next)
  77. {
  78. task->next->prev = p;
  79. }
  80. else
  81. {
  82. list->tail = p;
  83. }
  84. task->prev = NULL;
  85. task->next = NULL;
  86. }
  87. struct starpu_task *starpu_task_list_pop_front(struct starpu_task_list *list)
  88. {
  89. struct starpu_task *task = list->head;
  90. if (task)
  91. starpu_task_list_erase(list, task);
  92. return task;
  93. }
  94. struct starpu_task *starpu_task_list_pop_back(struct starpu_task_list *list)
  95. {
  96. struct starpu_task *task = list->tail;
  97. if (task)
  98. starpu_task_list_erase(list, task);
  99. return task;
  100. }
  101. struct starpu_task *starpu_task_list_begin(struct starpu_task_list *list)
  102. {
  103. return list->head;
  104. }
  105. struct starpu_task *starpu_task_list_end(struct starpu_task_list *list __attribute__ ((unused)))
  106. {
  107. return NULL;
  108. }
  109. struct starpu_task *starpu_task_list_next(struct starpu_task *task)
  110. {
  111. return task->next;
  112. }