@@ -8,6 +8,8 @@ use std::hash::{Hash, BuildHasher};
8
8
use std:: collections:: hash_map:: RandomState ;
9
9
use std:: borrow:: Borrow ;
10
10
use std:: iter:: FromIterator ;
11
+ use std:: cell;
12
+ use std:: marker:: PhantomData ;
11
13
12
14
/// A handle that may be used to read from the eventually consistent map.
13
15
///
@@ -20,13 +22,15 @@ pub struct ReadHandle<K, V, M = (), S = RandomState>
20
22
{
21
23
pub ( crate ) inner : sync:: Arc < AtomicPtr < Inner < K , V , M , S > > > ,
22
24
epoch : sync:: Arc < sync:: atomic:: AtomicUsize > ,
23
- }
24
25
25
- // Since a `ReadHandle` keeps track of its own epoch, it is not safe for multiple threads to call
26
- // `with_handle` at the same time. We *could* keep it `Sync` and make `with_handle` require `&mut
27
- // self`, but that seems overly excessive. It would also mean that all other methods on
28
- // `ReadHandle` would now take `&mut self`, *and* that `ReadHandle` can no longer be `Clone`.
29
- impl < K , V , M , S > !Sync for ReadHandle < K , V , M , S > { }
26
+ // Since a `ReadHandle` keeps track of its own epoch, it is not safe for multiple threads to
27
+ // call `with_handle` at the same time. We *could* keep it `Sync` and make `with_handle`
28
+ // require `&mut self`, but that seems overly excessive. It would also mean that all other
29
+ // methods on `ReadHandle` would now take `&mut self`, *and* that `ReadHandle` can no longer be
30
+ // `Clone`. Since optin_builtin_traits is still an unstable feature, we use this hack to make
31
+ // `ReadHandle` be marked as `!Sync` (since it contains an `Cell` which is `!Sync`).
32
+ _not_sync_no_feature : PhantomData < cell:: Cell < ( ) > > ,
33
+ }
30
34
31
35
impl < K , V , M , S > Clone for ReadHandle < K , V , M , S >
32
36
where K : Eq + Hash ,
@@ -39,6 +43,7 @@ impl<K, V, M, S> Clone for ReadHandle<K, V, M, S>
39
43
ReadHandle {
40
44
epoch : epoch,
41
45
inner : self . inner . clone ( ) ,
46
+ _not_sync_no_feature : PhantomData ,
42
47
}
43
48
}
44
49
}
@@ -55,6 +60,7 @@ pub fn new<K, V, M, S>(inner: Inner<K, V, M, S>) -> ReadHandle<K, V, M, S>
55
60
ReadHandle {
56
61
epoch : epoch,
57
62
inner : sync:: Arc :: new ( AtomicPtr :: new ( store) ) ,
63
+ _not_sync_no_feature : PhantomData ,
58
64
}
59
65
}
60
66
0 commit comments