1 /* Copyright (C) 2005-2019 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <rth@redhat.com>.
4 This file is part of the GNU Offloading and Multi Processing Library
7 Libgomp is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 /* This is a generic implementation of the public OpenMP locking primitives in
27 terms of internal gomp_mutex_t. It is not meant to be compiled on its own.
28 It is #include'd from config/{linux,nvptx}/lock.c. */
33 /* The internal gomp_mutex_t and the external non-recursive omp_lock_t
34 have the same form. Re-use it. */
37 gomp_init_lock_30 (omp_lock_t
*lock
)
39 gomp_mutex_init (lock
);
43 gomp_destroy_lock_30 (omp_lock_t
*lock
)
45 gomp_mutex_destroy (lock
);
49 gomp_set_lock_30 (omp_lock_t
*lock
)
51 gomp_mutex_lock (lock
);
55 gomp_unset_lock_30 (omp_lock_t
*lock
)
57 gomp_mutex_unlock (lock
);
61 gomp_test_lock_30 (omp_lock_t
*lock
)
65 return __atomic_compare_exchange_n (lock
, &oldval
, 1, false,
66 MEMMODEL_ACQUIRE
, MEMMODEL_RELAXED
);
70 gomp_init_nest_lock_30 (omp_nest_lock_t
*lock
)
72 memset (lock
, '\0', sizeof (*lock
));
76 gomp_destroy_nest_lock_30 (omp_nest_lock_t
*lock
)
81 gomp_set_nest_lock_30 (omp_nest_lock_t
*lock
)
83 void *me
= gomp_icv (true);
85 if (lock
->owner
!= me
)
87 gomp_mutex_lock (&lock
->lock
);
95 gomp_unset_nest_lock_30 (omp_nest_lock_t
*lock
)
97 if (--lock
->count
== 0)
100 gomp_mutex_unlock (&lock
->lock
);
105 gomp_test_nest_lock_30 (omp_nest_lock_t
*lock
)
107 void *me
= gomp_icv (true);
110 if (lock
->owner
== me
)
111 return ++lock
->count
;
114 if (__atomic_compare_exchange_n (&lock
->lock
, &oldval
, 1, false,
115 MEMMODEL_ACQUIRE
, MEMMODEL_RELAXED
))