From ee351a38ec0c62b76dd1b3f20fe56cb4d63e62be Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 3 Nov 2018 14:28:55 -0400 Subject: [PATCH] [object] Add "writable" --- src/hb-object.hh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/hb-object.hh b/src/hb-object.hh index 106f59206..309aa2b41 100644 --- a/src/hb-object.hh +++ b/src/hb-object.hh @@ -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 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 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 @@ -241,6 +243,16 @@ static inline bool hb_object_is_valid (const Type *obj) return likely (obj->header.ref_count.is_valid ()); } template +static inline bool hb_object_is_immutable (const Type *obj) +{ + return !obj->header.writable.get_relaxed (); +} +template +static inline bool hb_object_make_immutable (const Type *obj) +{ + return !obj->header.writable.set_relaxed (false); +} +template static inline Type *hb_object_reference (Type *obj) { hb_object_trace (obj, HB_FUNC);