errorcheck.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010, 2014, 2016 Université de Bordeaux
  4. * Copyright (C) 2010, 2011 CNRS
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <core/errorcheck.h>
  18. #include <core/workers.h>
  19. void _starpu_set_worker_status(struct _starpu_worker *worker, enum _starpu_worker_status st)
  20. {
  21. starpu_pthread_mutex_t *sched_mutex;
  22. starpu_pthread_cond_t *sched_cond;
  23. starpu_worker_get_sched_condition(worker->workerid, &sched_mutex, &sched_cond);
  24. STARPU_PTHREAD_MUTEX_LOCK_SCHED(sched_mutex);
  25. worker->status = st;
  26. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(sched_mutex);
  27. }
  28. void _starpu_set_local_worker_status(enum _starpu_worker_status st)
  29. {
  30. struct _starpu_worker *worker = _starpu_get_local_worker_key();
  31. /* It is possible that we call this function from the application (and
  32. * thereforce outside a worker), for instance if we are executing the
  33. * callback function of a task with a "NULL" codelet. */
  34. if (worker)
  35. _starpu_set_worker_status(worker, st);
  36. }
  37. enum _starpu_worker_status _starpu_get_local_worker_status(void)
  38. {
  39. struct _starpu_worker *worker = _starpu_get_local_worker_key();
  40. if (STARPU_UNLIKELY(!worker))
  41. return STATUS_INVALID;
  42. return worker->status;
  43. }
  44. /* It is forbidden to call blocking operations with Callback and during the
  45. * execution of a task. */
  46. unsigned _starpu_worker_may_perform_blocking_calls(void)
  47. {
  48. enum _starpu_worker_status st = _starpu_get_local_worker_status();
  49. #ifdef STARPU_OPENMP
  50. /* When the current task is an OpenMP task, we may need to block,
  51. * especially when unregistering data used by child tasks. However,
  52. * we don't want to blindly disable the check for non OpenMP tasks. */
  53. const struct starpu_task * const task = starpu_task_get_current();
  54. const int blocking_call_check_override = task && task->omp_task;
  55. #else /* STARPU_OPENMP */
  56. const int blocking_call_check_override = 0;
  57. #endif /* STARPU_OPENMP */
  58. return blocking_call_check_override || ( !(st == STATUS_CALLBACK) && !(st == STATUS_EXECUTING));
  59. }