sched_ctx_list.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. list->priority = 1;
  23. }
  24. void _starpu_sched_ctx_list_add(struct _starpu_sched_ctx_list **list, unsigned sched_ctx)
  25. {
  26. if((*list)->sched_ctx == STARPU_NMAX_SCHED_CTXS)
  27. (*list)->sched_ctx = sched_ctx;
  28. else
  29. {
  30. struct _starpu_sched_ctx_list *l = (struct _starpu_sched_ctx_list*)malloc(sizeof(struct _starpu_sched_ctx_list));
  31. l->sched_ctx = sched_ctx;
  32. l->priority = 1;
  33. l->next = *list;
  34. *list = l;
  35. }
  36. }
  37. void _starpu_sched_ctx_list_remove(struct _starpu_sched_ctx_list **list, unsigned sched_ctx)
  38. {
  39. struct _starpu_sched_ctx_list *l = NULL;
  40. struct _starpu_sched_ctx_list *prev = NULL;
  41. for (l = (*list); l; l = l->next)
  42. {
  43. if(l->sched_ctx == sched_ctx)
  44. break;
  45. prev = l;
  46. }
  47. struct _starpu_sched_ctx_list *next = NULL;
  48. if(l->next)
  49. next = l->next;
  50. free(l);
  51. l = NULL;
  52. if(next)
  53. {
  54. if(prev)
  55. prev->next = next;
  56. else
  57. *list = next;
  58. }
  59. }
  60. unsigned _starpu_sched_ctx_list_get_sched_ctx(struct _starpu_sched_ctx_list *list, unsigned sched_ctx)
  61. {
  62. struct _starpu_sched_ctx_list *l = NULL;
  63. for (l = list; l; l = l->next)
  64. {
  65. if(l->sched_ctx == sched_ctx)
  66. return sched_ctx;
  67. }
  68. return STARPU_NMAX_SCHED_CTXS;
  69. }
  70. void _starpu_sched_ctx_list_delete(struct _starpu_sched_ctx_list **list)
  71. {
  72. while(*list)
  73. {
  74. struct _starpu_sched_ctx_list *next = (*list)->next;
  75. free(*list);
  76. *list = NULL;
  77. if(next)
  78. *list = next;
  79. }
  80. }