@@ -6,7 +6,6 @@ use alloc::vec::Vec;
6
6
use crate :: lsps0:: ser:: LSPSMessage ;
7
7
use crate :: sync:: Mutex ;
8
8
9
- use core:: sync:: atomic:: { AtomicBool , Ordering } ;
10
9
use lightning:: util:: wakers:: { Future , Notifier } ;
11
10
12
11
use bitcoin:: secp256k1:: PublicKey ;
@@ -17,33 +16,29 @@ use bitcoin::secp256k1::PublicKey;
17
16
pub struct MessageQueue {
18
17
queue : Mutex < VecDeque < ( PublicKey , LSPSMessage ) > > ,
19
18
pending_msgs_notifier : Notifier ,
20
- needs_processing : AtomicBool ,
21
19
}
22
20
23
21
impl MessageQueue {
24
22
pub ( crate ) fn new ( ) -> Self {
25
23
let queue = Mutex :: new ( VecDeque :: new ( ) ) ;
26
24
let pending_msgs_notifier = Notifier :: new ( ) ;
27
- let needs_processing = AtomicBool :: new ( false ) ;
28
- Self { queue, pending_msgs_notifier, needs_processing }
25
+ Self { queue, pending_msgs_notifier }
29
26
}
30
27
31
28
pub ( crate ) fn get_and_clear_pending_msgs ( & self ) -> Vec < ( PublicKey , LSPSMessage ) > {
32
- self . needs_processing . store ( false , Ordering :: Relaxed ) ;
33
29
self . queue . lock ( ) . unwrap ( ) . drain ( ..) . collect ( )
34
30
}
35
31
36
32
pub ( crate ) fn get_pending_msgs_future ( & self ) -> Future {
37
33
self . pending_msgs_notifier . get_future ( )
38
34
}
39
35
40
- // Returns a [`MessageQueueNotifierGuard`] that will call `process_msgs_callback` when dropped.
41
36
pub ( crate ) fn notifier ( & self ) -> MessageQueueNotifierGuard {
42
37
MessageQueueNotifierGuard { msg_queue : self , buffer : VecDeque :: new ( ) }
43
38
}
44
39
}
45
40
46
- // A guard type that will notify about new messages when dropped.
41
+ // A guard type that will process buffered messages and wake the background processor when dropped.
47
42
#[ must_use]
48
43
pub ( crate ) struct MessageQueueNotifierGuard < ' a > {
49
44
msg_queue : & ' a MessageQueue ,
0 commit comments