Skip to content

Commit 70fd306

Browse files
committed
Make mk_attr_id thread safe
1 parent d81cd38 commit 70fd306

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/libsyntax/attr.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use symbol::Symbol;
3131
use tokenstream::{TokenStream, TokenTree, Delimited};
3232
use util::ThinVec;
3333

34-
use std::cell::{RefCell, Cell};
34+
use std::cell::RefCell;
3535
use std::iter;
3636

3737
thread_local! {
@@ -419,16 +419,14 @@ pub fn mk_spanned_word_item(sp: Span, name: Name) -> MetaItem {
419419
MetaItem { span: sp, name: name, node: MetaItemKind::Word }
420420
}
421421

422+
pub fn mk_attr_id() -> AttrId {
423+
use std::sync::atomic::AtomicUsize;
424+
use std::sync::atomic::Ordering;
422425

426+
static NEXT_ATTR_ID: AtomicUsize = AtomicUsize::new(0);
423427

424-
thread_local! { static NEXT_ATTR_ID: Cell<usize> = Cell::new(0) }
425-
426-
pub fn mk_attr_id() -> AttrId {
427-
let id = NEXT_ATTR_ID.with(|slot| {
428-
let r = slot.get();
429-
slot.set(r + 1);
430-
r
431-
});
428+
let id = NEXT_ATTR_ID.fetch_add(1, Ordering::SeqCst);
429+
assert!(id != ::std::usize::MAX);
432430
AttrId(id)
433431
}
434432

src/libsyntax/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#![feature(rustc_diagnostic_macros)]
2525
#![feature(match_default_bindings)]
2626
#![feature(i128_type)]
27+
#![feature(const_atomic_usize_new)]
2728

2829
// See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
2930
#[allow(unused_extern_crates)]

0 commit comments

Comments
 (0)