@@ -191,69 +191,45 @@ impl LastCommit {
191
191
192
192
pub type MinerThreadJoinHandle = JoinHandle < Result < ( ) , NakamotoNodeError > > ;
193
193
194
- /// Miner thread join handle.
195
- /// This can be a "bare" miner thread, or a "tenure-stop" miner thread which itself stops a "bare"
196
- /// miner thread.
197
- pub enum MinerStopHandle {
198
- Miner ( MinerThreadJoinHandle , Arc < AtomicBool > ) ,
199
- TenureStop ( MinerThreadJoinHandle , Arc < AtomicBool > ) ,
194
+ /// Miner thread join handle, as well as an "abort" flag to force the miner thread to exit when it
195
+ /// is blocked.
196
+ pub struct MinerStopHandle {
197
+ /// The join handle itself
198
+ join_handle : MinerThreadJoinHandle ,
199
+ /// The relayer-set abort flag
200
+ abort_flag : Arc < AtomicBool > ,
200
201
}
201
202
202
203
impl MinerStopHandle {
203
- pub fn new_miner ( jh : MinerThreadJoinHandle , abort_flag : Arc < AtomicBool > ) -> Self {
204
- Self :: Miner ( jh, abort_flag)
205
- }
206
-
207
- pub fn new_tenure_stop ( jh : MinerThreadJoinHandle , abort_flag : Arc < AtomicBool > ) -> Self {
208
- Self :: TenureStop ( jh, abort_flag)
204
+ pub fn new ( join_handle : MinerThreadJoinHandle , abort_flag : Arc < AtomicBool > ) -> Self {
205
+ Self {
206
+ join_handle,
207
+ abort_flag,
208
+ }
209
209
}
210
210
211
+ /// Get a ref to the inner thread object
211
212
pub fn inner_thread ( & self ) -> & std:: thread:: Thread {
212
- match self {
213
- Self :: Miner ( jh, ..) => jh. thread ( ) ,
214
- Self :: TenureStop ( jh, ..) => jh. thread ( ) ,
215
- }
213
+ self . join_handle . thread ( )
216
214
}
217
215
216
+ /// Destroy this stop handle to get the thread join handle
218
217
pub fn into_inner ( self ) -> MinerThreadJoinHandle {
219
- match self {
220
- Self :: Miner ( jh, ..) => jh,
221
- Self :: TenureStop ( jh, ..) => jh,
222
- }
223
- }
224
-
225
- pub fn is_tenure_stop ( & self ) -> bool {
226
- match self {
227
- Self :: TenureStop ( ..) => true ,
228
- _ => false ,
229
- }
230
- }
231
-
232
- pub fn is_miner ( & self ) -> bool {
233
- match self {
234
- Self :: Miner ( ..) => true ,
235
- _ => false ,
236
- }
218
+ self . join_handle
237
219
}
238
220
221
+ /// Set the miner-abort flag to true, which causes the miner thread to exit if it is blocked.
239
222
pub fn set_abort_flag ( & self ) {
240
- match self {
241
- Self :: Miner ( _, abort_flag) => {
242
- ( * abort_flag) . store ( true , Ordering :: SeqCst ) ;
243
- }
244
- Self :: TenureStop ( _, abort_flag) => {
245
- ( * abort_flag) . store ( true , Ordering :: SeqCst ) ;
246
- }
247
- }
223
+ self . abort_flag . store ( true , Ordering :: SeqCst ) ;
248
224
}
249
225
226
+ /// Get an Arc to the abort flag, so another thread can set it.
250
227
pub fn get_abort_flag ( & self ) -> Arc < AtomicBool > {
251
- match self {
252
- Self :: Miner ( _, abort_flag) => abort_flag. clone ( ) ,
253
- Self :: TenureStop ( _, abort_flag) => abort_flag. clone ( ) ,
254
- }
228
+ self . abort_flag . clone ( )
255
229
}
256
230
231
+ /// Stop the inner miner thread.
232
+ /// Blocks the miner, and sets the abort flag so that a blocked miner will error out.
257
233
pub fn stop ( self , globals : & Globals ) -> Result < ( ) , NakamotoNodeError > {
258
234
let my_id = thread:: current ( ) . id ( ) ;
259
235
let prior_thread_id = self . inner_thread ( ) . id ( ) ;
@@ -1181,10 +1157,8 @@ impl RelayerThread {
1181
1157
"Relayer: started tenure thread ID {:?}" ,
1182
1158
new_miner_handle. thread( ) . id( )
1183
1159
) ;
1184
- self . miner_thread . replace ( MinerStopHandle :: new_miner (
1185
- new_miner_handle,
1186
- miner_abort_flag,
1187
- ) ) ;
1160
+ self . miner_thread
1161
+ . replace ( MinerStopHandle :: new ( new_miner_handle, miner_abort_flag) ) ;
1188
1162
self . miner_thread_burn_view . replace ( burn_tip) ;
1189
1163
Ok ( ( ) )
1190
1164
}
@@ -1214,7 +1188,7 @@ impl RelayerThread {
1214
1188
} ) ?;
1215
1189
1216
1190
self . miner_thread
1217
- . replace ( MinerStopHandle :: new_tenure_stop ( stop_handle, abort_flag) ) ;
1191
+ . replace ( MinerStopHandle :: new ( stop_handle, abort_flag) ) ;
1218
1192
debug ! ( "Relayer: stopped tenure thread ID {id:?}" ) ;
1219
1193
Ok ( ( ) )
1220
1194
}
0 commit comments