From 0558d55bac7fb9279aac859b465e7c0e3ad97492 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 28 May 2012 10:46:47 -0400 Subject: [PATCH] Remove hb_atomic_int_set/get() We never use them in fact... I'm just adjusting these as I better understand the requirements of the code and the guarantees of each operation. --- src/hb-atomic-private.hh | 8 -------- src/hb-object-private.hh | 12 +++++------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/hb-atomic-private.hh b/src/hb-atomic-private.hh index 458c98496..d6bd1c93d 100644 --- a/src/hb-atomic-private.hh +++ b/src/hb-atomic-private.hh @@ -47,8 +47,6 @@ #include 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__) @@ -56,8 +54,6 @@ typedef long hb_atomic_int_t; #include 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) @@ -69,8 +65,6 @@ typedef volatile int hb_atomic_int_t; #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 @@ -78,8 +72,6 @@ typedef volatile int hb_atomic_int_t; #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 diff --git a/src/hb-object-private.hh b/src/hb-object-private.hh index edd89217e..2be20d346 100644 --- a/src/hb-object-private.hh +++ b/src/hb-object-private.hh @@ -48,17 +48,15 @@ /* 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 (ref_count) = v; } + inline int inc (void) { return hb_atomic_int_add (const_cast (ref_count), 1); } + inline int dec (void) { return hb_atomic_int_add (const_cast (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; @@ -159,7 +157,7 @@ struct _hb_object_header_t { DEBUG_MSG (OBJECT, (void *) this, "%s refcount=%d", function, - this ? ref_count.get_unsafe () : 0); + this ? ref_count.ref_count : 0); } };