#include <intrin.h>
typedef long hb_atomic_int_t;
#define hb_atomic_int_add(AI, V) _InterlockedExchangeAdd (&(AI), (V))
-#define hb_atomic_int_set(AI, V) ((AI) = (V), MemoryBarrier ())
-#define hb_atomic_int_get(AI) (MemoryBarrier (), (AI))
#elif !defined(HB_NO_MT) && defined(__APPLE__)
#include <libkern/OSAtomic.h>
typedef int32_t hb_atomic_int_t;
#define hb_atomic_int_add(AI, V) (OSAtomicAdd32Barrier ((V), &(AI)) - (V))
-#define hb_atomic_int_set(AI, V) ((AI) = (V), OSMemoryBarrier ())
-#define hb_atomic_int_get(AI) (OSMemoryBarrier (), (AI))
#elif !defined(HB_NO_MT) && defined(HAVE_GLIB)
#else
#define hb_atomic_int_add(AI, V) g_atomic_int_exchange_and_add (&(AI), (V))
#endif
-#define hb_atomic_int_set(AI, V) g_atomic_int_set (&(AI), (V))
-#define hb_atomic_int_get(AI) g_atomic_int_get (&(AI))
#else
#define HB_ATOMIC_INT_NIL 1
typedef volatile int hb_atomic_int_t;
#define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V))
-#define hb_atomic_int_set(AI, V) ((void) ((AI) = (V)))
-#define hb_atomic_int_get(AI) (AI)
#endif
/* reference_count */
typedef struct {
- hb_atomic_int_t ref_count;
+ const hb_atomic_int_t ref_count;
#define HB_REFERENCE_COUNT_INVALID_VALUE ((hb_atomic_int_t) -1)
#define HB_REFERENCE_COUNT_INVALID {HB_REFERENCE_COUNT_INVALID_VALUE}
- inline void init (int v) { ref_count = v; /* non-atomic is fine */ }
- inline int inc (void) { return hb_atomic_int_add (ref_count, 1); }
- inline int dec (void) { return hb_atomic_int_add (ref_count, -1); }
+ inline void init (int v) { const_cast<hb_atomic_int_t &> (ref_count) = v; }
+ inline int inc (void) { return hb_atomic_int_add (const_cast<hb_atomic_int_t &> (ref_count), 1); }
+ inline int dec (void) { return hb_atomic_int_add (const_cast<hb_atomic_int_t &> (ref_count), -1); }
- inline int get (void) { return hb_atomic_int_get (ref_count); }
- inline int get_unsafe (void) const { return ref_count; }
inline bool is_invalid (void) const { return ref_count == HB_REFERENCE_COUNT_INVALID_VALUE; }
} hb_reference_count_t;
DEBUG_MSG (OBJECT, (void *) this,
"%s refcount=%d",
function,
- this ? ref_count.get_unsafe () : 0);
+ this ? ref_count.ref_count : 0);
}
};