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

Unified Diff: include/ports/SkAtomics_atomic.h

Issue 868843003: SkAtomics: add asserts for valid memory orders. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: names Created 5 years, 10 months 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 | « no previous file | include/ports/SkAtomics_std.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/ports/SkAtomics_atomic.h
diff --git a/include/ports/SkAtomics_atomic.h b/include/ports/SkAtomics_atomic.h
index 3ae328a153fca91049fcdf18d11ff76d6c93f998..6ae78a89a97702925597a6be4e9049088a009e6d 100644
--- a/include/ports/SkAtomics_atomic.h
+++ b/include/ports/SkAtomics_atomic.h
@@ -3,16 +3,24 @@
template <typename T>
T sk_atomic_load(const T* ptr, sk_memory_order mo) {
+ SkASSERT(mo == sk_memory_order_relaxed ||
+ mo == sk_memory_order_seq_cst ||
+ mo == sk_memory_order_acquire ||
+ mo == sk_memory_order_consume);
return __atomic_load_n(ptr, mo);
}
template <typename T>
void sk_atomic_store(T* ptr, T val, sk_memory_order mo) {
+ SkASSERT(mo == sk_memory_order_relaxed ||
+ mo == sk_memory_order_seq_cst ||
+ mo == sk_memory_order_release);
__atomic_store_n(ptr, val, mo);
}
template <typename T>
T sk_atomic_fetch_add(T* ptr, T val, sk_memory_order mo) {
+ // All values of mo are valid.
return __atomic_fetch_add(ptr, val, mo);
}
@@ -20,6 +28,12 @@ template <typename T>
bool sk_atomic_compare_exchange(T* ptr, T* expected, T desired,
sk_memory_order success,
sk_memory_order failure) {
+ // All values of success are valid.
+ SkASSERT(failure == sk_memory_order_relaxed ||
+ failure == sk_memory_order_seq_cst ||
+ failure == sk_memory_order_acquire ||
+ failure == sk_memory_order_consume);
+ SkASSERT(failure <= success);
return __atomic_compare_exchange_n(ptr, expected, desired, false/*weak?*/, success, failure);
}
« no previous file with comments | « no previous file | include/ports/SkAtomics_std.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698