/* reference_count */
-#define HB_REFERENCE_COUNT_INERT_VALUE -1
-#define HB_REFERENCE_COUNT_POISON_VALUE -0x0000DEAD
-#define HB_REFERENCE_COUNT_INIT {HB_ATOMIC_INT_INIT(HB_REFERENCE_COUNT_INERT_VALUE)}
-
+#define HB_REFERENCE_COUNT_INVALID_VALUE ((hb_atomic_int_t) -1)
+#define HB_REFERENCE_COUNT_INVALID {HB_REFERENCE_COUNT_INVALID_VALUE}
struct hb_reference_count_t
{
hb_atomic_int_t ref_count;
- inline void init (int v) { ref_count.set_unsafe (v); }
- inline int get_unsafe (void) const { return ref_count.get_unsafe (); }
- inline int inc (void) { return ref_count.inc (); }
- inline int dec (void) { return ref_count.dec (); }
- inline void finish (void) { ref_count.set_unsafe (HB_REFERENCE_COUNT_POISON_VALUE); }
+ inline void init (int v) { 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 void finish (void) { ref_count = HB_REFERENCE_COUNT_INVALID_VALUE; }
+
+ inline bool is_invalid (void) const { return ref_count == HB_REFERENCE_COUNT_INVALID_VALUE; }
- inline bool is_inert (void) const { return ref_count.get_unsafe () == HB_REFERENCE_COUNT_INERT_VALUE; }
- inline bool is_valid (void) const { return ref_count.get_unsafe () > 0; }
};
hb_reference_count_t ref_count;
hb_user_data_array_t user_data;
-#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INIT, HB_USER_DATA_ARRAY_INIT}
+#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INVALID, HB_USER_DATA_ARRAY_INIT}
private:
ASSERT_POD ();
DEBUG_MSG (OBJECT, (void *) obj,
"%s refcount=%d",
function,
- obj ? obj->header.ref_count.get_unsafe () : 0);
+ obj ? obj->header.ref_count.ref_count : 0);
}
template <typename Type>
template <typename Type>
static inline bool hb_object_is_inert (const Type *obj)
{
- return unlikely (obj->header.ref_count.is_inert ());
-}
-template <typename Type>
-static inline bool hb_object_is_valid (const Type *obj)
-{
- return likely (obj->header.ref_count.is_valid ());
+ return unlikely (obj->header.ref_count.is_invalid ());
}
template <typename Type>
static inline Type *hb_object_reference (Type *obj)
hb_object_trace (obj, HB_FUNC);
if (unlikely (!obj || hb_object_is_inert (obj)))
return obj;
- assert (hb_object_is_valid (obj));
obj->header.ref_count.inc ();
return obj;
}
hb_object_trace (obj, HB_FUNC);
if (unlikely (!obj || hb_object_is_inert (obj)))
return false;
- assert (hb_object_is_valid (obj));
if (obj->header.ref_count.dec () != 1)
return false;
{
if (unlikely (!obj || hb_object_is_inert (obj)))
return false;
- assert (hb_object_is_valid (obj));
return obj->header.user_data.set (key, data, destroy, replace);
}
{
if (unlikely (!obj || hb_object_is_inert (obj)))
return NULL;
- assert (hb_object_is_valid (obj));
return obj->header.user_data.get (key);
}