diff options
| author | bors <bors@rust-lang.org> | 2015-07-21 00:03:37 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-07-21 00:03:37 +0000 |
| commit | 118a5c4c342883606fd96b121d741b133caa0347 (patch) | |
| tree | 6fc6a2c1cc22df2213444275ebe77a52f08fcfba | |
| parent | ed49bad0ccb0e9ee7e5ebea69d72a98bed08f77f (diff) | |
| parent | 225ad1752039f6c48189e8e30d4824de691761da (diff) | |
| download | rust-118a5c4c342883606fd96b121d741b133caa0347.tar.gz rust-118a5c4c342883606fd96b121d741b133caa0347.zip | |
Auto merge of #27129 - arthurprs:debug_atomic, r=alexcrichton
I'm being constantly bitten by the lack of this implementation.
I'm unsure if there's a reason to avoid these implementations though.
Since we have a "lossy" implementation for both Mutex and RWLock (RWLock {{ locked }}) I don't think there's a big reason for not having a Debug implementation for the atomic types, even if the user can't specify the ordering.
| -rw-r--r-- | src/libcore/atomic.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libcore/atomic.rs b/src/libcore/atomic.rs index a77df096643..c6434e71957 100644 --- a/src/libcore/atomic.rs +++ b/src/libcore/atomic.rs @@ -78,6 +78,7 @@ use intrinsics; use cell::UnsafeCell; use default::Default; +use fmt; /// A boolean type which can be safely shared between threads. #[stable(feature = "rust1", since = "1.0.0")] @@ -1089,3 +1090,23 @@ pub fn fence(order: Ordering) { } } } + +macro_rules! impl_Debug { + ($($t:ident)*) => ($( + #[stable(feature = "atomic_debug", since = "1.3.0")] + impl fmt::Debug for $t { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple(stringify!($t)).field(&self.load(Ordering::SeqCst)).finish() + } + } + )*); +} + +impl_Debug!{ AtomicUsize AtomicIsize AtomicBool } + +#[stable(feature = "atomic_debug", since = "1.3.0")] +impl<T> fmt::Debug for AtomicPtr<T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("AtomicPtr").field(&self.load(Ordering::SeqCst)).finish() + } +} |
