sched_ctx_list.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2013 INRIA
  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. #include "sched_ctx_list.h"
  18. void _starpu_sched_ctx_list_init(struct _starpu_sched_ctx_list *list)
  19. {
  20. list->next = NULL;
  21. list->sched_ctx = STARPU_NMAX_SCHED_CTXS;
  22. }
  23. void _starpu_sched_ctx_list_add(struct _starpu_sched_ctx_list **list, unsigned sched_ctx)
  24. {
  25. if((*list)->sched_ctx == STARPU_NMAX_SCHED_CTXS)
  26. (*list)->sched_ctx = sched_ctx;
  27. else
  28. {
  29. struct _starpu_sched_ctx_list *l = (struct _starpu_sched_ctx_list*)malloc(sizeof(struct _starpu_sched_ctx_list));
  30. l->sched_ctx = sched_ctx;
  31. l->next = *list;
  32. *list = l;
  33. }
  34. }
  35. void _starpu_sched_ctx_list_remove(struct _starpu_sched_ctx_list **list, unsigned sched_ctx)
  36. {
  37. struct _starpu_sched_ctx_list *l = NULL;
  38. struct _starpu_sched_ctx_list *prev = NULL;
  39. for (l = (*list); l; l = l->next)
  40. {
  41. if(l->sched_ctx == sched_ctx)
  42. break;
  43. prev = l;
  44. }
  45. struct _starpu_sched_ctx_list *next = NULL;
  46. if(l->next)
  47. next = l->next;
  48. free(l);
  49. l = NULL;
  50. if(next)
  51. {
  52. if(prev)
  53. prev->next = next;
  54. else
  55. *list = next;
  56. }
  57. }
  58. unsigned _starpu_sched_ctx_list_get_sched_ctx(struct _starpu_sched_ctx_list *list, unsigned sched_ctx)
  59. {
  60. struct _starpu_sched_ctx_list *l = NULL;
  61. for (l = list; l; l = l->next)
  62. {
  63. if(l->sched_ctx == sched_ctx)
  64. return sched_ctx;
  65. }
  66. return STARPU_NMAX_SCHED_CTXS;
  67. }
  68. void _starpu_sched_ctx_list_delete(struct _starpu_sched_ctx_list **list)
  69. {
  70. while(*list)
  71. {
  72. struct _starpu_sched_ctx_list *next = (*list)->next;
  73. free(*list);
  74. *list = NULL;
  75. if(next)
  76. *list = next;
  77. }
  78. }