diff --git a/Cargo.toml b/Cargo.toml index 4c6ca8575..74905488f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,6 @@ debug = false lto = true debug-assertions = false - [features] default = ["mmap"] streamdict = [] diff --git a/src/indexer/index_writer.rs b/src/indexer/index_writer.rs index 17e66f4c4..e882facf1 100644 --- a/src/indexer/index_writer.rs +++ b/src/indexer/index_writer.rs @@ -81,10 +81,6 @@ pub struct IndexWriter { committed_opstamp: u64, } -// IndexWriter cannot be sent to another thread. -impl !Send for IndexWriter {} -impl !Sync for IndexWriter {} - /// Open a new index writer. Attempts to acquire a lockfile. /// /// The lockfile should be deleted on drop, but it is possible diff --git a/src/indexer/stamper.rs b/src/indexer/stamper.rs index 63b91f4a4..f9eee3136 100644 --- a/src/indexer/stamper.rs +++ b/src/indexer/stamper.rs @@ -1,15 +1,70 @@ -use std::sync::atomic::{AtomicU64, Ordering}; -use std::sync::Arc; +// AtomicU64 have not landed in stable. +// For the moment let's just use AtomicUsize on +// x86/64 bit platform, and a mutex on other platform. -#[derive(Clone, Default)] -pub struct Stamper(Arc); +#[cfg(target="x86_64")] +mod archicture_impl { -impl Stamper { - pub fn new(first_opstamp: u64) -> Stamper { - Stamper(Arc::new(AtomicU64::new(first_opstamp))) - } + use std::sync::Arc; + use std::sync::atomic::{AtomicUsize, Ordering}; - pub fn stamp(&self) -> u64 { - self.0.fetch_add(1u64, Ordering::SeqCst) + #[derive(Clone, Default)] + pub struct Stamper(Arc); + + impl Stamper { + pub fn new(first_opstamp: u64) -> Stamper { + Stamper(Arc::new(AtomicU64::new(first_opstamp))) + } + + pub fn stamp(&self) -> u64 { + self.0.fetch_add(1u64, Ordering::SeqCst) as u64 + } } } + + + + +#[cfg(not(target="x86_64"))] +mod archicture_impl { + + use std::sync::{Arc, Mutex}; + + #[derive(Clone, Default)] + pub struct Stamper(Arc>); + + impl Stamper { + pub fn new(first_opstamp: u64) -> Stamper { + Stamper(Arc::new(Mutex::new(first_opstamp))) + } + + pub fn stamp(&self) -> u64 { + let mut guard = self.0.lock().expect("Failed to lock the stamper"); + let previous_val = *guard; + *guard = previous_val + 1; + previous_val + } + } +} + +pub use self::archicture_impl::Stamper; + + +#[cfg(test)] +mod test { + + use super::Stamper; + + #[test] + fn test_stamper() { + let stamper = Stamper::new(7u64); + assert_eq!(stamper.stamp(), 7u64); + assert_eq!(stamper.stamp(), 8u64); + + let stamper_clone = stamper.clone(); + assert_eq!(stamper.stamp(), 9u64); + + assert_eq!(stamper.stamp(), 10u64); + assert_eq!(stamper_clone.stamp(), 11u64); + } +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 4a39cdd4f..eec646886 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,9 +2,8 @@ #![cfg_attr(feature = "cargo-clippy", allow(module_inception))] #![cfg_attr(feature = "cargo-clippy", allow(inline_always))] -#![feature(optin_builtin_traits)] #![feature(collections_range)] -#![feature(integer_atomics)] + #![feature(drain_filter)] #![cfg_attr(test, feature(test))] #![cfg_attr(test, feature(iterator_step_by))]