Remove hb_atomic_int_set/get()
authorBehdad Esfahbod <behdad@behdad.org>
Mon, 28 May 2012 14:46:47 +0000 (10:46 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Mon, 28 May 2012 14:46:47 +0000 (10:46 -0400)
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
src/hb-object-private.hh

index 458c984..d6bd1c9 100644 (file)
@@ -47,8 +47,6 @@
 #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__)
@@ -56,8 +54,6 @@ typedef long hb_atomic_int_t;
 #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)
@@ -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
 
index edd8921..2be20d3 100644 (file)
 /* 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;
@@ -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);
   }
 
 };