diff options
| author | Steven Fackler <sfackler@gmail.com> | 2014-04-26 18:25:20 -0700 |
|---|---|---|
| committer | Steven Fackler <sfackler@gmail.com> | 2014-05-01 19:07:40 -0700 |
| commit | b0b7c252d79f57e47af5f677b9e551f42657c509 (patch) | |
| tree | 20505e9beef7594687052800b33210ddc11342ce /src/libstd/sync | |
| parent | 9f836d5a53e20fde65aa3469fa1826228e7c273a (diff) | |
| download | rust-b0b7c252d79f57e47af5f677b9e551f42657c509.tar.gz rust-b0b7c252d79f57e47af5f677b9e551f42657c509.zip | |
Add debug_assert and debug_assert_eq macros
I also switched some `assert!` calls over to `debug_assert!`. Closes #12049. RFC: 0015-assert
Diffstat (limited to 'src/libstd/sync')
| -rw-r--r-- | src/libstd/sync/arc.rs | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/libstd/sync/arc.rs b/src/libstd/sync/arc.rs index 7ac7700d8d3..8d6d1c222cf 100644 --- a/src/libstd/sync/arc.rs +++ b/src/libstd/sync/arc.rs @@ -86,8 +86,7 @@ impl<T: Send> UnsafeArc<T> { #[inline] pub fn get(&self) -> *mut T { unsafe { - // FIXME(#12049): this needs some sort of debug assertion - if cfg!(test) { assert!((*self.data).count.load(Relaxed) > 0); } + debug_assert!((*self.data).count.load(Relaxed) > 0); return (*self.data).data.get(); } } @@ -97,8 +96,7 @@ impl<T: Send> UnsafeArc<T> { #[inline] pub fn get_immut(&self) -> *T { unsafe { - // FIXME(#12049): this needs some sort of debug assertion - if cfg!(test) { assert!((*self.data).count.load(Relaxed) > 0); } + debug_assert!((*self.data).count.load(Relaxed) > 0); return (*self.data).data.get() as *T; } } @@ -125,8 +123,7 @@ impl<T: Send> Clone for UnsafeArc<T> { // synchronization. // [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html) let old_count = (*self.data).count.fetch_add(1, Relaxed); - // FIXME(#12049): this needs some sort of debug assertion - if cfg!(test) { assert!(old_count >= 1); } + debug_assert!(old_count >= 1); return UnsafeArc { data: self.data }; } } @@ -144,8 +141,7 @@ impl<T> Drop for UnsafeArc<T>{ // Because `fetch_sub` is already atomic, we do not need to synchronize with other // threads unless we are going to delete the object. let old_count = (*self.data).count.fetch_sub(1, Release); - // FIXME(#12049): this needs some sort of debug assertion - if cfg!(test) { assert!(old_count >= 1); } + debug_assert!(old_count >= 1); if old_count == 1 { // This fence is needed to prevent reordering of use of the data and deletion of // the data. Because it is marked `Release`, the decreasing of the reference count |
