event.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. cl_command cmd = event->command;
  43. /* Remove from command queue */
  44. if (cq != NULL) {
  45. /* Lock command queue */
  46. pthread_mutex_lock(&cq->mutex);
  47. /* Remove barrier if applicable */
  48. if (cq->barrier == event->command)
  49. cq->barrier = NULL;
  50. /* Remove from the list of out-of-order commands */
  51. cq->commands = command_list_remove(cq->commands, cmd);
  52. /* Unlock command queue */
  53. pthread_mutex_unlock(&cq->mutex);
  54. gc_entity_unstore(&cq);
  55. }
  56. free(cmd->events);
  57. cmd->events = NULL;
  58. cmd->num_events = 0;
  59. /* Destruct object */
  60. //FIXME: we cannot release tag because it makes StarPU crash
  61. //starpu_tag_remove(event->id);
  62. }