errorcheck.c 2.6 KB

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