Skip to content

Commit b0ac54a

Browse files
committed
Remove ATOMIC_U8_REF_INIT and static_atomic_ref
1 parent 557aef0 commit b0ac54a

File tree

1 file changed

+3
-87
lines changed

1 file changed

+3
-87
lines changed

src/lib.rs

Lines changed: 3 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@
3939
//! }
4040
//!
4141
//! // The methods for working with our currently defined static logger
42-
//! static_atomic_ref! {
43-
//! static LOGGER: AtomicRef<LoggerInfo>;
44-
//! }
42+
//! static LOGGER: AtomicRef<LoggerInfo> = AtomicRef::new(None);
4543
//! fn log(msg: &str) -> bool {
4644
//! if let Some(info) = LOGGER.load(Ordering::SeqCst) {
4745
//! info.logger.log(msg);
@@ -73,7 +71,6 @@
7371
//! ```
7472
#![no_std]
7573

76-
7774
use core::sync::atomic::{AtomicPtr, Ordering};
7875
use core::marker::PhantomData;
7976
use core::fmt;
@@ -92,91 +89,11 @@ pub struct AtomicRef<'a, T: 'a> {
9289
// `#![feature(const_fn)]`
9390
struct Invariant<'a, T: 'a>(&'a mut &'a mut T);
9491

95-
/// You will probably never need to use this type. It exists mostly for internal
96-
/// use in the `static_atomic_ref!` macro.
97-
///
98-
/// Unlike `AtomicUsize` and its ilk, we cannot have an `ATOMIC_REF_INIT` const
99-
/// which is initialized to `None`, as constants cannot be generic over a type
100-
/// parameter. This is the same reason why `AtomicPtr` does not have an
101-
/// `ATOMIC_PTR_INIT` const.
102-
///
103-
/// Instead, we have a single const for `&'static u8`, and take advantage of the
104-
/// fact that all AtomicRef types have identical layout to implement the
105-
/// `static_atomic_ref!` macro.
106-
///
107-
/// Please use `static_atomic_ref!` instead of this constant if you need to
108-
/// implement a static atomic reference variable.
109-
pub const ATOMIC_U8_REF_INIT: AtomicRef<'static, u8> = AtomicRef {
110-
data: AtomicPtr::new(null_mut()),
111-
_marker: PhantomData,
112-
};
113-
11492
/// Re-export `core` for `static_atomic_ref!` (which may be used in a
11593
/// non-`no_std` crate, where `core` is unavailable).
11694
#[doc(hidden)]
11795
pub use core::{mem as core_mem, ops as core_ops};
11896

119-
/// A macro to define a statically allocated `AtomicRef<'static, T>` which is
120-
/// initialized to `None`.
121-
///
122-
/// # Examples
123-
///
124-
/// ```
125-
/// # #[macro_use]
126-
/// # extern crate atomic_ref;
127-
/// use std::sync::atomic::Ordering;
128-
///
129-
/// static_atomic_ref! {
130-
/// static SOME_REFERENCE: AtomicRef<i32>;
131-
/// pub static PUB_REFERENCE: AtomicRef<u64>;
132-
/// }
133-
///
134-
/// fn main() {
135-
/// let a: Option<&'static i32> = SOME_REFERENCE.load(Ordering::SeqCst);
136-
/// assert_eq!(a, None);
137-
/// }
138-
/// ```
139-
#[macro_export]
140-
macro_rules! static_atomic_ref {
141-
($(#[$attr:meta])* static $N:ident : AtomicRef<$T:ty>; $($t:tt)*) => {
142-
static_atomic_ref!(@PRIV, $(#[$attr])* static $N : $T; $($t)*);
143-
};
144-
($(#[$attr:meta])* pub static $N:ident : AtomicRef<$T:ty>; $($t:tt)*) => {
145-
static_atomic_ref!(@PUB, $(#[$attr])* static $N : $T; $($t)*);
146-
};
147-
(@$VIS:ident, $(#[$attr:meta])* static $N:ident : $T:ty; $($t:tt)*) => {
148-
static_atomic_ref!(@MAKE TY, $VIS, $(#[$attr])*, $N);
149-
impl $crate::core_ops::Deref for $N {
150-
type Target = $crate::AtomicRef<'static, $T>;
151-
#[allow(unsafe_code)]
152-
fn deref<'a>(&'a self) -> &'a $crate::AtomicRef<'static, $T> {
153-
static STORAGE: $crate::AtomicRef<'static, u8> = $crate::ATOMIC_U8_REF_INIT;
154-
unsafe { $crate::core_mem::transmute(&STORAGE) }
155-
}
156-
}
157-
static_atomic_ref!($($t)*);
158-
};
159-
(@MAKE TY, PUB, $(#[$attr:meta])*, $N:ident) => {
160-
#[allow(missing_copy_implementations)]
161-
#[allow(non_camel_case_types)]
162-
#[allow(dead_code)]
163-
$(#[$attr])*
164-
pub struct $N { _private: () }
165-
#[doc(hidden)]
166-
pub static $N: $N = $N { _private: () };
167-
};
168-
(@MAKE TY, PRIV, $(#[$attr:meta])*, $N:ident) => {
169-
#[allow(missing_copy_implementations)]
170-
#[allow(non_camel_case_types)]
171-
#[allow(dead_code)]
172-
$(#[$attr])*
173-
struct $N { _private: () }
174-
#[doc(hidden)]
175-
static $N: $N = $N { _private: () };
176-
};
177-
() => ();
178-
}
179-
18097
/// An internal helper function for converting `Option<&'a T>` values to
18198
/// `*mut T` for storing in the `AtomicUsize`.
18299
const fn from_opt<'a, T>(p: Option<&'a T>) -> *mut T {
@@ -416,10 +333,9 @@ impl<'a, T> Default for AtomicRef<'a, T> {
416333
#[cfg(test)]
417334
mod tests {
418335
use core::sync::atomic::Ordering;
336+
use super::AtomicRef;
419337

420-
static_atomic_ref! {
421-
static FOO: AtomicRef<i32>;
422-
}
338+
static FOO: AtomicRef<i32> = AtomicRef::new(None);
423339

424340
static A: i32 = 10;
425341

0 commit comments

Comments
 (0)