From 140797d4a2841d4109ad667a38226bfd59de5829 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 29 Jun 2020 03:51:09 -0700 Subject: [PATCH] [constexpr] hb_atomic_int_t --- src/hb-atomic.hh | 13 ++++++++----- src/hb-face.cc | 4 ++-- src/hb-object.hh | 11 +++-------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/hb-atomic.hh b/src/hb-atomic.hh index 0abe50caa..6048efe86 100644 --- a/src/hb-atomic.hh +++ b/src/hb-atomic.hh @@ -221,9 +221,11 @@ inline void *hb_atomic_ptr_impl_get (void ** const P) { void *v = *P; _hb_memory #endif -#define HB_ATOMIC_INT_INIT(V) {V} 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 (int v_) { hb_atomic_int_impl_set (&v, 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 dec () { return hb_atomic_int_impl_add (&v, -1); } - int v; + int v = 0; }; - -#define HB_ATOMIC_PTR_INIT(V) {V} template struct hb_atomic_ptr_t { typedef hb_remove_pointer

T; + hb_atomic_ptr_t () = default; + constexpr hb_atomic_ptr_t (T* v) : v (v) {} + void init (T* v_ = nullptr) { set_relaxed (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); } @@ -250,7 +253,7 @@ struct hb_atomic_ptr_t T * operator -> () const { return get (); } template operator C * () const { return get (); } - T *v; + T *v = nullptr; }; diff --git a/src/hb-face.cc b/src/hb-face.cc index 900014fae..61bd4af7b 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -89,8 +89,8 @@ DEFINE_NULL_INSTANCE (hb_face_t) = nullptr, /* destroy */ 0, /* index */ - HB_ATOMIC_INT_INIT (1000), /* upem */ - HB_ATOMIC_INT_INIT (0), /* num_glyphs */ + 1000, /* upem */ + 0, /* num_glyphs */ /* Zero for the rest is fine. */ }; diff --git a/src/hb-object.hh b/src/hb-object.hh index fd96ea8ad..f3048b1c3 100644 --- a/src/hb-object.hh +++ b/src/hb-object.hh @@ -140,7 +140,7 @@ struct hb_lockable_set_t * Reference-count. */ -#define HB_REFERENCE_COUNT_INIT {HB_ATOMIC_INT_INIT (0)} +#define HB_REFERENCE_COUNT_INIT {0} struct hb_reference_count_t { @@ -195,15 +195,10 @@ struct hb_user_data_array_t struct hb_object_header_t { hb_reference_count_t ref_count; - mutable hb_atomic_int_t writable; + mutable hb_atomic_int_t writable = 0; hb_atomic_ptr_t user_data; }; -#define HB_OBJECT_HEADER_STATIC \ - { \ - HB_REFERENCE_COUNT_INIT, \ - HB_ATOMIC_INT_INIT (false), \ - HB_ATOMIC_PTR_INIT (nullptr) \ - } +#define HB_OBJECT_HEADER_STATIC {} /*