@@ -30,13 +30,13 @@ use ptr::P;
30
30
use symbol:: Symbol ;
31
31
use tokenstream:: { TokenStream , TokenTree , Delimited } ;
32
32
use util:: ThinVec ;
33
+ use rustc_data_structures:: sync:: Lock ;
33
34
34
- use std:: cell:: { RefCell , Cell } ;
35
35
use std:: iter;
36
36
37
- thread_local ! {
38
- static USED_ATTRS : RefCell <Vec <u64 >> = RefCell :: new( Vec :: new( ) ) ;
39
- static KNOWN_ATTRS : RefCell <Vec <u64 >> = RefCell :: new( Vec :: new( ) ) ;
37
+ rustc_global ! {
38
+ static USED_ATTRS : Lock <Vec <u64 >> = Lock :: new( Vec :: new( ) ) ;
39
+ static KNOWN_ATTRS : Lock <Vec <u64 >> = Lock :: new( Vec :: new( ) ) ;
40
40
}
41
41
42
42
enum AttrError {
@@ -65,45 +65,49 @@ fn handle_errors(diag: &Handler, span: Span, error: AttrError) {
65
65
pub fn mark_used ( attr : & Attribute ) {
66
66
debug ! ( "Marking {:?} as used." , attr) ;
67
67
let AttrId ( id) = attr. id ;
68
- USED_ATTRS . with ( |slot| {
68
+ rustc_access_global ! ( USED_ATTRS , |slot| {
69
+ let mut slot = slot. lock( ) ;
69
70
let idx = ( id / 64 ) as usize ;
70
71
let shift = id % 64 ;
71
- if slot. borrow ( ) . len ( ) <= idx {
72
- slot. borrow_mut ( ) . resize ( idx + 1 , 0 ) ;
72
+ if slot. len( ) <= idx {
73
+ slot. resize( idx + 1 , 0 ) ;
73
74
}
74
- slot. borrow_mut ( ) [ idx] |= 1 << shift;
75
+ slot[ idx] |= 1 << shift;
75
76
} ) ;
76
77
}
77
78
78
79
pub fn is_used ( attr : & Attribute ) -> bool {
79
80
let AttrId ( id) = attr. id ;
80
- USED_ATTRS . with ( |slot| {
81
+ rustc_access_global ! ( USED_ATTRS , |slot| {
82
+ let slot = slot. lock( ) ;
81
83
let idx = ( id / 64 ) as usize ;
82
84
let shift = id % 64 ;
83
- slot. borrow ( ) . get ( idx) . map ( |bits| bits & ( 1 << shift) != 0 )
85
+ slot. get( idx) . map( |bits| bits & ( 1 << shift) != 0 )
84
86
. unwrap_or( false )
85
87
} )
86
88
}
87
89
88
90
pub fn mark_known ( attr : & Attribute ) {
89
91
debug ! ( "Marking {:?} as known." , attr) ;
90
92
let AttrId ( id) = attr. id ;
91
- KNOWN_ATTRS . with ( |slot| {
93
+ rustc_access_global ! ( KNOWN_ATTRS , |slot| {
94
+ let mut slot = slot. lock( ) ;
92
95
let idx = ( id / 64 ) as usize ;
93
96
let shift = id % 64 ;
94
- if slot. borrow ( ) . len ( ) <= idx {
95
- slot. borrow_mut ( ) . resize ( idx + 1 , 0 ) ;
97
+ if slot. len( ) <= idx {
98
+ slot. resize( idx + 1 , 0 ) ;
96
99
}
97
- slot. borrow_mut ( ) [ idx] |= 1 << shift;
100
+ slot[ idx] |= 1 << shift;
98
101
} ) ;
99
102
}
100
103
101
104
pub fn is_known ( attr : & Attribute ) -> bool {
102
105
let AttrId ( id) = attr. id ;
103
- KNOWN_ATTRS . with ( |slot| {
106
+ rustc_access_global ! ( KNOWN_ATTRS , |slot| {
107
+ let slot = slot. lock( ) ;
104
108
let idx = ( id / 64 ) as usize ;
105
109
let shift = id % 64 ;
106
- slot. borrow ( ) . get ( idx) . map ( |bits| bits & ( 1 << shift) != 0 )
110
+ slot. get( idx) . map( |bits| bits & ( 1 << shift) != 0 )
107
111
. unwrap_or( false )
108
112
} )
109
113
}
0 commit comments