From: Behdad Esfahbod Date: Tue, 3 May 2011 04:49:06 +0000 (-0400) Subject: Move Win32 thread-safety stuff to hb-object-private.h X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2000179487b49e0d504ec127450dc6fcb5568cec;p=platform%2Fupstream%2FlibHarfBuzzSharp.git Move Win32 thread-safety stuff to hb-object-private.h The Win32 definitions for LONG, ULONG, etc conflicts with hb-open-type.h. Avoid that by making sure hb-object-private.h and hb-open-type.h are not included in the same compilation unit. --- diff --git a/src/hb-common.cc b/src/hb-common.cc index 2f5e89b..b75146d 100644 --- a/src/hb-common.cc +++ b/src/hb-common.cc @@ -263,58 +263,4 @@ hb_script_get_horizontal_direction (hb_script_t script) } - -/* System stuff */ - - -#ifdef _MSC_VER - -#include - -hb_mutex_t -_hb_win32_mutex_create () -{ - hb_mutex_t m; - _hb_win32_mutex_init (&m); - return m; -} - -void -_hb_win32_mutex_init (hb_mutex_t *m) -{ - LPCRITICAL_SECTION lpcs = (LPCRITICAL_SECTION) calloc(1, sizeof(CRITICAL_SECTION)); - InitializeCriticalSection (lpcs); - *m = (void*) lpcs; -} - -void -_hb_win32_mutex_lock (hb_mutex_t m) -{ - EnterCriticalSection ((LPCRITICAL_SECTION) m); -} - -int -_hb_win32_mutex_trylock (hb_mutex_t m) -{ - return TryEnterCriticalSection ((LPCRITICAL_SECTION) m); -} - -void -_hb_win32_mutex_unlock (hb_mutex_t m) -{ - LeaveCriticalSection ((LPCRITICAL_SECTION) m); -} - -void -_hb_win32_mutex_free (hb_mutex_t *m) -{ - LPCRITICAL_SECTION lpcs = (LPCRITICAL_SECTION) *m; - DeleteCriticalSection (lpcs); - free(lpcs); - *m = 0; -} - -#endif - - HB_END_DECLS diff --git a/src/hb-object-private.hh b/src/hb-object-private.hh index 47cef7e..d77b6a5 100644 --- a/src/hb-object-private.hh +++ b/src/hb-object-private.hh @@ -44,6 +44,72 @@ HB_BEGIN_DECLS #endif +/* atomic_int and mutex */ + +/* We need external help for these */ + +#ifdef HAVE_GLIB + +#include + +typedef volatile int hb_atomic_int_t; +#define hb_atomic_int_fetch_and_add(AI, V) g_atomic_int_exchange_and_add (&(AI), V) +#define hb_atomic_int_get(AI) g_atomic_int_get (&(AI)) +#define hb_atomic_int_set(AI, V) g_atomic_int_set (&(AI), V) + +typedef GStaticMutex hb_mutex_t; +#define HB_MUTEX_INIT G_STATIC_MUTEX_INIT +#define hb_mutex_init(M) g_static_mutex_init (&(M)) +#define hb_mutex_lock(M) g_static_mutex_lock (&(M)) +#define hb_mutex_trylock(M) g_static_mutex_trylock (&(M)) +#define hb_mutex_unlock(M) g_static_mutex_unlock (&(M)) +#define hb_mutex_free(M) g_static_mutex_free (&(M)) + +#else + +#ifdef _MSC_VER + +#include + +typedef long hb_atomic_int_t; +#define hb_atomic_int_fetch_and_add(AI, V) _InterlockedExchangeAdd (&(AI), V) +#define hb_atomic_int_get(AI) (_ReadBarrier (), (AI)) +#define hb_atomic_int_set(AI, V) ((void) _InterlockedExchange (&(AI), (V))) + +#include + +typedef CRITICAL_SECTION hb_mutex_t; +#define HB_MUTEX_INIT { NULL, 0, 0, NULL, NULL, 0 } +#define hb_mutex_init(M) InitializeCriticalSection (&(M)) +#define hb_mutex_lock(M) EnterCriticalSection (&(M)) +#define hb_mutex_trylock(M) TryEnterCriticalSection (&(M)) +#define hb_mutex_unlock(M) LeaveCriticalSection (&(M)) +#define hb_mutex_free(M) DeleteCriticalSection (&(M)) + +#else + +#warning "Could not find any system to define platform macros, library will NOT be thread-safe" + +typedef volatile int hb_atomic_int_t; +#define hb_atomic_int_fetch_and_add(AI, V) ((AI) += (V), (AI) - (V)) +#define hb_atomic_int_get(AI) (AI) +#define hb_atomic_int_set(AI, V) ((void) ((AI) = (V))) + +typedef volatile int hb_mutex_t; +#define HB_MUTEX_INIT 0 +#define hb_mutex_init(M) ((void) ((M) = 0)) +#define hb_mutex_lock(M) ((void) ((M) = 1)) +#define hb_mutex_trylock(M) ((M) = 1, 1) +#define hb_mutex_unlock(M) ((void) ((M) = 0)) +#define hb_mutex_free(M) ((void) ((M) = 2)) + +#endif + +#endif + + + + /* reference_count */ typedef struct { diff --git a/src/hb-private.hh b/src/hb-private.hh index cac434a..1d40d66 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -221,72 +221,6 @@ _hb_unsigned_int_mul_overflows (unsigned int count, unsigned int size) typedef int (*hb_compare_func_t) (const void *, const void *); -/* We need external help for these */ - -#ifdef HAVE_GLIB - -#include - -typedef volatile int hb_atomic_int_t; -#define hb_atomic_int_fetch_and_add(AI, V) g_atomic_int_exchange_and_add (&(AI), V) -#define hb_atomic_int_get(AI) g_atomic_int_get (&(AI)) -#define hb_atomic_int_set(AI, V) g_atomic_int_set (&(AI), V) - -typedef GStaticMutex hb_mutex_t; -#define HB_MUTEX_INIT G_STATIC_MUTEX_INIT -#define hb_mutex_init(M) g_static_mutex_init (&(M)) -#define hb_mutex_lock(M) g_static_mutex_lock (&(M)) -#define hb_mutex_trylock(M) g_static_mutex_trylock (&(M)) -#define hb_mutex_unlock(M) g_static_mutex_unlock (&(M)) -#define hb_mutex_free(M) g_static_mutex_free (&(M)) - -#else - -#ifdef _MSC_VER - -#include - -typedef long hb_atomic_int_t; -#define hb_atomic_int_fetch_and_add(AI, V) _InterlockedExchangeAdd (&(AI), V) -#define hb_atomic_int_get(AI) (_ReadBarrier (), (AI)) -#define hb_atomic_int_set(AI, V) ((void) _InterlockedExchange (&(AI), (V))) - -typedef void * hb_mutex_t; -extern HB_INTERNAL hb_mutex_t _hb_win32_mutex_create (void); -extern HB_INTERNAL void _hb_win32_mutex_init (hb_mutex_t *m); -extern HB_INTERNAL void _hb_win32_mutex_lock (hb_mutex_t m); -extern HB_INTERNAL int _hb_win32_mutex_trylock (hb_mutex_t m); -extern HB_INTERNAL void _hb_win32_mutex_unlock (hb_mutex_t m); -extern HB_INTERNAL void _hb_win32_mutex_free (hb_mutex_t *m); -#define HB_MUTEX_INIT _hb_win32_mutex_create () -#define hb_mutex_init(M) _hb_win32_mutex_init (&(M)) -#define hb_mutex_lock(M) _hb_win32_mutex_lock ((M)) -#define hb_mutex_trylock(M) _hb_win32_mutex_trylock ((M)) -#define hb_mutex_unlock(M) _hb_win32_mutex_unlock ((M)) -#define hb_mutex_free(M) _hb_win32_mutex_free (&(M)) - -#else - -#warning "Could not find any system to define platform macros, library will NOT be thread-safe" - -typedef volatile int hb_atomic_int_t; -#define hb_atomic_int_fetch_and_add(AI, V) ((AI) += (V), (AI) - (V)) -#define hb_atomic_int_get(AI) (AI) -#define hb_atomic_int_set(AI, V) ((void) ((AI) = (V))) - -typedef volatile int hb_mutex_t; -#define HB_MUTEX_INIT 0 -#define hb_mutex_init(M) ((void) ((M) = 0)) -#define hb_mutex_lock(M) ((void) ((M) = 1)) -#define hb_mutex_trylock(M) ((M) = 1, 1) -#define hb_mutex_unlock(M) ((void) ((M) = 0)) -#define hb_mutex_free(M) ((void) ((M) = 2)) - -#endif - -#endif - - HB_END_DECLS