command_list.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012,2017 CNRS
  4. * Copyright (C) 2010-2012 Université de Bordeaux
  5. * Copyright (C) 2011,2012 Inria
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include "socl.h"
  19. command_list command_list_cons(cl_command cmd, command_list ls)
  20. {
  21. command_list e = malloc(sizeof(struct command_list_t));
  22. e->cmd = cmd;
  23. e->next = ls;
  24. e->prev = NULL;
  25. if (ls != NULL)
  26. ls->prev = e;
  27. return e;
  28. }
  29. /**
  30. * Remove every occurence of cmd in the list l
  31. */
  32. command_list command_list_remove(command_list l, cl_command cmd)
  33. {
  34. command_list e = l;
  35. while (e != NULL)
  36. {
  37. if (e->cmd == cmd)
  38. {
  39. if (e->prev != NULL) e->prev->next = e->next;
  40. if (e->next != NULL) e->next->prev = e->prev;
  41. command_list old = e;
  42. if (l == old)
  43. { // list head has been removed
  44. l = old->next;
  45. }
  46. e = old->next;
  47. free(old);
  48. }
  49. else
  50. {
  51. e = e->next;
  52. }
  53. }
  54. return l;
  55. }