annotate liboctave/util/oct-refcount.h @ 23615:be7b884ac589

use version number in OCTAVE_DEPRECATED macro * mk-octave-config-h.sh, oct-conf-post.in.h (OCTAVE_DEPRECATED): New argument, VER, to record and display version number in which the object was marked as deprecated. Change all uses.
author John W. Eaton <jwe@octave.org>
date Fri, 16 Jun 2017 09:19:20 -0400
parents cd4e1ee28716
children ece6f43304e5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
1 /*
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
2
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 2012-2017 Jaroslav Hajek
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
4
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
5 This file is part of Octave.
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
6
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
8 under the terms of the GNU General Public License as published by
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
10 (at your option) any later version.
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
15 GNU General Public License for more details.
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
16
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
20
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
21 */
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
22
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 19697
diff changeset
23 #if ! defined (octave_oct_refcount_h)
17822
ebb3ef964372 maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents: 17769
diff changeset
24 #define octave_oct_refcount_h 1
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
25
21240
7af5ca01ecac allow octave-config.h to be included unconditionally
John W. Eaton <jwe@octave.org>
parents: 21229
diff changeset
26 #include "octave-config.h"
13985
43cc49c7abd1 Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 12174
diff changeset
27
22381
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
28 #if (defined (OCTAVE_ENABLE_ATOMIC_REFCOUNT) \
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
29 && (defined (__GNUC__) || defined (_MSC_VER)))
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
30
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
31 # if defined (__GNUC__)
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
32
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
33 # define OCTAVE_ATOMIC_INCREMENT(x) __sync_add_and_fetch (x, 1)
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
34 # define OCTAVE_ATOMIC_DECREMENT(x) __sync_add_and_fetch (x, -1)
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
35 # define OCTAVE_ATOMIC_POST_INCREMENT(x) __sync_fetch_and_add (x, 1)
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
36 # define OCTAVE_ATOMIC_POST_DECREMENT(x) __sync_fetch_and_add (x, -1)
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
37
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
38 # elif defined (_MSC_VER)
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
39
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 21139
diff changeset
40 # include <intrin.h>
22381
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
41
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
42 # define OCTAVE_ATOMIC_INCREMENT(x) \
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
43 _InterlockedIncrement (static_cast<long *> (x))
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
44
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
45 # define OCTAVE_ATOMIC_DECREMENT(x) \
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
46 _InterlockedDecrement (static_cast<long *> (x))
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
47
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
48 # define OCTAVE_ATOMIC_POST_INCREMENT(x) \
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
49 _InterlockedExchangeAdd (static_cast<long *> (x))
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
50
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
51 # define OCTAVE_ATOMIC_POST_DECREMENT(x) \
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
52 _InterlockedExchangeAdd (static_cast<long *> (x))
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
53
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 21139
diff changeset
54 # endif
22381
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
55
20945
9d9270e2f98f eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
56 #else
22381
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
57
20945
9d9270e2f98f eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
58 // Generic non-locking versions
22381
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
59
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
60 # define OCTAVE_ATOMIC_INCREMENT(x) ++(*(x))
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
61 # define OCTAVE_ATOMIC_DECREMENT(x) --(*(x))
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
62 # define OCTAVE_ATOMIC_POST_INCREMENT(x) (*(x))++
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
63 # define OCTAVE_ATOMIC_POST_DECREMENT(x) (*(x))--
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
64
13985
43cc49c7abd1 Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 12174
diff changeset
65 #endif
43cc49c7abd1 Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 12174
diff changeset
66
23012
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
67 namespace octave
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
68 {
23012
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
69
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
70 // Encapsulates a reference counter.
22381
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
71
23012
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
72 template <typename T>
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
73 class refcount
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
74 {
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
75 public:
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
76
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
77 typedef T count_type;
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
78
23012
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
79 refcount (count_type initial_count)
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
80 : count (initial_count)
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
81 { }
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
82
23012
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
83 // Increment/Decrement. int is postfix.
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
84 count_type operator++ (void)
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
85 {
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
86 return OCTAVE_ATOMIC_INCREMENT (&count);
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
87 }
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
88
23012
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
89 count_type operator++ (int)
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
90 {
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
91 return OCTAVE_ATOMIC_POST_INCREMENT (&count);
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
92 }
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
93
23012
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
94 count_type operator-- (void)
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
95 {
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
96 return OCTAVE_ATOMIC_DECREMENT (&count);
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
97 }
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
98
23012
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
99 count_type operator-- (int)
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
100 {
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
101 return OCTAVE_ATOMIC_POST_DECREMENT (&count);
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
102 }
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
103
23012
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
104 operator count_type (void) const
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
105 {
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
106 return static_cast<count_type const volatile&> (count);
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
107 }
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
108
23446
cd4e1ee28716 maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents: 23443
diff changeset
109 count_type * get (void)
23012
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
110 {
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
111 return &count;
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
112 }
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
113
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
114 private:
14951
4c9fd3e31436 Start of jit support for double matricies
Max Brister <max@2bass.com>
parents: 14138
diff changeset
115
23012
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
116 count_type count;
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
117 };
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
118 }
22381
6eba7555794a style fixes
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
119
23012
27e4ec3b0b49 move octave_refcount inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
120 template <typename T>
23615
be7b884ac589 use version number in OCTAVE_DEPRECATED macro
John W. Eaton <jwe@octave.org>
parents: 23446
diff changeset
121 using octave_refcount OCTAVE_DEPRECATED (4.4, "use 'octave::refcount' instead") = octave::refcount<T>;
12125
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
122
a21a3875ca83 implement a common class for reference counts
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
123 #endif