diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-05-29 18:24:54 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-05-29 18:24:54 +0000 |
commit | 448e2a3b3935d91e7bf84dc5b0367b92d2e2a518 (patch) | |
tree | e7c16afcc032d9f49d9b352ad33a31ec9dcaafdc /include | |
parent | ecc86492042ec70b4d606731d6e1e22781be7197 (diff) |
Add SkBarriers to ports.
This completes a TODO we've had to move our memory-barrier code out of
SkOnce. I also want to start using sk_acquire_load elsewhere.
BUG=skia:
R=bungeman@google.com, mtklein@google.com, reed@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/304593003
git-svn-id: http://skia.googlecode.com/svn/trunk@14970 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r-- | include/config/SkUserConfig.h | 1 | ||||
-rw-r--r-- | include/core/SkOnce.h | 51 | ||||
-rw-r--r-- | include/core/SkPostConfig.h | 8 | ||||
-rw-r--r-- | include/core/SkThread.h | 19 |
4 files changed, 34 insertions, 45 deletions
diff --git a/include/config/SkUserConfig.h b/include/config/SkUserConfig.h index 81033f3fa5..5f59b9131c 100644 --- a/include/config/SkUserConfig.h +++ b/include/config/SkUserConfig.h @@ -176,5 +176,6 @@ */ //#define SK_ATOMICS_PLATFORM_H "SkAtomics_xxx.h" //#define SK_MUTEX_PLATFORM_H "SkMutex_xxx.h" +//#define SK_BARRIERS_PLATFORM_H "SkBarriers_xxx.h" #endif diff --git a/include/core/SkOnce.h b/include/core/SkOnce.h index d5330b9408..d39a05b7bb 100644 --- a/include/core/SkOnce.h +++ b/include/core/SkOnce.h @@ -71,44 +71,6 @@ struct SkOnceFlag { SkSpinlock lock; }; -// TODO(bungeman, mtklein): move all these *barrier* functions to SkThread when refactoring lands. - -#ifdef SK_BUILD_FOR_WIN -# include <intrin.h> -inline static void compiler_barrier() { - _ReadWriteBarrier(); -} -#else -inline static void compiler_barrier() { - asm volatile("" : : : "memory"); -} -#endif - -inline static void full_barrier_on_arm() { -#if (defined(SK_CPU_ARM) && SK_ARM_ARCH >= 7) || defined(SK_CPU_ARM64) - asm volatile("dmb ish" : : : "memory"); -#elif defined(SK_CPU_ARM) - asm volatile("mcr p15, 0, %0, c7, c10, 5" : : "r" (0) : "memory"); -#endif -} - -// On every platform, we issue a compiler barrier to prevent it from reordering -// code. That's enough for platforms like x86 where release and acquire -// barriers are no-ops. On other platforms we may need to be more careful; -// ARM, in particular, needs real code for both acquire and release. We use a -// full barrier, which acts as both, because that the finest precision ARM -// provides. - -inline static void release_barrier() { - compiler_barrier(); - full_barrier_on_arm(); -} - -inline static void acquire_barrier() { - compiler_barrier(); - full_barrier_on_arm(); -} - // Works with SkSpinlock or SkMutex. template <typename Lock> class SkAutoLockAcquire { @@ -143,8 +105,7 @@ static void sk_once_slow(bool* done, Lock* lock, Func f, Arg arg, void (*atExit) // // We'll use this in the fast path to make sure f(arg)'s effects are // observable whenever we observe *done == true. - release_barrier(); - *done = true; + sk_release_store(done, true); } } @@ -156,15 +117,15 @@ inline void SkOnce(bool* done, Lock* lock, Func f, Arg arg, void(*atExit)()) { } // Also known as a load-load/load-store barrier, this acquire barrier makes // sure that anything we read from memory---in particular, memory written by - // calling f(arg)---is at least as current as the value we read from once->done. + // calling f(arg)---is at least as current as the value we read from done. // // In version control terms, this is a lot like saying "sync up to the - // commit where we wrote once->done = true". + // commit where we wrote done = true". // - // The release barrier in sk_once_slow guaranteed that once->done = true - // happens after f(arg), so by syncing to once->done = true here we're + // The release barrier in sk_once_slow guaranteed that done = true + // happens after f(arg), so by syncing to done = true here we're // forcing ourselves to also wait until the effects of f(arg) are readble. - acquire_barrier(); + SkAssertResult(sk_acquire_load(done)); } template <typename Func, typename Arg> diff --git a/include/core/SkPostConfig.h b/include/core/SkPostConfig.h index 2538522806..d4d9857d87 100644 --- a/include/core/SkPostConfig.h +++ b/include/core/SkPostConfig.h @@ -399,6 +399,14 @@ # endif #endif +#ifndef SK_BARRIERS_PLATFORM_H +# if defined(SK_CPU_ARM) || defined(SK_CPU_ARM64) +# define SK_BARRIERS_PLATFORM_H "../../src/ports/SkBarriers_arm.h" +# else +# define SK_BARRIERS_PLATFORM_H "../../src/ports/SkBarriers_x86.h" +# endif +#endif + ////////////////////////////////////////////////////////////////////// diff --git a/include/core/SkThread.h b/include/core/SkThread.h index c8cd4e9112..3038e2d954 100644 --- a/include/core/SkThread.h +++ b/include/core/SkThread.h @@ -60,6 +60,25 @@ static inline int32_t sk_atomic_conditional_inc(int32_t* addr) { return prev; } +// SK_BARRIERS_PLATFORM_H must provide implementations for the following declarations: + +/** Prevent the compiler from reordering across this barrier. */ +static void sk_compiler_barrier(); + +/** Read T*, with at least an acquire barrier. + * + * Only needs to be implemented for T which can be atomically read. + */ +template <typename T> T sk_acquire_load(T*); + +/** Write T*, with at least a release barrier. + * + * Only needs to be implemented for T which can be atomically written. + */ +template <typename T> void sk_release_store(T*, T); + +#include SK_BARRIERS_PLATFORM_H + /** SK_MUTEX_PLATFORM_H must provide the following (or equivalent) declarations. class SkBaseMutex { |