提交 ee351a38 编写于 作者: B Behdad Esfahbod

[object] Add "writable"

上级 b8a78ce2
...@@ -194,9 +194,10 @@ struct hb_user_data_array_t ...@@ -194,9 +194,10 @@ struct hb_user_data_array_t
struct hb_object_header_t struct hb_object_header_t
{ {
hb_reference_count_t ref_count; hb_reference_count_t ref_count;
hb_atomic_int_t writable;
hb_atomic_ptr_t<hb_user_data_array_t> user_data; 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> ...@@ -228,6 +229,7 @@ template <typename Type>
static inline void hb_object_init (Type *obj) static inline void hb_object_init (Type *obj)
{ {
obj->header.ref_count.init (); obj->header.ref_count.init ();
obj->header.writable.set_relaxed (true);
obj->header.user_data.init (); obj->header.user_data.init ();
} }
template <typename Type> template <typename Type>
...@@ -241,6 +243,16 @@ static inline bool hb_object_is_valid (const Type *obj) ...@@ -241,6 +243,16 @@ static inline bool hb_object_is_valid (const Type *obj)
return likely (obj->header.ref_count.is_valid ()); return likely (obj->header.ref_count.is_valid ());
} }
template <typename Type> 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) static inline Type *hb_object_reference (Type *obj)
{ {
hb_object_trace (obj, HB_FUNC); hb_object_trace (obj, HB_FUNC);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册