event.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010,2011 University of Bordeaux
  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 "socl.h"
  17. #include "event.h"
  18. #include "gc.h"
  19. static void release_callback_event(void * e);
  20. int event_unique_id() {
  21. static int id = 1;
  22. return __sync_fetch_and_add(&id,1);
  23. }
  24. /**
  25. * Create a new event
  26. *
  27. * Events have one-to-one relation with tag. Tag number is event ID
  28. */
  29. cl_event event_create(void) {
  30. cl_event ev;
  31. ev = gc_entity_alloc(sizeof(struct _cl_event), release_callback_event);
  32. ev->id = event_unique_id();
  33. ev->status = CL_SUBMITTED;
  34. ev->command = NULL;
  35. ev->profiling_info = NULL;
  36. ev->cq = NULL;
  37. return ev;
  38. }
  39. static void release_callback_event(void * e) {
  40. cl_event event = (cl_event)e;
  41. cl_command_queue cq = event->cq;
  42. /* Remove from command queue */
  43. if (cq != NULL) {
  44. /* Lock command queue */
  45. pthread_mutex_lock(&cq->mutex);
  46. /* Remove barrier if applicable */
  47. if (cq->barrier == event->command)
  48. cq->barrier = NULL;
  49. /* Remove from the list of out-of-order commands */
  50. cq->commands = command_list_remove(cq->commands, event->command);
  51. /* Unlock command queue */
  52. pthread_mutex_unlock(&cq->mutex);
  53. gc_entity_unstore(&cq);
  54. }
  55. /* Destruct object */
  56. //FIXME: we cannot release tag because it makes StarPU crash
  57. //starpu_tag_remove(event->id);
  58. }