Skip to content

Commit d141cd8

Browse files
committed
encapsulate Runtime within Zalsa
The aim is to eventually eliminate Runtime.
1 parent 703e12d commit d141cd8

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

src/function/sync.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::{
44
};
55

66
use crate::{
7-
hash::FxDashMap, key::DatabaseKeyIndex, local_state::LocalState, runtime::WaitResult, Database,
8-
Id, Runtime,
7+
hash::FxDashMap, key::DatabaseKeyIndex, local_state::LocalState, runtime::WaitResult,
8+
storage::Zalsa, Database, Id,
99
};
1010

1111
#[derive(Default)]
@@ -28,7 +28,7 @@ impl SyncMap {
2828
local_state: &LocalState,
2929
database_key_index: DatabaseKeyIndex,
3030
) -> Option<ClaimGuard<'me>> {
31-
let runtime = db.zalsa().runtimex();
31+
let zalsa = db.zalsa();
3232
let thread_id = std::thread::current().id();
3333
match self.sync_map.entry(database_key_index.key_index) {
3434
dashmap::mapref::entry::Entry::Vacant(entry) => {
@@ -38,7 +38,7 @@ impl SyncMap {
3838
});
3939
Some(ClaimGuard {
4040
database_key: database_key_index,
41-
runtime,
41+
zalsa,
4242
sync_map: &self.sync_map,
4343
})
4444
}
@@ -51,7 +51,7 @@ impl SyncMap {
5151
// not to gate future atomic reads.
5252
entry.get().anyone_waiting.store(true, Ordering::Relaxed);
5353
let other_id = entry.get().id;
54-
runtime.block_on_or_unwind(db, local_state, database_key_index, other_id, entry);
54+
zalsa.block_on_or_unwind(db, local_state, database_key_index, other_id, entry);
5555
None
5656
}
5757
}
@@ -63,7 +63,7 @@ impl SyncMap {
6363
#[must_use]
6464
pub(super) struct ClaimGuard<'me> {
6565
database_key: DatabaseKeyIndex,
66-
runtime: &'me Runtime,
66+
zalsa: &'me Zalsa,
6767
sync_map: &'me FxDashMap<Id, SyncState>,
6868
}
6969

@@ -75,7 +75,7 @@ impl<'me> ClaimGuard<'me> {
7575
// NB: `Ordering::Relaxed` is sufficient here,
7676
// see `store` above for explanation.
7777
if anyone_waiting.load(Ordering::Relaxed) {
78-
self.runtime
78+
self.zalsa
7979
.unblock_queries_blocked_on(self.database_key, wait_result)
8080
}
8181
}

src/storage.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::any::{Any, TypeId};
2+
use std::thread::ThreadId;
23

34
use orx_concurrent_vec::ConcurrentVec;
45
use parking_lot::Mutex;
@@ -7,10 +8,11 @@ use rustc_hash::FxHashMap;
78
use crate::cycle::CycleRecoveryStrategy;
89
use crate::database::UserData;
910
use crate::ingredient::{Ingredient, Jar};
11+
use crate::local_state::LocalState;
1012
use crate::nonce::{Nonce, NonceGenerator};
11-
use crate::runtime::Runtime;
13+
use crate::runtime::{Runtime, WaitResult};
1214
use crate::views::Views;
13-
use crate::{Database, DatabaseImpl, Durability, Revision};
15+
use crate::{Database, DatabaseImpl, DatabaseKeyIndex, Durability, Revision};
1416

1517
pub fn views<Db: ?Sized + Database>(db: &Db) -> &Views {
1618
db.zalsa().views()
@@ -164,10 +166,6 @@ impl Zalsa {
164166
self.runtime.report_tracked_write(durability)
165167
}
166168

167-
pub(crate) fn runtimex(&self) -> &Runtime {
168-
&self.runtime
169-
}
170-
171169
/// **NOT SEMVER STABLE**
172170
pub fn last_changed_revision(&self, durability: Durability) -> Revision {
173171
self.runtime.last_changed_revision(durability)
@@ -195,6 +193,29 @@ impl Zalsa {
195193

196194
new_revision
197195
}
196+
197+
/// See [`Runtime::block_on_or_unwind`][]
198+
pub(crate) fn block_on_or_unwind<QueryMutexGuard>(
199+
&self,
200+
db: &dyn Database,
201+
local_state: &LocalState,
202+
database_key: DatabaseKeyIndex,
203+
other_id: ThreadId,
204+
query_mutex_guard: QueryMutexGuard,
205+
) {
206+
self.runtime
207+
.block_on_or_unwind(db, local_state, database_key, other_id, query_mutex_guard)
208+
}
209+
210+
/// See [`Runtime::unblock_queries_blocked_on`][]
211+
pub(crate) fn unblock_queries_blocked_on(
212+
&self,
213+
database_key: DatabaseKeyIndex,
214+
wait_result: WaitResult,
215+
) {
216+
self.runtime
217+
.unblock_queries_blocked_on(database_key, wait_result)
218+
}
198219
}
199220

200221
/// Caches a pointer to an ingredient in a database.

0 commit comments

Comments
 (0)