1*4c3eb207Smrg /* Copyright (C) 2005-2020 Free Software Foundation, Inc.
23ad841b2Smrg Contributed by Richard Henderson <rth@redhat.com>.
33ad841b2Smrg
43ad841b2Smrg This file is part of the GNU Offloading and Multi Processing Library
53ad841b2Smrg (libgomp).
63ad841b2Smrg
73ad841b2Smrg Libgomp is free software; you can redistribute it and/or modify it
83ad841b2Smrg under the terms of the GNU General Public License as published by
93ad841b2Smrg the Free Software Foundation; either version 3, or (at your option)
103ad841b2Smrg any later version.
113ad841b2Smrg
123ad841b2Smrg Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
133ad841b2Smrg WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
143ad841b2Smrg FOR A PARTICULAR PURPOSE. See the GNU General Public License for
153ad841b2Smrg more details.
163ad841b2Smrg
173ad841b2Smrg Under Section 7 of GPL version 3, you are granted additional
183ad841b2Smrg permissions described in the GCC Runtime Library Exception, version
193ad841b2Smrg 3.1, as published by the Free Software Foundation.
203ad841b2Smrg
213ad841b2Smrg You should have received a copy of the GNU General Public License and
223ad841b2Smrg a copy of the GCC Runtime Library Exception along with this program;
233ad841b2Smrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
243ad841b2Smrg <http://www.gnu.org/licenses/>. */
253ad841b2Smrg
263ad841b2Smrg /* This file contains helpers for the ATOMIC construct. */
273ad841b2Smrg
283ad841b2Smrg #include "libgomp.h"
293ad841b2Smrg
303ad841b2Smrg /* This mutex is used when atomic operations don't exist for the target
313ad841b2Smrg in the mode requested. The result is not globally atomic, but works so
323ad841b2Smrg long as all parallel references are within #pragma omp atomic directives.
333ad841b2Smrg According to responses received from omp@openmp.org, appears to be within
343ad841b2Smrg spec. Which makes sense, since that's how several other compilers
353ad841b2Smrg handle this situation as well. */
363ad841b2Smrg
373ad841b2Smrg static gomp_mutex_t atomic_lock;
383ad841b2Smrg
393ad841b2Smrg void
GOMP_atomic_start(void)403ad841b2Smrg GOMP_atomic_start (void)
413ad841b2Smrg {
423ad841b2Smrg gomp_mutex_lock (&atomic_lock);
433ad841b2Smrg }
443ad841b2Smrg
453ad841b2Smrg void
GOMP_atomic_end(void)463ad841b2Smrg GOMP_atomic_end (void)
473ad841b2Smrg {
483ad841b2Smrg gomp_mutex_unlock (&atomic_lock);
493ad841b2Smrg }
503ad841b2Smrg
513ad841b2Smrg #if !GOMP_MUTEX_INIT_0
523ad841b2Smrg static void __attribute__((constructor))
initialize_atomic(void)533ad841b2Smrg initialize_atomic (void)
543ad841b2Smrg {
553ad841b2Smrg gomp_mutex_init (&atomic_lock);
563ad841b2Smrg }
573ad841b2Smrg #endif
58