Implement C++11 <atomic> operations
Fixes https://github.com/harfbuzz/harfbuzz/issues/345
This commit is contained in:
parent
5244112240
commit
bda242409f
|
@ -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 <atomic>
|
||||
|
||||
typedef int hb_atomic_int_impl_t;
|
||||
#define hb_atomic_int_impl_add(AI, V) (reinterpret_cast<std::atomic<int> *> (&AI)->fetch_add (V))
|
||||
|
||||
#define hb_atomic_ptr_impl_get(P) (reinterpret_cast<std::atomic<void*> *> (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<std::atomic<const void*> *> (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 <windows.h>
|
||||
|
@ -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<hb_atomic_int_impl_t &> (v), 1); }
|
||||
inline int dec (void) { return hb_atomic_int_impl_add (const_cast<hb_atomic_int_impl_t &> (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); }
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue