diff --git a/src/hb-atomic-private.hh b/src/hb-atomic-private.hh index 12caacaaba7712a4e1fc9d058c236fbfdbb4d03e..f234fe041bc502b868e66043c9a7335cde661614 100644 --- a/src/hb-atomic-private.hh +++ b/src/hb-atomic-private.hh @@ -46,6 +46,25 @@ /* Defined externally, i.e. in config.h; must have typedef'ed hb_atomic_int_impl_t as well. */ +#elif !defined(HB_NO_MT) && __cplusplus >= 201103L + +/* Prefer C++11 atomics. */ + +#include + +typedef int hb_atomic_int_impl_t; +#define hb_atomic_int_impl_add(AI, V) (reinterpret_cast *> (&AI)->fetch_add (V)) + +#define hb_atomic_ptr_impl_get(P) (reinterpret_cast *> (P)->load ()) +static inline bool +_hb_atomic_ptr_impl_cmplexch (const void **P, const void *O_, const void *N) +{ + const void *O = O_; // Need lvalue + return reinterpret_cast *> (P)->compare_exchange_weak ((O), (N)); +} +#define hb_atomic_ptr_impl_cmpexch(P,O,N) (_hb_atomic_ptr_impl_cmplexch ((const void **) (P), (O), (N))) + + #elif !defined(HB_NO_MT) && (defined(_WIN32) || defined(__CYGWIN__)) #include @@ -162,16 +181,18 @@ typedef int hb_atomic_int_impl_t; #endif +#ifndef HB_ATOMIC_INT_INIT #define HB_ATOMIC_INT_INIT(V) {V} +#endif struct hb_atomic_int_t { - hb_atomic_int_impl_t v; + mutable hb_atomic_int_impl_t v; inline void set_unsafe (int v_) { v = v_; } inline int get_unsafe (void) const { return v; } - inline int inc (void) { return hb_atomic_int_impl_add (const_cast (v), 1); } - inline int dec (void) { return hb_atomic_int_impl_add (const_cast (v), -1); } + inline int inc (void) { return hb_atomic_int_impl_add (v, 1); } + inline int dec (void) { return hb_atomic_int_impl_add (v, -1); } }; diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 207f6e0e20471ea6f595720e275b3dc9e09b5b7e..f6113c33aaf922cec030fff264e2e977e4667f48 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -1247,7 +1247,7 @@ struct hb_lazy_loader_t private: hb_face_t *face; - T *instance; + mutable T *instance; }; /* Logic is shared between hb_lazy_loader_t and hb_table_lazy_loader_t */ diff --git a/src/hb-ot-shape-complex-arabic.cc b/src/hb-ot-shape-complex-arabic.cc index b1cba1c711d66ae1d30347a9abc68aa06198fd68..0c4948dfdf48f674c1f5022e939c800e0fde6b44 100644 --- a/src/hb-ot-shape-complex-arabic.cc +++ b/src/hb-ot-shape-complex-arabic.cc @@ -250,7 +250,7 @@ struct arabic_shape_plan_t * mask_array[NONE] == 0. */ hb_mask_t mask_array[ARABIC_NUM_FEATURES + 1]; - arabic_fallback_plan_t *fallback_plan; + mutable arabic_fallback_plan_t *fallback_plan; unsigned int do_fallback : 1; unsigned int has_stch : 1;