From: Behdad Esfahbod Date: Tue, 5 Jun 2012 21:27:20 +0000 (-0400) Subject: Add atomic-pointer functions X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6843ce01be0df501ef3149a2c1c54cdfb693195d;p=platform%2Fupstream%2FlibHarfBuzzSharp.git Add atomic-pointer functions Gonig to use these for lock-free linked-lists, to be used for hb_language_t among other things. --- diff --git a/src/hb-atomic-private.hh b/src/hb-atomic-private.hh index 3394afc..c1b25bd 100644 --- a/src/hb-atomic-private.hh +++ b/src/hb-atomic-private.hh @@ -45,22 +45,34 @@ #elif !defined(HB_NO_MT) && defined(_MSC_VER) && _MSC_VER >= 1600 #include +#pragma intrinsic(_InterlockedExchangeAdd, _InterlockedCompareExchangePointer) + typedef long hb_atomic_int_t; #define hb_atomic_int_add(AI, V) _InterlockedExchangeAdd (&(AI), (V)) +#define hb_atomic_ptr_get(P) (MemoryBarrier (), (void *) *(P)) +#define hb_atomic_ptr_cmpexch(P,O,N) (_InterlockedCompareExchangePointer ((void * volatile *) (P), (N), (O)) == (O)) + #elif !defined(HB_NO_MT) && defined(__APPLE__) #include + typedef int32_t hb_atomic_int_t; #define hb_atomic_int_add(AI, V) (OSAtomicAdd32Barrier ((V), &(AI)) - (V)) +#define hb_atomic_ptr_get(P) (OSMemoryBarrier (), (void *) *(P)) +#define hb_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwapPtrBarrier ((O), (N), (void * volatile *) (P)) + #elif !defined(HB_NO_MT) && defined(__GNUC__) typedef int hb_atomic_int_t; #define hb_atomic_int_add(AI, V) __sync_fetch_and_add (&(AI), (V)) +#define hb_atomic_ptr_get(P) (void *) (__sync_synchronize (), *(P)) +#define hb_atomic_ptr_cmpexch(P,O,N) __sync_bool_compare_and_swap ((P), (O), (N)) + #elif !defined(HB_NO_MT) && defined(HAVE_GLIB) #include @@ -71,6 +83,9 @@ typedef int hb_atomic_int_t; #define hb_atomic_int_add(AI, V) g_atomic_int_exchange_and_add (&(AI), (V)) #endif +#define hb_atomic_ptr_get(P) g_atomic_pointer_get (P) +#define hb_atomic_ptr_cmpexch(P,O,N) g_atomic_pointer_compare_and_exchange ((void * volatile *) (P), (O), (N)) + #elif !defined(HB_NO_MT) @@ -78,12 +93,18 @@ typedef int hb_atomic_int_t; typedef volatile int hb_atomic_int_t; #define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V)) +#define hb_atomic_ptr_get(P) ((void *) *(P)) +#define hb_atomic_ptr_cmpexch(P,O,N) (*(P) == (O) ? (*(P) = (N), TRUE) : FALSE) + #else /* HB_NO_MT */ typedef int hb_atomic_int_t; #define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V)) +#define hb_atomic_ptr_get(P) ((void *) *(P)) +#define hb_atomic_ptr_cmpexch(P,O,N) *(P) + #endif /* TODO Add tracing. */