bar.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Copyright (C) 2005-2022 Free Software Foundation, Inc.
  2. Contributed by Sebastian Huber <sebastian.huber@embedded-brains.de>.
  3. This file is part of the GNU OpenMP Library (libgomp).
  4. Libgomp is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. /* This is the RTEMS implementation of a barrier synchronization
  20. mechanism for libgomp. It is identical to the Linux implementation, except
  21. that the futex API is slightly different. This type is private to the
  22. library. */
  23. #include "libgomp.h"
  24. #include "bar.h"
  25. #include <limits.h>
  26. static gomp_barrier_t *
  27. generation_to_barrier (int *addr)
  28. {
  29. return (gomp_barrier_t *)
  30. ((char *) addr - __builtin_offsetof (gomp_barrier_t, generation));
  31. }
  32. static void
  33. futex_wait (int *addr, int val)
  34. {
  35. gomp_barrier_t *bar = generation_to_barrier (addr);
  36. _Futex_Wait (&bar->futex, addr, val);
  37. }
  38. static void
  39. futex_wake (int *addr, int count)
  40. {
  41. gomp_barrier_t *bar = generation_to_barrier (addr);
  42. _Futex_Wake (&bar->futex, count);
  43. }
  44. static int
  45. do_spin (int *addr, int val)
  46. {
  47. unsigned long long i, count = gomp_spin_count_var;
  48. if (__builtin_expect (gomp_managed_threads > gomp_available_cpus, 0))
  49. count = gomp_throttled_spin_count_var;
  50. for (i = 0; i < count; i++)
  51. if (__builtin_expect (__atomic_load_n (addr, MEMMODEL_RELAXED) != val, 0))
  52. return 0;
  53. return 1;
  54. }
  55. static void
  56. do_wait (int *addr, int val)
  57. {
  58. if (do_spin (addr, val))
  59. futex_wait (addr, val);
  60. }
  61. #define GOMP_WAIT_H 1
  62. #include "../linux/bar.c"