[object] Add "writable"

This commit is contained in:
Behdad Esfahbod 2018-11-03 14:28:55 -04:00
parent b8a78ce201
commit ee351a38ec
1 changed files with 13 additions and 1 deletions

View File

@ -194,9 +194,10 @@ struct hb_user_data_array_t
struct hb_object_header_t
{
hb_reference_count_t ref_count;
hb_atomic_int_t writable;
hb_atomic_ptr_t<hb_user_data_array_t> user_data;
};
#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INIT, HB_ATOMIC_PTR_INIT (nullptr)}
#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INIT, HB_ATOMIC_INT_INIT (0), HB_ATOMIC_PTR_INIT (nullptr)}
/*
@ -228,6 +229,7 @@ template <typename Type>
static inline void hb_object_init (Type *obj)
{
obj->header.ref_count.init ();
obj->header.writable.set_relaxed (true);
obj->header.user_data.init ();
}
template <typename Type>
@ -241,6 +243,16 @@ static inline bool hb_object_is_valid (const Type *obj)
return likely (obj->header.ref_count.is_valid ());
}
template <typename Type>
static inline bool hb_object_is_immutable (const Type *obj)
{
return !obj->header.writable.get_relaxed ();
}
template <typename Type>
static inline bool hb_object_make_immutable (const Type *obj)
{
return !obj->header.writable.set_relaxed (false);
}
template <typename Type>
static inline Type *hb_object_reference (Type *obj)
{
hb_object_trace (obj, HB_FUNC);