8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use sys :: rwlock as imp ;
11
+ use super :: parking_lot :: raw_rwlock :: RawRwLock ;
12
12
13
13
/// An OS-based reader-writer lock.
14
14
///
15
15
/// This structure is entirely unsafe and serves as the lowest layer of a
16
16
/// cross-platform binding of system rwlocks. It is recommended to use the
17
17
/// safer types at the top level of this crate instead of this type.
18
- pub struct RWLock ( imp :: RWLock ) ;
18
+ pub struct RWLock ( RawRwLock ) ;
19
19
20
20
impl RWLock {
21
21
/// Creates a new reader-writer lock for use.
22
22
///
23
23
/// Behavior is undefined if the reader-writer lock is moved after it is
24
24
/// first used with any of the functions below.
25
25
#[ unstable( feature = "sys_internals" , issue = "0" ) ] // FIXME: min_const_fn
26
- pub const fn new ( ) -> RWLock { RWLock ( imp :: RWLock :: new ( ) ) }
26
+ pub const fn new ( ) -> RWLock { RWLock ( RawRwLock :: INIT ) }
27
27
28
28
/// Acquires shared access to the underlying lock, blocking the current
29
29
/// thread to do so.
30
30
///
31
31
/// Behavior is undefined if the rwlock has been moved between this and any
32
32
/// previous method call.
33
33
#[ inline]
34
- pub unsafe fn read ( & self ) { self . 0 . read ( ) }
34
+ pub unsafe fn read ( & self ) { self . 0 . lock_shared ( ) }
35
35
36
36
/// Attempts to acquire shared access to this lock, returning whether it
37
37
/// succeeded or not.
@@ -41,15 +41,15 @@ impl RWLock {
41
41
/// Behavior is undefined if the rwlock has been moved between this and any
42
42
/// previous method call.
43
43
#[ inline]
44
- pub unsafe fn try_read ( & self ) -> bool { self . 0 . try_read ( ) }
44
+ pub unsafe fn try_read ( & self ) -> bool { self . 0 . try_lock_shared ( ) }
45
45
46
46
/// Acquires write access to the underlying lock, blocking the current thread
47
47
/// to do so.
48
48
///
49
49
/// Behavior is undefined if the rwlock has been moved between this and any
50
50
/// previous method call.
51
51
#[ inline]
52
- pub unsafe fn write ( & self ) { self . 0 . write ( ) }
52
+ pub unsafe fn write ( & self ) { self . 0 . lock_exclusive ( ) }
53
53
54
54
/// Attempts to acquire exclusive access to this lock, returning whether it
55
55
/// succeeded or not.
@@ -59,25 +59,25 @@ impl RWLock {
59
59
/// Behavior is undefined if the rwlock has been moved between this and any
60
60
/// previous method call.
61
61
#[ inline]
62
- pub unsafe fn try_write ( & self ) -> bool { self . 0 . try_write ( ) }
62
+ pub unsafe fn try_write ( & self ) -> bool { self . 0 . try_lock_exclusive ( ) }
63
63
64
64
/// Unlocks previously acquired shared access to this lock.
65
65
///
66
66
/// Behavior is undefined if the current thread does not have shared access.
67
67
#[ inline]
68
- pub unsafe fn read_unlock ( & self ) { self . 0 . read_unlock ( ) }
68
+ pub unsafe fn read_unlock ( & self ) { self . 0 . unlock_shared ( ) }
69
69
70
70
/// Unlocks previously acquired exclusive access to this lock.
71
71
///
72
72
/// Behavior is undefined if the current thread does not currently have
73
73
/// exclusive access.
74
74
#[ inline]
75
- pub unsafe fn write_unlock ( & self ) { self . 0 . write_unlock ( ) }
75
+ pub unsafe fn write_unlock ( & self ) { self . 0 . unlock_exclusive ( ) }
76
76
77
77
/// Destroys OS-related resources with this RWLock.
78
78
///
79
79
/// Behavior is undefined if there are any currently active users of this
80
80
/// lock.
81
81
#[ inline]
82
- pub unsafe fn destroy ( & self ) { self . 0 . destroy ( ) }
82
+ pub unsafe fn destroy ( & self ) { }
83
83
}
0 commit comments