mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-22 01:57:41 +08:00
get rids of the horrendous spinlock in favor of synchronoise
This commit is contained in:
parent
7b6673dc1d
commit
366a344474
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1791,6 +1791,7 @@ dependencies = [
|
||||
"nelson",
|
||||
"roaring 0.9.0",
|
||||
"serde",
|
||||
"synchronoise",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"time",
|
||||
|
@ -19,6 +19,7 @@ tempfile = "3.3.0"
|
||||
thiserror = "1.0.30"
|
||||
time = { version = "0.3.7", features = ["serde-well-known", "formatting", "parsing", "macros"] }
|
||||
uuid = { version = "1.1.2", features = ["serde", "v4"] }
|
||||
synchronoise = "1.0.1"
|
||||
|
||||
[dev-dependencies]
|
||||
nelson = { git = "https://github.com/meilisearch/nelson.git", rev = "675f13885548fb415ead8fbb447e9e6d9314000a"}
|
||||
|
@ -10,6 +10,7 @@ pub use error::Error;
|
||||
use file_store::FileStore;
|
||||
use index::Index;
|
||||
use index_mapper::IndexMapper;
|
||||
use synchronoise::SignalEvent;
|
||||
pub use task::Task;
|
||||
use task::{Kind, KindWithContent, Status};
|
||||
use time::OffsetDateTime;
|
||||
@ -73,10 +74,16 @@ pub struct IndexScheduler {
|
||||
index_mapper: IndexMapper,
|
||||
|
||||
// set to true when there is work to do.
|
||||
wake_up: Arc<AtomicBool>,
|
||||
wake_up: Arc<SignalEvent>,
|
||||
}
|
||||
|
||||
impl IndexScheduler {
|
||||
pub fn new() -> Self {
|
||||
// we want to start the loop right away in case meilisearch was ctrl+Ced while processing things
|
||||
let wake_up = SignalEvent::auto(true);
|
||||
todo!()
|
||||
}
|
||||
|
||||
/// Return the index corresponding to the name. If it wasn't opened before
|
||||
/// it'll be opened. But if it doesn't exist on disk it'll throw an
|
||||
/// `IndexNotFound` error.
|
||||
@ -166,8 +173,7 @@ impl IndexScheduler {
|
||||
/// This worker function must be run in a different thread and must be run only once.
|
||||
fn run(&self) {
|
||||
loop {
|
||||
// TODO: TAMO: remove this horrible spinlock in favor of a sleep / channel / we’ll see
|
||||
while !self.wake_up.swap(false, Ordering::Relaxed) {}
|
||||
self.wake_up.wait();
|
||||
|
||||
let mut wtxn = match self.env.write_txn() {
|
||||
Ok(wtxn) => wtxn,
|
||||
@ -370,7 +376,6 @@ impl IndexScheduler {
|
||||
|
||||
/// Notify the scheduler there is or may be work to do.
|
||||
pub fn notify(&self) {
|
||||
self.wake_up
|
||||
.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
self.wake_up.signal()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user