GNU Octave  9.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-2024 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 #if defined (__GNUC__)
33 
36 {
37  return __sync_add_and_fetch (x, 1);
38 }
39 
42 {
43  return __sync_sub_and_fetch (x, 1);
44 }
45 
46 /* Some versions of GCC can't compile stdatomic.h with -fopenmp. */
47 
48 #elif defined (OCTAVE_STDATOMIC_H_OK)
49 # include <stdatomic.h>
50 
53 {
54  // This cast appears to be needed for some versions of clang.
55  atomic_fetch_add ((_Atomic octave_idx_type *) x, 1);
56 
57  return *x;
58 }
59 
62 {
63  // This cast appears to be needed for some versions of clang.
64  atomic_fetch_sub ((_Atomic octave_idx_type *) x, 1);
65 
66  return *x;
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_idx_type octave_atomic_increment(octave_idx_type *x)
octave_idx_type octave_atomic_decrement(octave_idx_type *x)