diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-11-21 16:57:18 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-11-21 16:57:18 +0900 |
commit | 4dfe393027cfcfe844a8c8b97209a714904308c4 (patch) | |
tree | d94a05252de9becb345ed10d7c3cfed598005923 /util | |
parent | 485249b5a02cf59571cde61f83d10a6a9ec36b3d (diff) | |
download | re2-4dfe393027cfcfe844a8c8b97209a714904308c4.tar.gz re2-4dfe393027cfcfe844a8c8b97209a714904308c4.tar.bz2 re2-4dfe393027cfcfe844a8c8b97209a714904308c4.zip |
Imported Upstream version 20160301upstream/20160301
Change-Id: I33831129b7d3a860e34c551b415ede10da350c73
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'util')
-rw-r--r-- | util/atomicops.h | 179 | ||||
-rw-r--r-- | util/util.h | 5 |
2 files changed, 5 insertions, 179 deletions
diff --git a/util/atomicops.h b/util/atomicops.h deleted file mode 100644 index dc944e7..0000000 --- a/util/atomicops.h +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright 2006-2008 The RE2 Authors. All Rights Reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -#ifndef RE2_UTIL_ATOMICOPS_H__ -#define RE2_UTIL_ATOMICOPS_H__ - -// The memory ordering constraints resemble the ones in C11. -// RELAXED - no memory ordering, just an atomic operation. -// CONSUME - data-dependent ordering. -// ACQUIRE - prevents memory accesses from hoisting above the operation. -// RELEASE - prevents memory accesses from sinking below the operation. - -#ifndef __has_builtin -#define __has_builtin(x) 0 -#endif - -#if !defined(OS_NACL) && (__has_builtin(__atomic_load_n) || (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__ >= 40801)) - -#define ATOMIC_LOAD_RELAXED(x, p) do { (x) = __atomic_load_n((p), __ATOMIC_RELAXED); } while (0) -#define ATOMIC_LOAD_CONSUME(x, p) do { (x) = __atomic_load_n((p), __ATOMIC_CONSUME); } while (0) -#define ATOMIC_LOAD_ACQUIRE(x, p) do { (x) = __atomic_load_n((p), __ATOMIC_ACQUIRE); } while (0) -#define ATOMIC_STORE_RELAXED(p, v) __atomic_store_n((p), (v), __ATOMIC_RELAXED) -#define ATOMIC_STORE_RELEASE(p, v) __atomic_store_n((p), (v), __ATOMIC_RELEASE) - -#else // old compiler - -#define ATOMIC_LOAD_RELAXED(x, p) do { (x) = *(p); } while (0) -#define ATOMIC_LOAD_CONSUME(x, p) do { (x) = *(p); MaybeReadMemoryBarrier(); } while (0) -#define ATOMIC_LOAD_ACQUIRE(x, p) do { (x) = *(p); ReadMemoryBarrier(); } while (0) -#define ATOMIC_STORE_RELAXED(p, v) do { *(p) = (v); } while (0) -#define ATOMIC_STORE_RELEASE(p, v) do { WriteMemoryBarrier(); *(p) = (v); } while (0) - -// WriteMemoryBarrier(), ReadMemoryBarrier() and MaybeReadMemoryBarrier() -// are an implementation detail and must not be used in the rest of the code. - -#if defined(__i386__) - -static inline void WriteMemoryBarrier() { - int x; - __asm__ __volatile__("xchgl (%0),%0" // The lock prefix is implicit for xchg. - :: "r" (&x)); -} - -#elif defined(__x86_64__) - -// 64-bit implementations of memory barrier can be simpler, because -// "sfence" is guaranteed to exist. -static inline void WriteMemoryBarrier() { - __asm__ __volatile__("sfence" : : : "memory"); -} - -#elif defined(__ppc__) || defined(__powerpc64__) - -static inline void WriteMemoryBarrier() { - __asm__ __volatile__("lwsync" : : : "memory"); -} - -#elif defined(__aarch64__) - -static inline void WriteMemoryBarrier() { - __asm__ __volatile__("dmb st" : : : "memory"); -} - -#elif defined(__alpha__) - -static inline void WriteMemoryBarrier() { - __asm__ __volatile__("wmb" : : : "memory"); -} - -#elif defined(__arm__) && defined(__linux__) - -// Linux on ARM puts a suitable memory barrier at a magic address for us to call. -static inline void WriteMemoryBarrier() { - ((void(*)(void))0xffff0fa0)(); -} - -#elif defined(__windows__) || defined(_WIN32) - -#include <intrin.h> -#include <windows.h> - -static inline void WriteMemoryBarrier() { -#if defined(_M_IX86) || defined(_M_X64) - // x86 and x64 CPUs have a strong memory model that prohibits most types of - // reordering, so a non-instruction intrinsic to suppress compiler reordering - // is sufficient. _WriteBarrier is deprecated, but is still appropriate for - // the "old compiler" path (pre C++11). - _WriteBarrier(); -#else - LONG x; - ::InterlockedExchange(&x, 0); -#endif -} - -#elif defined(OS_NACL) - -static inline void WriteMemoryBarrier() { - __sync_synchronize(); -} - -#elif defined(__mips__) - -static inline void WriteMemoryBarrier() { - __asm__ __volatile__("sync" : : : "memory"); -} - -#else - -#include "util/mutex.h" - -static inline void WriteMemoryBarrier() { - // Slight overkill, but good enough: - // any mutex implementation must have - // a read barrier after the lock operation and - // a write barrier before the unlock operation. - // - // It may be worthwhile to write architecture-specific - // barriers for the common platforms, as above, but - // this is a correct fallback. - re2::Mutex mu; - re2::MutexLock l(&mu); -} - -#endif - -// Alpha has very weak memory ordering. If relying on WriteBarriers, one must -// use read barriers for the readers too. -#if defined(__alpha__) - -static inline void MaybeReadMemoryBarrier() { - __asm__ __volatile__("mb" : : : "memory"); -} - -#else - -static inline void MaybeReadMemoryBarrier() {} - -#endif // __alpha__ - -// Read barrier for various targets. - -#if defined(__ppc__) || defined(__powerpc64__) - -static inline void ReadMemoryBarrier() { - __asm__ __volatile__("lwsync" : : : "memory"); -} - -#elif defined(__aarch64__) - -static inline void ReadMemoryBarrier() { - __asm__ __volatile__("dmb ld" : : : "memory"); -} - -#elif defined(__alpha__) - -static inline void ReadMemoryBarrier() { - __asm__ __volatile__("mb" : : : "memory"); -} - -#elif defined(__mips__) - -static inline void ReadMemoryBarrier() { - __asm__ __volatile__("sync" : : : "memory"); -} - -#else - -static inline void ReadMemoryBarrier() {} - -#endif - -#endif // old compiler - -#ifndef NO_THREAD_SAFETY_ANALYSIS -#define NO_THREAD_SAFETY_ANALYSIS -#endif - -#endif // RE2_UTIL_ATOMICOPS_H__ diff --git a/util/util.h b/util/util.h index c59d91f..8c5d922 100644 --- a/util/util.h +++ b/util/util.h @@ -30,6 +30,7 @@ #include <ostream> #include <utility> #include <set> +#include <atomic> // Use std names. using std::set; @@ -113,6 +114,10 @@ template<bool> struct CompileAssert {}; #define arraysize(array) (int)(sizeof(array)/sizeof((array)[0])) +#ifndef NO_THREAD_SAFETY_ANALYSIS +#define NO_THREAD_SAFETY_ANALYSIS +#endif + class StringPiece; string CEscape(const StringPiece& src); |