starpu_task_list.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 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. list->head->prev = task;
  31. }
  32. task->prev = NULL;
  33. task->next = list->head;
  34. list->head = task;
  35. }
  36. void starpu_task_list_push_back(struct starpu_task_list *list,
  37. struct starpu_task *task)
  38. {
  39. if (list->head == NULL)
  40. {
  41. list->head = task;
  42. }
  43. else {
  44. list->tail->next = task;
  45. }
  46. task->next = NULL;
  47. task->prev = list->tail;
  48. list->tail = task;
  49. }
  50. struct starpu_task *starpu_task_list_front(struct starpu_task_list *list)
  51. {
  52. return list->head;
  53. }
  54. struct starpu_task *starpu_task_list_back(struct starpu_task_list *list)
  55. {
  56. return list->tail;
  57. }
  58. int starpu_task_list_empty(struct starpu_task_list *list)
  59. {
  60. return (list->head == NULL);
  61. }
  62. void starpu_task_list_erase(struct starpu_task_list *list,
  63. struct starpu_task *task)
  64. {
  65. struct starpu_task *p = task->prev;
  66. if (p)
  67. {
  68. p->next = task->next;
  69. }
  70. else {
  71. list->head = task->next;
  72. }
  73. if (task->next)
  74. {
  75. task->next->prev = p;
  76. }
  77. else {
  78. list->tail = p;
  79. }
  80. task->prev = NULL;
  81. task->next = NULL;
  82. }
  83. struct starpu_task *starpu_task_list_pop_front(struct starpu_task_list *list)
  84. {
  85. struct starpu_task *task = list->head;
  86. if (task)
  87. starpu_task_list_erase(list, task);
  88. return task;
  89. }
  90. struct starpu_task *starpu_task_list_pop_back(struct starpu_task_list *list)
  91. {
  92. struct starpu_task *task = list->tail;
  93. if (task)
  94. starpu_task_list_erase(list, task);
  95. return task;
  96. }