Skip to content

Commit 335715b

Browse files
committed
Avoid unstable !Sync impl feature requirement
Note that !Sync doesn't yet show up in docs because of rust-lang/rust#17606.
1 parent 1066dc9 commit 335715b

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "evmap"
3-
version = "0.6.1"
3+
version = "0.6.2"
44

55
description = "A lock-free, eventually consistent, concurrent multi-value map."
66
readme = "README.md"

src/lib.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
//! });
104104
//! ```
105105
#![deny(missing_docs)]
106-
#![feature(optin_builtin_traits)]
107106

108107
use std::collections::hash_map::RandomState;
109108
use std::hash::{Hash, BuildHasher};
@@ -219,3 +218,15 @@ pub fn with_meta<K, V, M>
219218
{
220219
Options::default().with_meta(meta).construct()
221220
}
221+
222+
// test that ReadHandle isn't Sync
223+
// waiting on https://github.com/rust-lang/rust/issues/17606
224+
//#[test]
225+
//fn is_not_sync() {
226+
// use std::sync;
227+
// use std::thread;
228+
// let (r, mut w) = new();
229+
// w.insert(true, false);
230+
// let x = sync::Arc::new(r);
231+
// thread::spawn(move || { drop(x); });
232+
//}

src/read.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use std::hash::{Hash, BuildHasher};
88
use std::collections::hash_map::RandomState;
99
use std::borrow::Borrow;
1010
use std::iter::FromIterator;
11+
use std::cell;
12+
use std::marker::PhantomData;
1113

1214
/// A handle that may be used to read from the eventually consistent map.
1315
///
@@ -20,13 +22,15 @@ pub struct ReadHandle<K, V, M = (), S = RandomState>
2022
{
2123
pub(crate) inner: sync::Arc<AtomicPtr<Inner<K, V, M, S>>>,
2224
epoch: sync::Arc<sync::atomic::AtomicUsize>,
23-
}
2425

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+
}
3034

3135
impl<K, V, M, S> Clone for ReadHandle<K, V, M, S>
3236
where K: Eq + Hash,
@@ -39,6 +43,7 @@ impl<K, V, M, S> Clone for ReadHandle<K, V, M, S>
3943
ReadHandle {
4044
epoch: epoch,
4145
inner: self.inner.clone(),
46+
_not_sync_no_feature: PhantomData,
4247
}
4348
}
4449
}
@@ -55,6 +60,7 @@ pub fn new<K, V, M, S>(inner: Inner<K, V, M, S>) -> ReadHandle<K, V, M, S>
5560
ReadHandle {
5661
epoch: epoch,
5762
inner: sync::Arc::new(AtomicPtr::new(store)),
63+
_not_sync_no_feature: PhantomData,
5864
}
5965
}
6066

0 commit comments

Comments
 (0)