@@ -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,
@@ -55,7 +62,7 @@ impl SyncTable {
55
62
match zalsa. runtime ( ) . block_on (
56
63
db. as_dyn_database ( ) ,
57
64
db. zalsa_local ( ) ,
58
- database_key_index ,
65
+ DatabaseKeyIndex :: new ( self . ingredient , key_index ) ,
59
66
id,
60
67
write,
61
68
) {
@@ -69,7 +76,7 @@ impl SyncTable {
69
76
anyone_waiting : false ,
70
77
} ) ;
71
78
ClaimResult :: Claimed ( ClaimGuard {
72
- database_key_index ,
79
+ key_index ,
73
80
zalsa,
74
81
sync_table : self ,
75
82
_padding : false ,
@@ -83,7 +90,7 @@ impl SyncTable {
83
90
/// released when this value is dropped.
84
91
#[ must_use]
85
92
pub ( crate ) struct ClaimGuard < ' me > {
86
- database_key_index : DatabaseKeyIndex ,
93
+ key_index : Id ,
87
94
zalsa : & ' me Zalsa ,
88
95
sync_table : & ' me SyncTable ,
89
96
// Reduce the size of ClaimResult by making more niches available in ClaimGuard; this fits into
@@ -95,14 +102,13 @@ impl ClaimGuard<'_> {
95
102
fn remove_from_map_and_unblock_queries ( & self ) {
96
103
let mut syncs = self . sync_table . syncs . lock ( ) ;
97
104
98
- let SyncState { anyone_waiting, .. } =
99
- syncs. remove ( & self . database_key_index . key_index ( ) ) . unwrap ( ) ;
105
+ let SyncState { anyone_waiting, .. } = syncs. remove ( & self . key_index ) . unwrap ( ) ;
100
106
101
107
drop ( syncs) ;
102
108
103
109
if anyone_waiting {
104
110
self . zalsa . runtime ( ) . unblock_queries_blocked_on (
105
- self . database_key_index ,
111
+ DatabaseKeyIndex :: new ( self . sync_table . ingredient , self . key_index ) ,
106
112
if std:: thread:: panicking ( ) {
107
113
WaitResult :: Panicked
108
114
} else {
0 commit comments