Skip to content

Commit c6d4ff0

Browse files
committed
Modify sys_common::RWLock to use parking_lot
1 parent a068a8f commit c6d4ff0

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/libstd/sys_common/rwlock.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,30 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use sys::rwlock as imp;
11+
use super::parking_lot::raw_rwlock::RawRwLock;
1212

1313
/// An OS-based reader-writer lock.
1414
///
1515
/// This structure is entirely unsafe and serves as the lowest layer of a
1616
/// cross-platform binding of system rwlocks. It is recommended to use the
1717
/// safer types at the top level of this crate instead of this type.
18-
pub struct RWLock(imp::RWLock);
18+
pub struct RWLock(RawRwLock);
1919

2020
impl RWLock {
2121
/// Creates a new reader-writer lock for use.
2222
///
2323
/// Behavior is undefined if the reader-writer lock is moved after it is
2424
/// first used with any of the functions below.
2525
#[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) }
2727

2828
/// Acquires shared access to the underlying lock, blocking the current
2929
/// thread to do so.
3030
///
3131
/// Behavior is undefined if the rwlock has been moved between this and any
3232
/// previous method call.
3333
#[inline]
34-
pub unsafe fn read(&self) { self.0.read() }
34+
pub unsafe fn read(&self) { self.0.lock_shared() }
3535

3636
/// Attempts to acquire shared access to this lock, returning whether it
3737
/// succeeded or not.
@@ -41,15 +41,15 @@ impl RWLock {
4141
/// Behavior is undefined if the rwlock has been moved between this and any
4242
/// previous method call.
4343
#[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() }
4545

4646
/// Acquires write access to the underlying lock, blocking the current thread
4747
/// to do so.
4848
///
4949
/// Behavior is undefined if the rwlock has been moved between this and any
5050
/// previous method call.
5151
#[inline]
52-
pub unsafe fn write(&self) { self.0.write() }
52+
pub unsafe fn write(&self) { self.0.lock_exclusive() }
5353

5454
/// Attempts to acquire exclusive access to this lock, returning whether it
5555
/// succeeded or not.
@@ -59,25 +59,25 @@ impl RWLock {
5959
/// Behavior is undefined if the rwlock has been moved between this and any
6060
/// previous method call.
6161
#[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() }
6363

6464
/// Unlocks previously acquired shared access to this lock.
6565
///
6666
/// Behavior is undefined if the current thread does not have shared access.
6767
#[inline]
68-
pub unsafe fn read_unlock(&self) { self.0.read_unlock() }
68+
pub unsafe fn read_unlock(&self) { self.0.unlock_shared() }
6969

7070
/// Unlocks previously acquired exclusive access to this lock.
7171
///
7272
/// Behavior is undefined if the current thread does not currently have
7373
/// exclusive access.
7474
#[inline]
75-
pub unsafe fn write_unlock(&self) { self.0.write_unlock() }
75+
pub unsafe fn write_unlock(&self) { self.0.unlock_exclusive() }
7676

7777
/// Destroys OS-related resources with this RWLock.
7878
///
7979
/// Behavior is undefined if there are any currently active users of this
8080
/// lock.
8181
#[inline]
82-
pub unsafe fn destroy(&self) { self.0.destroy() }
82+
pub unsafe fn destroy(&self) { }
8383
}

0 commit comments

Comments
 (0)