 Chromium Code Reviews
 Chromium Code Reviews Issue 1039323002:
  Extract the spinlock from SkOnce as SkSpinlock.  (Closed) 
  Base URL: https://skia.googlesource.com/skia@master
    
  
    Issue 1039323002:
  Extract the spinlock from SkOnce as SkSpinlock.  (Closed) 
  Base URL: https://skia.googlesource.com/skia@master| Index: include/ports/SkAtomics_sync.h | 
| diff --git a/include/ports/SkAtomics_sync.h b/include/ports/SkAtomics_sync.h | 
| index 66da4d35eeb3c47524e4aeb9832aa757ee4cf8fe..7ca0b46a94a6b23f95e60d7d57109cb3325d8167 100644 | 
| --- a/include/ports/SkAtomics_sync.h | 
| +++ b/include/ports/SkAtomics_sync.h | 
| @@ -1,3 +1,10 @@ | 
| +/* | 
| + * Copyright 2015 Google Inc. | 
| + * | 
| + * Use of this source code is governed by a BSD-style license that can be | 
| + * found in the LICENSE file. | 
| + */ | 
| + | 
| #ifndef SkAtomics_sync_DEFINED | 
| #define SkAtomics_sync_DEFINED | 
| @@ -48,4 +55,14 @@ bool sk_atomic_compare_exchange(T* ptr, T* expected, T desired, sk_memory_order, | 
| return false; | 
| } | 
| +template <typename T> | 
| +T sk_atomic_exchange(T* ptr, T val, sk_memory_order) { | 
| + // There is no __sync exchange. Emulate it with a CAS loop. | 
| + T prev; | 
| + do { | 
| + prev = sk_atomic_load(ptr); | 
| + } while(!sk_atomic_compare_exchange(ptr, &prev, val)); | 
| 
bungeman-skia
2015/03/30 14:52:17
nit: usually there is a space between the 'while'
 | 
| + return prev; | 
| +} | 
| + | 
| #endif//SkAtomics_sync_DEFINED |