diff options
| author | bors <bors@rust-lang.org> | 2017-12-22 12:34:45 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-12-22 12:34:45 +0000 |
| commit | 2c037d55891a974be415f9dac32e1bacfbb46210 (patch) | |
| tree | 354fd55beb26e55c5b36d70852d6fdbcc1506ccd /src/libsyntax | |
| parent | 264af16757e3aab5abc6606e016c10faf204380a (diff) | |
| parent | 84ce4f1c10f419916a4432cc3b021797f4dc4bfe (diff) | |
| download | rust-2c037d55891a974be415f9dac32e1bacfbb46210.tar.gz rust-2c037d55891a974be415f9dac32e1bacfbb46210.zip | |
Auto merge of #46779 - Zoxc:par-merge-without-sync, r=arielb1
Work towards thread safety in rustc This PR is split out from https://github.com/rust-lang/rust/pull/45912. It contains changes which do not require the `sync` module.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/attr.rs | 16 | ||||
| -rw-r--r-- | src/libsyntax/lib.rs | 1 |
2 files changed, 8 insertions, 9 deletions
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index e5e95002e10..cc72ff7d15d 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -31,7 +31,7 @@ use symbol::Symbol; use tokenstream::{TokenStream, TokenTree, Delimited}; use util::ThinVec; -use std::cell::{RefCell, Cell}; +use std::cell::RefCell; use std::iter; thread_local! { @@ -419,16 +419,14 @@ pub fn mk_spanned_word_item(sp: Span, name: Name) -> MetaItem { MetaItem { span: sp, name: name, node: MetaItemKind::Word } } +pub fn mk_attr_id() -> AttrId { + use std::sync::atomic::AtomicUsize; + use std::sync::atomic::Ordering; + static NEXT_ATTR_ID: AtomicUsize = AtomicUsize::new(0); -thread_local! { static NEXT_ATTR_ID: Cell<usize> = Cell::new(0) } - -pub fn mk_attr_id() -> AttrId { - let id = NEXT_ATTR_ID.with(|slot| { - let r = slot.get(); - slot.set(r + 1); - r - }); + let id = NEXT_ATTR_ID.fetch_add(1, Ordering::SeqCst); + assert!(id != ::std::usize::MAX); AttrId(id) } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 44383233a8a..0b51f2e9814 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -24,6 +24,7 @@ #![feature(rustc_diagnostic_macros)] #![feature(match_default_bindings)] #![feature(i128_type)] +#![feature(const_atomic_usize_new)] // See librustc_cratesio_shim/Cargo.toml for a comment explaining this. #[allow(unused_extern_crates)] |
