1*b1e83836Smrg /* Copyright (C) 2005-2022 Free Software Foundation, Inc.
2b17d1066Smrg Contributed by Richard Henderson <rth@redhat.com>.
3b17d1066Smrg
4b17d1066Smrg This file is part of the GNU Offloading and Multi Processing Library
5b17d1066Smrg (libgomp).
6b17d1066Smrg
7b17d1066Smrg Libgomp is free software; you can redistribute it and/or modify it
8b17d1066Smrg under the terms of the GNU General Public License as published by
9b17d1066Smrg the Free Software Foundation; either version 3, or (at your option)
10b17d1066Smrg any later version.
11b17d1066Smrg
12b17d1066Smrg Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
13b17d1066Smrg WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14b17d1066Smrg FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15b17d1066Smrg more details.
16b17d1066Smrg
17b17d1066Smrg Under Section 7 of GPL version 3, you are granted additional
18b17d1066Smrg permissions described in the GCC Runtime Library Exception, version
19b17d1066Smrg 3.1, as published by the Free Software Foundation.
20b17d1066Smrg
21b17d1066Smrg You should have received a copy of the GNU General Public License and
22b17d1066Smrg a copy of the GCC Runtime Library Exception along with this program;
23b17d1066Smrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24b17d1066Smrg <http://www.gnu.org/licenses/>. */
25b17d1066Smrg
26b17d1066Smrg /* This file contains helpers for the ATOMIC construct. */
27b17d1066Smrg
28b17d1066Smrg #include "libgomp.h"
29b17d1066Smrg
30b17d1066Smrg /* This mutex is used when atomic operations don't exist for the target
31b17d1066Smrg in the mode requested. The result is not globally atomic, but works so
32b17d1066Smrg long as all parallel references are within #pragma omp atomic directives.
33b17d1066Smrg According to responses received from omp@openmp.org, appears to be within
34b17d1066Smrg spec. Which makes sense, since that's how several other compilers
35b17d1066Smrg handle this situation as well. */
36b17d1066Smrg
37b17d1066Smrg static gomp_mutex_t atomic_lock;
38b17d1066Smrg
39b17d1066Smrg void
GOMP_atomic_start(void)40b17d1066Smrg GOMP_atomic_start (void)
41b17d1066Smrg {
42b17d1066Smrg gomp_mutex_lock (&atomic_lock);
43b17d1066Smrg }
44b17d1066Smrg
45b17d1066Smrg void
GOMP_atomic_end(void)46b17d1066Smrg GOMP_atomic_end (void)
47b17d1066Smrg {
48b17d1066Smrg gomp_mutex_unlock (&atomic_lock);
49b17d1066Smrg }
50b17d1066Smrg
51b17d1066Smrg #if !GOMP_MUTEX_INIT_0
52b17d1066Smrg static void __attribute__((constructor))
initialize_atomic(void)53b17d1066Smrg initialize_atomic (void)
54b17d1066Smrg {
55b17d1066Smrg gomp_mutex_init (&atomic_lock);
56b17d1066Smrg }
57b17d1066Smrg #endif
58