1
1
use std:: thread:: ThreadId ;
2
2
3
- use crate :: active_query:: ActiveQuery ;
4
3
use crate :: key:: DatabaseKeyIndex ;
5
4
use crate :: runtime:: WaitResult ;
6
5
use parking_lot:: MutexGuard ;
@@ -59,12 +58,9 @@ impl DependencyGraph {
59
58
from_id : ThreadId ,
60
59
database_key : DatabaseKeyIndex ,
61
60
to_id : ThreadId ,
62
- from_stack : & mut [ ActiveQuery ] ,
63
61
query_mutex_guard : QueryMutexGuard ,
64
62
) -> WaitResult {
65
- // SAFETY: We are blocking until the result is removed from `DependencyGraph::wait_results`
66
- // and as such we are keeping `from_stack` alive.
67
- let condvar = unsafe { me. add_edge ( from_id, database_key, to_id, from_stack) } ;
63
+ let edge = me. add_edge ( from_id, database_key, to_id) ;
68
64
69
65
// Release the mutex that prevents `database_key`
70
66
// from completing, now that the edge has been added.
@@ -75,30 +71,23 @@ impl DependencyGraph {
75
71
debug_assert ! ( !me. edges. contains_key( & from_id) ) ;
76
72
return result;
77
73
}
78
- condvar . wait ( & mut me) ;
74
+ edge . wait ( & mut me) ;
79
75
}
80
76
}
81
77
82
78
/// Helper for `block_on`: performs actual graph modification
83
79
/// to add a dependency edge from `from_id` to `to_id`, which is
84
80
/// computing `database_key`.
85
- ///
86
- /// # Safety
87
- ///
88
- /// The caller needs to keep `from_stack`/`'aq`` alive until `from_id` has been removed from the `wait_results`.
89
- // This safety invariant is consumed by the `Edge` struct
90
- unsafe fn add_edge < ' aq > (
81
+ fn add_edge (
91
82
& mut self ,
92
83
from_id : ThreadId ,
93
84
database_key : DatabaseKeyIndex ,
94
85
to_id : ThreadId ,
95
- from_stack : & ' aq mut [ ActiveQuery ] ,
96
- ) -> edge:: EdgeGuard < ' aq > {
86
+ ) -> edge:: EdgeGuard {
97
87
assert_ne ! ( from_id, to_id) ;
98
88
debug_assert ! ( !self . edges. contains_key( & from_id) ) ;
99
89
debug_assert ! ( !self . depends_on( to_id, from_id) ) ;
100
- // SAFETY: The caller is responsible for ensuring that the `EdgeGuard` outlives the `Edge`.
101
- let ( edge, guard) = unsafe { edge:: Edge :: new ( to_id, from_stack) } ;
90
+ let ( edge, guard) = edge:: Edge :: new ( to_id) ;
102
91
self . edges . insert ( from_id, edge) ;
103
92
self . query_dependents
104
93
. entry ( database_key)
@@ -138,11 +127,11 @@ impl DependencyGraph {
138
127
}
139
128
140
129
mod edge {
141
- use std:: { marker :: PhantomData , sync:: Arc , thread:: ThreadId } ;
130
+ use std:: { sync:: Arc , thread:: ThreadId } ;
142
131
143
132
use parking_lot:: MutexGuard ;
144
133
145
- use crate :: { active_query :: ActiveQuery , runtime:: dependency_graph:: DependencyGraph } ;
134
+ use crate :: runtime:: dependency_graph:: DependencyGraph ;
146
135
147
136
#[ derive( Debug ) ]
148
137
pub ( super ) struct Edge {
@@ -153,35 +142,24 @@ mod edge {
153
142
condvar : Arc < parking_lot:: Condvar > ,
154
143
}
155
144
156
- pub struct EdgeGuard < ' aq > {
145
+ pub struct EdgeGuard {
157
146
condvar : Arc < parking_lot:: Condvar > ,
158
- // Inform the borrow checker that the edge stack is borrowed until the guard is released.
159
- // This is necessary to ensure that the stack is not modified by the caller of
160
- // `DependencyGraph::add_edge` after the call returns.
161
- _pd : PhantomData < & ' aq mut [ ActiveQuery ] > ,
162
147
}
163
148
164
- impl EdgeGuard < ' _ > {
149
+ impl EdgeGuard {
165
150
pub fn wait ( & self , mutex_guard : & mut MutexGuard < ' _ , DependencyGraph > ) {
166
151
self . condvar . wait ( mutex_guard)
167
152
}
168
153
}
169
154
170
155
impl Edge {
171
- pub ( super ) unsafe fn new (
172
- blocked_on_id : ThreadId ,
173
- stack : & mut [ ActiveQuery ] ,
174
- ) -> ( Self , EdgeGuard < ' _ > ) {
175
- _ = stack;
156
+ pub ( super ) fn new ( blocked_on_id : ThreadId ) -> ( Self , EdgeGuard ) {
176
157
let condvar = Arc :: new ( parking_lot:: Condvar :: new ( ) ) ;
177
158
let edge = Self {
178
159
blocked_on_id,
179
160
condvar : condvar. clone ( ) ,
180
161
} ;
181
- let edge_guard = EdgeGuard {
182
- condvar,
183
- _pd : PhantomData ,
184
- } ;
162
+ let edge_guard = EdgeGuard { condvar } ;
185
163
( edge, edge_guard)
186
164
}
187
165
0 commit comments