@@ -7,14 +7,14 @@ use crate::{
7
7
key::DatabaseKeyIndex,
8
8
runtime::{BlockResult, WaitResult},
9
9
zalsa::Zalsa,
10
- Database, Id,
10
+ Database, Id, IngredientIndex,
11
11
};
12
12
13
13
/// Tracks the keys that are currently being processed; used to coordinate between
14
14
/// worker threads.
15
- #[derive(Default)]
16
15
pub(crate) struct SyncTable {
17
16
syncs: Mutex<FxHashMap<Id, SyncState>>,
17
+ ingredient: IngredientIndex,
18
18
}
19
19
20
20
pub(crate) enum ClaimResult<'a> {
@@ -32,14 +32,21 @@ struct SyncState {
32
32
}
33
33
34
34
impl SyncTable {
35
+ pub(crate) fn new(ingredient: IngredientIndex) -> Self {
36
+ Self {
37
+ syncs: Default::default(),
38
+ ingredient,
39
+ }
40
+ }
41
+
35
42
pub(crate) fn try_claim<'me>(
36
43
&'me self,
37
44
db: &'me (impl ?Sized + Database),
38
45
zalsa: &'me Zalsa,
39
- database_key_index: DatabaseKeyIndex ,
46
+ key_index: Id ,
40
47
) -> ClaimResult<'me> {
41
48
let mut write = self.syncs.lock();
42
- match write.entry(database_key_index. key_index() ) {
49
+ match write.entry(key_index) {
43
50
std::collections::hash_map::Entry::Occupied(occupied_entry) => {
44
51
let &mut SyncState {
45
52
id,
@@ -52,7 +59,12 @@ impl SyncTable {
52
59
// boolean is to decide *whether* to acquire the lock,
53
60
// not to gate future atomic reads.
54
61
*anyone_waiting = true;
55
- match zalsa.runtime().block_on(db, database_key_index, id, write) {
62
+ match zalsa.runtime().block_on(
63
+ db,
64
+ DatabaseKeyIndex::new(self.ingredient, key_index),
65
+ id,
66
+ write,
67
+ ) {
56
68
BlockResult::Completed => ClaimResult::Retry,
57
69
BlockResult::Cycle => ClaimResult::Cycle,
58
70
}
@@ -63,7 +75,7 @@ impl SyncTable {
63
75
anyone_waiting: false,
64
76
});
65
77
ClaimResult::Claimed(ClaimGuard {
66
- database_key_index ,
78
+ key_index ,
67
79
zalsa,
68
80
sync_table: self,
69
81
_padding: false,
@@ -77,7 +89,7 @@ impl SyncTable {
77
89
/// released when this value is dropped.
78
90
#[must_use]
79
91
pub(crate) struct ClaimGuard<'me> {
80
- database_key_index: DatabaseKeyIndex ,
92
+ key_index: Id ,
81
93
zalsa: &'me Zalsa,
82
94
sync_table: &'me SyncTable,
83
95
// Reduce the size of ClaimResult by making more niches available in ClaimGuard; this fits into
@@ -89,14 +101,13 @@ impl ClaimGuard<'_> {
89
101
fn remove_from_map_and_unblock_queries(&self) {
90
102
let mut syncs = self.sync_table.syncs.lock();
91
103
92
- let SyncState { anyone_waiting, .. } =
93
- syncs.remove(&self.database_key_index.key_index()).unwrap();
104
+ let SyncState { anyone_waiting, .. } = syncs.remove(&self.key_index).unwrap();
94
105
95
106
drop(syncs);
96
107
97
108
if anyone_waiting {
98
109
self.zalsa.runtime().unblock_queries_blocked_on(
99
- self.database_key_index ,
110
+ DatabaseKeyIndex::new( self.sync_table.ingredient, self.key_index) ,
100
111
if std::thread::panicking() {
101
112
WaitResult::Panicked
102
113
} else {
0 commit comments