GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-atomic.c
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2019-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include "oct-atomic.h"
31
32/* Some versions of GCC can't compile stdatomic.h with -fopenmp. */
33
34#if defined (OCTAVE_STDATOMIC_H_OK)
35# include <stdatomic.h>
36
39{
40 // This cast appears to be needed for some versions of clang.
41 atomic_fetch_add ((_Atomic octave_idx_type *) x, 1);
42
43 return *x;
44}
45
48{
49 // This cast appears to be needed for some versions of clang.
50 atomic_fetch_sub ((_Atomic octave_idx_type *) x, 1);
51
52 return *x;
53}
54
55#elif defined (__GNUC__)
56
59{
60 return __sync_add_and_fetch (x, 1);
61}
62
65{
66 return __sync_sub_and_fetch (x, 1);
67}
68
69#elif defined (_MSC_VER)
70# include <intrin.h>
71
74{
75#if defined (OCTAVE_ENABLE_64)
76 return _InterlockedIncrement64 (x);
77#else
78 return _InterlockedIncrement (x);
79#endif
80}
81
84{
85#if defined (OCTAVE_ENABLE_64)
86 return _InterlockedDecrement64 (x);
87#else
88 return _InterlockedDecrement (x);
89#endif
90}
91
92#else
93# error "Octave requires atomic integer increment and decrement functions"
94#endif
F77_RET_T const F77_DBLE * x
OCTAVE_API octave_idx_type octave_atomic_increment(octave_idx_type *x)
OCTAVE_API octave_idx_type octave_atomic_decrement(octave_idx_type *x)