Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Unified Diff: include/ports/SkAtomics_sync.h

Issue 1441773002: SkAtomic: always use std::atomic (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/ports/SkAtomics_std.h ('k') | include/private/SkAtomics.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/ports/SkAtomics_sync.h
diff --git a/include/ports/SkAtomics_sync.h b/include/ports/SkAtomics_sync.h
deleted file mode 100644
index 02b1e580725d9f949ded0b3c6861f07de16fa8dc..0000000000000000000000000000000000000000
--- a/include/ports/SkAtomics_sync.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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
-
-// This file is mostly a shim. We'd like to delete it. Please don't put much
-// effort into maintaining it, and if you find bugs in it, the right fix is to
-// delete this file and upgrade your compiler to something that supports
-// __atomic builtins or std::atomic.
-
-static inline void barrier(sk_memory_order mo) {
- asm volatile("" : : : "memory"); // Prevents the compiler from reordering code.
- #if SK_CPU_X86
- // On x86, we generally don't need an extra memory barrier for loads or stores.
- if (sk_memory_order_seq_cst == mo) { __sync_synchronize(); }
- #else
- // On other platforms (e.g. ARM) we do unless the memory order is relaxed.
- if (sk_memory_order_relaxed != mo) { __sync_synchronize(); }
- #endif
-}
-
-// These barriers only support our majority use cases: acquire and relaxed loads, release stores.
-// For anything more complicated, please consider deleting this file and upgrading your compiler.
-
-template <typename T>
-T sk_atomic_load(const T* ptr, sk_memory_order mo) {
- T val = *ptr;
- barrier(mo);
- return val;
-}
-
-template <typename T>
-void sk_atomic_store(T* ptr, T val, sk_memory_order mo) {
- barrier(mo);
- *ptr = val;
-}
-
-template <typename T>
-T sk_atomic_fetch_add(T* ptr, T val, sk_memory_order) {
- return __sync_fetch_and_add(ptr, val);
-}
-
-template <typename T>
-T sk_atomic_fetch_sub(T* ptr, T val, sk_memory_order) {
- return __sync_fetch_and_sub(ptr, val);
-}
-
-template <typename T>
-bool sk_atomic_compare_exchange(T* ptr, T* expected, T desired, sk_memory_order, sk_memory_order) {
- T prev = __sync_val_compare_and_swap(ptr, *expected, desired);
- if (prev == *expected) {
- return true;
- }
- *expected = prev;
- 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));
- return prev;
-}
-
-#endif//SkAtomics_sync_DEFINED
« no previous file with comments | « include/ports/SkAtomics_std.h ('k') | include/private/SkAtomics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698