[constexpr] hb_atomic_int_t

This commit is contained in:
Behdad Esfahbod 2020-06-29 03:51:09 -07:00
parent 2ec802b42a
commit 140797d4a2
3 changed files with 13 additions and 15 deletions

View File

@ -221,9 +221,11 @@ inline void *hb_atomic_ptr_impl_get (void ** const P) { void *v = *P; _hb_memory
#endif #endif
#define HB_ATOMIC_INT_INIT(V) {V}
struct hb_atomic_int_t struct hb_atomic_int_t
{ {
hb_atomic_int_t () = default;
constexpr hb_atomic_int_t (int v) : v (v) {}
void set_relaxed (int v_) { hb_atomic_int_impl_set_relaxed (&v, v_); } void set_relaxed (int v_) { hb_atomic_int_impl_set_relaxed (&v, v_); }
void set (int v_) { hb_atomic_int_impl_set (&v, v_); } void set (int v_) { hb_atomic_int_impl_set (&v, v_); }
int get_relaxed () const { return hb_atomic_int_impl_get_relaxed (&v); } int get_relaxed () const { return hb_atomic_int_impl_get_relaxed (&v); }
@ -231,16 +233,17 @@ struct hb_atomic_int_t
int inc () { return hb_atomic_int_impl_add (&v, 1); } int inc () { return hb_atomic_int_impl_add (&v, 1); }
int dec () { return hb_atomic_int_impl_add (&v, -1); } int dec () { return hb_atomic_int_impl_add (&v, -1); }
int v; int v = 0;
}; };
#define HB_ATOMIC_PTR_INIT(V) {V}
template <typename P> template <typename P>
struct hb_atomic_ptr_t struct hb_atomic_ptr_t
{ {
typedef hb_remove_pointer<P> T; typedef hb_remove_pointer<P> T;
hb_atomic_ptr_t () = default;
constexpr hb_atomic_ptr_t (T* v) : v (v) {}
void init (T* v_ = nullptr) { set_relaxed (v_); } void init (T* v_ = nullptr) { set_relaxed (v_); }
void set_relaxed (T* v_) { hb_atomic_ptr_impl_set_relaxed (&v, v_); } void set_relaxed (T* v_) { hb_atomic_ptr_impl_set_relaxed (&v, v_); }
T *get_relaxed () const { return (T *) hb_atomic_ptr_impl_get_relaxed (&v); } T *get_relaxed () const { return (T *) hb_atomic_ptr_impl_get_relaxed (&v); }
@ -250,7 +253,7 @@ struct hb_atomic_ptr_t
T * operator -> () const { return get (); } T * operator -> () const { return get (); }
template <typename C> operator C * () const { return get (); } template <typename C> operator C * () const { return get (); }
T *v; T *v = nullptr;
}; };

View File

@ -89,8 +89,8 @@ DEFINE_NULL_INSTANCE (hb_face_t) =
nullptr, /* destroy */ nullptr, /* destroy */
0, /* index */ 0, /* index */
HB_ATOMIC_INT_INIT (1000), /* upem */ 1000, /* upem */
HB_ATOMIC_INT_INIT (0), /* num_glyphs */ 0, /* num_glyphs */
/* Zero for the rest is fine. */ /* Zero for the rest is fine. */
}; };

View File

@ -140,7 +140,7 @@ struct hb_lockable_set_t
* Reference-count. * Reference-count.
*/ */
#define HB_REFERENCE_COUNT_INIT {HB_ATOMIC_INT_INIT (0)} #define HB_REFERENCE_COUNT_INIT {0}
struct hb_reference_count_t struct hb_reference_count_t
{ {
@ -195,15 +195,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;
mutable hb_atomic_int_t writable; mutable hb_atomic_int_t writable = 0;
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 \ #define HB_OBJECT_HEADER_STATIC {}
{ \
HB_REFERENCE_COUNT_INIT, \
HB_ATOMIC_INT_INIT (false), \
HB_ATOMIC_PTR_INIT (nullptr) \
}
/* /*