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.
This commit is contained in:
parent
4efdffec09
commit
0558d55bac
|
@ -47,8 +47,6 @@
|
||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
typedef long hb_atomic_int_t;
|
typedef long hb_atomic_int_t;
|
||||||
#define hb_atomic_int_add(AI, V) _InterlockedExchangeAdd (&(AI), (V))
|
#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__)
|
#elif !defined(HB_NO_MT) && defined(__APPLE__)
|
||||||
|
@ -56,8 +54,6 @@ typedef long hb_atomic_int_t;
|
||||||
#include <libkern/OSAtomic.h>
|
#include <libkern/OSAtomic.h>
|
||||||
typedef int32_t hb_atomic_int_t;
|
typedef int32_t hb_atomic_int_t;
|
||||||
#define hb_atomic_int_add(AI, V) (OSAtomicAdd32Barrier ((V), &(AI)) - (V))
|
#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)
|
#elif !defined(HB_NO_MT) && defined(HAVE_GLIB)
|
||||||
|
@ -69,8 +65,6 @@ typedef volatile int hb_atomic_int_t;
|
||||||
#else
|
#else
|
||||||
#define hb_atomic_int_add(AI, V) g_atomic_int_exchange_and_add (&(AI), (V))
|
#define hb_atomic_int_add(AI, V) g_atomic_int_exchange_and_add (&(AI), (V))
|
||||||
#endif
|
#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
|
#else
|
||||||
|
@ -78,8 +72,6 @@ typedef volatile int hb_atomic_int_t;
|
||||||
#define HB_ATOMIC_INT_NIL 1
|
#define HB_ATOMIC_INT_NIL 1
|
||||||
typedef volatile int hb_atomic_int_t;
|
typedef volatile int hb_atomic_int_t;
|
||||||
#define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V))
|
#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
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -48,17 +48,15 @@
|
||||||
/* reference_count */
|
/* reference_count */
|
||||||
|
|
||||||
typedef struct {
|
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_VALUE ((hb_atomic_int_t) -1)
|
||||||
#define HB_REFERENCE_COUNT_INVALID {HB_REFERENCE_COUNT_INVALID_VALUE}
|
#define HB_REFERENCE_COUNT_INVALID {HB_REFERENCE_COUNT_INVALID_VALUE}
|
||||||
|
|
||||||
inline void init (int v) { ref_count = v; /* non-atomic is fine */ }
|
inline void init (int v) { const_cast<hb_atomic_int_t &> (ref_count) = v; }
|
||||||
inline int inc (void) { return hb_atomic_int_add (ref_count, 1); }
|
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 (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; }
|
inline bool is_invalid (void) const { return ref_count == HB_REFERENCE_COUNT_INVALID_VALUE; }
|
||||||
|
|
||||||
} hb_reference_count_t;
|
} hb_reference_count_t;
|
||||||
|
@ -159,7 +157,7 @@ struct _hb_object_header_t {
|
||||||
DEBUG_MSG (OBJECT, (void *) this,
|
DEBUG_MSG (OBJECT, (void *) this,
|
||||||
"%s refcount=%d",
|
"%s refcount=%d",
|
||||||
function,
|
function,
|
||||||
this ? ref_count.get_unsafe () : 0);
|
this ? ref_count.ref_count : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue