@@ -70,8 +70,8 @@ use std::ops::{Deref, DerefMut};
70
70
use std:: panic:: { RefUnwindSafe , UnwindSafe } ;
71
71
use std:: pin:: Pin ;
72
72
use std:: ptr:: { self , NonNull } ;
73
- use std:: sync:: atomic:: { self , AtomicBool , AtomicPtr , AtomicUsize , Ordering } ;
74
- use std:: sync:: Arc ;
73
+ use std:: sync:: atomic:: { self , AtomicPtr , AtomicUsize , Ordering } ;
74
+ use std:: sync:: { Arc , Mutex , MutexGuard } ;
75
75
use std:: task:: { Context , Poll , Waker } ;
76
76
use std:: thread:: { self , Thread } ;
77
77
use std:: time:: { Duration , Instant } ;
@@ -85,7 +85,7 @@ struct Inner {
85
85
notified : AtomicUsize ,
86
86
87
87
/// A linked list holding registered listeners.
88
- list : Spinlock < List > ,
88
+ list : Mutex < List > ,
89
89
90
90
/// A single cached list entry to avoid allocations on the fast path of the insertion.
91
91
cache : UnsafeCell < Entry > ,
@@ -96,7 +96,7 @@ impl Inner {
96
96
fn lock ( & self ) -> ListGuard < ' _ > {
97
97
ListGuard {
98
98
inner : self ,
99
- guard : self . list . lock ( ) ,
99
+ guard : self . list . lock ( ) . unwrap ( ) ,
100
100
}
101
101
}
102
102
@@ -374,7 +374,7 @@ impl Event {
374
374
// Allocate on the heap.
375
375
let new = Arc :: new ( Inner {
376
376
notified : AtomicUsize :: new ( usize:: MAX ) ,
377
- list : Spinlock :: new ( List {
377
+ list : std :: sync :: Mutex :: new ( List {
378
378
head : None ,
379
379
tail : None ,
380
380
start : None ,
@@ -722,7 +722,7 @@ struct ListGuard<'a> {
722
722
inner : & ' a Inner ,
723
723
724
724
/// The actual guard that acquired the linked list.
725
- guard : SpinlockGuard < ' a , List > ,
725
+ guard : MutexGuard < ' a , List > ,
726
726
}
727
727
728
728
impl Drop for ListGuard < ' _ > {
@@ -984,52 +984,3 @@ fn full_fence() {
984
984
atomic:: fence ( Ordering :: SeqCst ) ;
985
985
}
986
986
}
987
-
988
- /// A simple spinlock.
989
- struct Spinlock < T > {
990
- flag : AtomicBool ,
991
- value : UnsafeCell < T > ,
992
- }
993
-
994
- impl < T > Spinlock < T > {
995
- /// Returns a new spinlock initialized with `value`.
996
- fn new ( value : T ) -> Spinlock < T > {
997
- Spinlock {
998
- flag : AtomicBool :: new ( false ) ,
999
- value : UnsafeCell :: new ( value) ,
1000
- }
1001
- }
1002
-
1003
- /// Locks the spinlock.
1004
- fn lock ( & self ) -> SpinlockGuard < ' _ , T > {
1005
- while self . flag . swap ( true , Ordering :: Acquire ) {
1006
- thread:: yield_now ( ) ;
1007
- }
1008
- SpinlockGuard { parent : self }
1009
- }
1010
- }
1011
-
1012
- /// A guard holding a spinlock locked.
1013
- struct SpinlockGuard < ' a , T > {
1014
- parent : & ' a Spinlock < T > ,
1015
- }
1016
-
1017
- impl < T > Drop for SpinlockGuard < ' _ , T > {
1018
- fn drop ( & mut self ) {
1019
- self . parent . flag . store ( false , Ordering :: Release ) ;
1020
- }
1021
- }
1022
-
1023
- impl < T > Deref for SpinlockGuard < ' _ , T > {
1024
- type Target = T ;
1025
-
1026
- fn deref ( & self ) -> & T {
1027
- unsafe { & * self . parent . value . get ( ) }
1028
- }
1029
- }
1030
-
1031
- impl < T > DerefMut for SpinlockGuard < ' _ , T > {
1032
- fn deref_mut ( & mut self ) -> & mut T {
1033
- unsafe { & mut * self . parent . value . get ( ) }
1034
- }
1035
- }
0 commit comments