exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / simple-atomic.h
blob6205c91f0af940ab19138266fb93c07448915497
1 /* Simple atomic operations for multithreading.
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 This file is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2021. */
19 #ifndef _SIMPLE_ATOMIC_H
20 #define _SIMPLE_ATOMIC_H
22 #include <stdint.h>
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 /* Guarantees that memory stores that are in code before this call
29 are finished before this call, and that memory loads that are in code
30 after this call are started after this call. */
31 extern void memory_barrier (void);
33 /* Stores NEWVAL in *VP if the old value *VP is == CMP.
34 Returns the old value. */
35 extern unsigned int atomic_compare_and_swap (unsigned int volatile *vp,
36 unsigned int cmp,
37 unsigned int newval);
39 /* Stores NEWVAL in *VP if the old value *VP is == CMP.
40 Returns the old value. */
41 extern uintptr_t atomic_compare_and_swap_ptr (uintptr_t volatile *vp,
42 uintptr_t cmp,
43 uintptr_t newval);
45 #ifdef __cplusplus
47 #endif
49 #endif /* _SIMPLE_ATOMIC_H */