| OLD | NEW |
| (Empty) |
| 1 diff --git a/source/common/putilimp.h b/source/common/putilimp.h | |
| 2 index e3da340..90bae92 100644 | |
| 3 --- a/source/common/putilimp.h | |
| 4 +++ b/source/common/putilimp.h | |
| 5 @@ -1,7 +1,7 @@ | |
| 6 /* | |
| 7 ****************************************************************************** | |
| 8 * | |
| 9 -* Copyright (C) 1997-2014, International Business Machines | |
| 10 +* Copyright (C) 1997-2015, International Business Machines | |
| 11 * Corporation and others. All Rights Reserved. | |
| 12 * | |
| 13 ****************************************************************************** | |
| 14 @@ -229,6 +229,26 @@ typedef size_t uintptr_t; | |
| 15 #endif | |
| 16 | |
| 17 | |
| 18 +/** | |
| 19 + * \def U_HAVE_CLANG_ATOMICS | |
| 20 + * Defines whether Clang c11 style built-in atomics are avaialable. | |
| 21 + * These are used in preference to gcc atomics when both are available. | |
| 22 + */ | |
| 23 +#ifdef U_HAVE_CLANG_ATOMICS | |
| 24 + /* Use the predefined value. */ | |
| 25 +#elif !defined(__clang__) | |
| 26 +# define U_HAVE_CLANG_ATOMICS 0 | |
| 27 +#else | |
| 28 +#if __has_builtin(__c11_atomic_load) && \ | |
| 29 + __has_builtin(__c11_atomic_store) && \ | |
| 30 + __has_builtin(__c11_atomic_fetch_add) && \ | |
| 31 + __has_builtin(__c11_atomic_fetch_sub) | |
| 32 +# define U_HAVE_CLANG_ATOMICS 1 | |
| 33 +#else | |
| 34 +# define U_HAVE_CLANG_ATOMICS 0 | |
| 35 +#endif | |
| 36 +#endif | |
| 37 + | |
| 38 /*===========================================================================*/ | |
| 39 /** @{ Code alignment */ | |
| 40 /*===========================================================================*/ | |
| 41 diff --git a/source/common/umutex.cpp b/source/common/umutex.cpp | |
| 42 index 0c1fdc8..581f2b9 100644 | |
| 43 --- a/source/common/umutex.cpp | |
| 44 +++ b/source/common/umutex.cpp | |
| 45 @@ -349,8 +349,8 @@ umtx_atomic_dec(u_atomic_int32_t *p) { | |
| 46 | |
| 47 U_COMMON_API int32_t U_EXPORT2 | |
| 48 umtx_loadAcquire(u_atomic_int32_t &var) { | |
| 49 - int32_t val = var; | |
| 50 umtx_lock(&gIncDecMutex); | |
| 51 + int32_t val = var; | |
| 52 umtx_unlock(&gIncDecMutex); | |
| 53 return val; | |
| 54 } | |
| 55 @@ -358,8 +358,8 @@ umtx_loadAcquire(u_atomic_int32_t &var) { | |
| 56 U_COMMON_API void U_EXPORT2 | |
| 57 umtx_storeRelease(u_atomic_int32_t &var, int32_t val) { | |
| 58 umtx_lock(&gIncDecMutex); | |
| 59 - umtx_unlock(&gIncDecMutex); | |
| 60 var = val; | |
| 61 + umtx_unlock(&gIncDecMutex); | |
| 62 } | |
| 63 | |
| 64 U_NAMESPACE_END | |
| 65 diff --git a/source/common/umutex.h b/source/common/umutex.h | |
| 66 index e0ad0d3..0e4d118 100644 | |
| 67 --- a/source/common/umutex.h | |
| 68 +++ b/source/common/umutex.h | |
| 69 @@ -1,6 +1,6 @@ | |
| 70 /* | |
| 71 ********************************************************************** | |
| 72 -* Copyright (C) 1997-2014, International Business Machines | |
| 73 +* Copyright (C) 1997-2015, International Business Machines | |
| 74 * Corporation and others. All Rights Reserved. | |
| 75 ********************************************************************** | |
| 76 * | |
| 77 @@ -118,6 +118,33 @@ inline int32_t umtx_atomic_dec(u_atomic_int32_t *var) { | |
| 78 U_NAMESPACE_END | |
| 79 | |
| 80 | |
| 81 +#elif U_HAVE_CLANG_ATOMICS | |
| 82 +/* | |
| 83 + * Clang __c11 atomic built-ins | |
| 84 + */ | |
| 85 + | |
| 86 +U_NAMESPACE_BEGIN | |
| 87 +typedef _Atomic(int32_t) u_atomic_int32_t; | |
| 88 +#define ATOMIC_INT32_T_INITIALIZER(val) val | |
| 89 + | |
| 90 +inline int32_t umtx_loadAcquire(u_atomic_int32_t &var) { | |
| 91 + return __c11_atomic_load(&var, __ATOMIC_ACQUIRE); | |
| 92 +} | |
| 93 + | |
| 94 +inline void umtx_storeRelease(u_atomic_int32_t &var, int32_t val) { | |
| 95 + return __c11_atomic_store(&var, val, __ATOMIC_RELEASE); | |
| 96 +} | |
| 97 + | |
| 98 +inline int32_t umtx_atomic_inc(u_atomic_int32_t *var) { | |
| 99 + return __c11_atomic_fetch_add(var, 1, __ATOMIC_SEQ_CST) + 1; | |
| 100 +} | |
| 101 + | |
| 102 +inline int32_t umtx_atomic_dec(u_atomic_int32_t *var) { | |
| 103 + return __c11_atomic_fetch_sub(var, 1, __ATOMIC_SEQ_CST) - 1; | |
| 104 +} | |
| 105 +U_NAMESPACE_END | |
| 106 + | |
| 107 + | |
| 108 #elif U_HAVE_GCC_ATOMICS | |
| 109 /* | |
| 110 * gcc atomic ops. These are available on several other compilers as well. | |
| OLD | NEW |