queues.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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 "queues.h"
  17. /*
  18. * There can be various queue designs
  19. * - trivial single list
  20. * - cilk-like
  21. * - hierarchical (marcel-like)
  22. */
  23. void _starpu_setup_queues(void (*init_queue_design)(void),
  24. struct starpu_jobq_s *(*func_init_queue)(void),
  25. struct starpu_machine_config_s *config)
  26. {
  27. unsigned worker;
  28. init_queue_design();
  29. for (worker = 0; worker < config->nworkers; worker++)
  30. {
  31. struct starpu_worker_s *workerarg = &config->workers[worker];
  32. workerarg->jobq = func_init_queue();
  33. }
  34. }
  35. /* this may return NULL for an "anonymous thread" */
  36. struct starpu_jobq_s *_starpu_get_local_queue(void)
  37. {
  38. struct starpu_sched_policy_s *policy = _starpu_get_sched_policy();
  39. return pthread_getspecific(policy->local_queue_key);
  40. }
  41. /* XXX how to retrieve policy ? that may be given in the machine config ? */
  42. void _starpu_set_local_queue(struct starpu_jobq_s *jobq)
  43. {
  44. struct starpu_sched_policy_s *policy = _starpu_get_sched_policy();
  45. pthread_setspecific(policy->local_queue_key, jobq);
  46. }
  47. void _starpu_jobq_lock(struct starpu_jobq_s *jobq)
  48. {
  49. pthread_mutex_lock(&jobq->activity_mutex);
  50. }
  51. void _starpu_jobq_unlock(struct starpu_jobq_s *jobq)
  52. {
  53. pthread_mutex_unlock(&jobq->activity_mutex);
  54. }
  55. int _starpu_jobq_trylock(struct starpu_jobq_s *jobq)
  56. {
  57. return pthread_mutex_trylock(&jobq->activity_mutex);
  58. }