errorcheck.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), 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 <core/errorcheck.h>
  17. #include <core/workers.h>
  18. void _starpu_set_worker_status(struct _starpu_worker *worker, enum _starpu_worker_status st)
  19. {
  20. starpu_pthread_mutex_t *sched_mutex;
  21. starpu_pthread_cond_t *sched_cond;
  22. starpu_worker_get_sched_condition(worker->workerid, &sched_mutex, &sched_cond);
  23. STARPU_PTHREAD_MUTEX_LOCK_SCHED(sched_mutex);
  24. worker->status = st;
  25. STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(sched_mutex);
  26. }
  27. void _starpu_set_local_worker_status(enum _starpu_worker_status st)
  28. {
  29. struct _starpu_worker *worker = _starpu_get_local_worker_key();
  30. /* It is possible that we call this function from the application (and
  31. * thereforce outside a worker), for instance if we are executing the
  32. * callback function of a task with a "NULL" codelet. */
  33. if (worker)
  34. _starpu_set_worker_status(worker, st);
  35. }
  36. enum _starpu_worker_status _starpu_get_local_worker_status(void)
  37. {
  38. struct _starpu_worker *worker = _starpu_get_local_worker_key();
  39. if (STARPU_UNLIKELY(!worker))
  40. return STATUS_INVALID;
  41. return worker->status;
  42. }
  43. /* It is forbidden to call blocking operations with Callback and during the
  44. * execution of a task. */
  45. unsigned _starpu_worker_may_perform_blocking_calls(void)
  46. {
  47. enum _starpu_worker_status st = _starpu_get_local_worker_status();
  48. #ifdef STARPU_OPENMP
  49. /* When the current task is an OpenMP task, we may need to block,
  50. * especially when unregistering data used by child tasks. However,
  51. * we don't want to blindly disable the check for non OpenMP tasks. */
  52. const struct starpu_task * const task = starpu_task_get_current();
  53. const int blocking_call_check_override = task && task->omp_task;
  54. #else /* STARPU_OPENMP */
  55. const int blocking_call_check_override = 0;
  56. #endif /* STARPU_OPENMP */
  57. return blocking_call_check_override || ( !(st == STATUS_CALLBACK) && !(st == STATUS_EXECUTING));
  58. }