23 #if !defined (octave_oct_refcount_h)
24 #define octave_oct_refcount_h 1
26 #ifndef OCTAVE_CONFIG_INCLUDED
27 # error "The file <octave/config.h> must be included before oct-refcount.h."
30 #if defined (USE_ATOMIC_REFCOUNT) && (defined (_MSC_VER) || defined (__GNUC__))
31 # if defined (_MSC_VER)
33 # define OCTREFCOUNT_ATOMIC_INCREMENT(x) _InterlockedIncrement((long*)x)
34 # define OCTREFCOUNT_ATOMIC_DECREMENT(x) _InterlockedDecrement((long*)x)
35 # define OCTREFCOUNT_ATOMIC_INCREMENT_POST(x) _InterlockedExchangeAdd((long*)x, 1)
36 # define OCTREFCOUNT_ATOMIC_DECREMENT_POST(x) _InterlockedExchangeAdd((long*)x, -1)
37 # elif defined (__GNUC__)
38 # define OCTREFCOUNT_ATOMIC_INCREMENT(x) __sync_add_and_fetch(x, 1)
39 # define OCTREFCOUNT_ATOMIC_DECREMENT(x) __sync_add_and_fetch(x, -1)
40 # define OCTREFCOUNT_ATOMIC_INCREMENT_POST(x) __sync_fetch_and_add(x, 1)
41 # define OCTREFCOUNT_ATOMIC_DECREMENT_POST(x) __sync_fetch_and_add(x, -1)
43 #else // Generic non-locking versions
44 # define OCTREFCOUNT_ATOMIC_INCREMENT(x) ++(*(x))
45 # define OCTREFCOUNT_ATOMIC_DECREMENT(x) --(*(x))
46 # define OCTREFCOUNT_ATOMIC_INCREMENT_POST(x) (*(x))++
47 # define OCTREFCOUNT_ATOMIC_DECREMENT_POST(x) (*(x))--
82 return static_cast<count_type
const volatile&
> (
count);
85 count_type *
get (void)
count_type operator++(int)
#define OCTREFCOUNT_ATOMIC_DECREMENT(x)
#define OCTREFCOUNT_ATOMIC_INCREMENT_POST(x)
#define OCTREFCOUNT_ATOMIC_DECREMENT_POST(x)
#define OCTREFCOUNT_ATOMIC_INCREMENT(x)
octave_refcount(count_type initial_count)
count_type operator++(void)
count_type operator--(int)
count_type operator--(void)