@@ -26,12 +26,11 @@ use alloc::boxed::Box;
26
26
use core:: cmp;
27
27
use core:: int;
28
28
use rustrt:: local:: Local ;
29
- use rustrt:: mutex:: NativeMutex ;
30
29
use rustrt:: task:: { Task , BlockedTask } ;
31
30
use rustrt:: thread:: Thread ;
32
31
33
- use sync:: atomic;
34
- use sync :: mpsc_queue as mpsc;
32
+ use sync:: { atomic, Mutex , MutexGuard } ;
33
+ use comm :: mpsc_queue as mpsc;
35
34
36
35
const DISCONNECTED : int = int:: MIN ;
37
36
const FUDGE : int = 1024 ;
@@ -56,7 +55,7 @@ pub struct Packet<T> {
56
55
57
56
// this lock protects various portions of this implementation during
58
57
// select()
59
- select_lock : NativeMutex ,
58
+ select_lock : Mutex < ( ) > ,
60
59
}
61
60
62
61
pub enum Failure {
@@ -76,7 +75,7 @@ impl<T: Send> Packet<T> {
76
75
channels : atomic:: AtomicInt :: new ( 2 ) ,
77
76
port_dropped : atomic:: AtomicBool :: new ( false ) ,
78
77
sender_drain : atomic:: AtomicInt :: new ( 0 ) ,
79
- select_lock : unsafe { NativeMutex :: new ( ) } ,
78
+ select_lock : Mutex :: new ( ( ) ) ,
80
79
} ;
81
80
return p;
82
81
}
@@ -86,16 +85,18 @@ impl<T: Send> Packet<T> {
86
85
// In other case mutex data will be duplicated while cloning
87
86
// and that could cause problems on platforms where it is
88
87
// represented by opaque data structure
89
- pub fn postinit_lock ( & mut self ) {
90
- unsafe { self . select_lock . lock_noguard ( ) }
88
+ pub fn postinit_lock ( & self ) -> MutexGuard < ( ) > {
89
+ self . select_lock . lock ( )
91
90
}
92
91
93
92
// This function is used at the creation of a shared packet to inherit a
94
93
// previously blocked task. This is done to prevent spurious wakeups of
95
94
// tasks in select().
96
95
//
97
96
// This can only be called at channel-creation time
98
- pub fn inherit_blocker ( & mut self , task : Option < BlockedTask > ) {
97
+ pub fn inherit_blocker ( & mut self ,
98
+ task : Option < BlockedTask > ,
99
+ guard : MutexGuard < ( ) > ) {
99
100
match task {
100
101
Some ( task) => {
101
102
assert_eq ! ( self . cnt. load( atomic:: SeqCst ) , 0 ) ;
@@ -135,7 +136,7 @@ impl<T: Send> Packet<T> {
135
136
// interfere with this method. After we unlock this lock, we're
136
137
// signifying that we're done modifying self.cnt and self.to_wake and
137
138
// the port is ready for the world to continue using it.
138
- unsafe { self . select_lock . unlock_noguard ( ) }
139
+ drop ( guard ) ;
139
140
}
140
141
141
142
pub fn send ( & mut self , t : T ) -> Result < ( ) , T > {
@@ -441,7 +442,7 @@ impl<T: Send> Packet<T> {
441
442
// done with. Without this bounce, we can race with inherit_blocker
442
443
// about looking at and dealing with to_wake. Once we have acquired the
443
444
// lock, we are guaranteed that inherit_blocker is done.
444
- unsafe {
445
+ {
445
446
let _guard = self . select_lock . lock ( ) ;
446
447
}
447
448
0 commit comments