Skip to content

Commit

Permalink
Upgrade to Rust 2018
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Mar 4, 2019
1 parent 0b69116 commit 28bf1aa
Show file tree
Hide file tree
Showing 21 changed files with 127 additions and 143 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repository = "https://github.com/Amanieu/parking_lot"
readme = "README.md"
keywords = ["mutex", "condvar", "rwlock", "once", "thread"]
categories = ["concurrency"]
edition = "2018"

[dependencies]
parking_lot_core = { path = "core", version = "0.4" }
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license = "Apache-2.0/MIT"
repository = "https://github.com/Amanieu/parking_lot"
keywords = ["mutex", "condvar", "rwlock", "once", "thread"]
categories = ["concurrency"]
edition = "2018"

[dependencies]
smallvec = "0.6"
Expand Down
28 changes: 7 additions & 21 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,6 @@
feature(integer_atomics)
)]

extern crate rand;
extern crate smallvec;

#[cfg(feature = "deadlock_detection")]
extern crate backtrace;
#[cfg(feature = "deadlock_detection")]
extern crate petgraph;
#[cfg(feature = "deadlock_detection")]
extern crate thread_id;

#[cfg(unix)]
extern crate libc;

#[cfg(windows)]
extern crate winapi;

#[cfg(all(feature = "nightly", target_os = "linux"))]
#[path = "thread_parker/linux.rs"]
mod thread_parker;
Expand All @@ -77,8 +61,10 @@ mod spinwait;
mod util;
mod word_lock;

pub use parking_lot::deadlock;
pub use parking_lot::{park, unpark_all, unpark_filter, unpark_one, unpark_requeue};
pub use parking_lot::{FilterOp, ParkResult, ParkToken, RequeueOp, UnparkResult, UnparkToken};
pub use parking_lot::{DEFAULT_PARK_TOKEN, DEFAULT_UNPARK_TOKEN};
pub use spinwait::SpinWait;
pub use self::parking_lot::deadlock;
pub use self::parking_lot::{park, unpark_all, unpark_filter, unpark_one, unpark_requeue};
pub use self::parking_lot::{
FilterOp, ParkResult, ParkToken, RequeueOp, UnparkResult, UnparkToken,
};
pub use self::parking_lot::{DEFAULT_PARK_TOKEN, DEFAULT_UNPARK_TOKEN};
pub use self::spinwait::SpinWait;
8 changes: 4 additions & 4 deletions core/src/parking_lot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use crate::thread_parker::ThreadParker;
use crate::util::UncheckedOptionExt;
use crate::word_lock::WordLock;
use rand::rngs::SmallRng;
use rand::{FromEntropy, Rng};
use smallvec::SmallVec;
use std::cell::{Cell, UnsafeCell};
use std::ptr;
use std::sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
use std::time::{Duration, Instant};
use thread_parker::ThreadParker;
use util::UncheckedOptionExt;
use word_lock::WordLock;

static NUM_THREADS: AtomicUsize = AtomicUsize::new(0);
static HASHTABLE: AtomicPtr<HashTable> = AtomicPtr::new(ptr::null_mut());
Expand Down Expand Up @@ -1085,6 +1085,7 @@ pub mod deadlock {
#[cfg(feature = "deadlock_detection")]
mod deadlock_impl {
use super::{get_hashtable, lock_bucket, with_thread_data, ThreadData, NUM_THREADS};
use crate::word_lock::WordLock;
use backtrace::Backtrace;
use petgraph;
use petgraph::graphmap::DiGraphMap;
Expand All @@ -1093,7 +1094,6 @@ mod deadlock_impl {
use std::sync::atomic::Ordering;
use std::sync::mpsc;
use thread_id;
use word_lock::WordLock;

/// Representation of a deadlocked thread
pub struct DeadlockedThread {
Expand Down
2 changes: 1 addition & 1 deletion core/src/spinwait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use crate::thread_parker;
use std::sync::atomic::spin_loop_hint;
use thread_parker;

// Wastes some CPU time for the given number of iterations,
// using a hint to indicate to the CPU that we are spinning.
Expand Down
1 change: 0 additions & 1 deletion core/src/thread_parker/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use std::ptr;
use std::sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
use std::time::Instant;
use winapi;

mod keyed_event;
mod waitaddress;
Expand Down
4 changes: 2 additions & 2 deletions core/src/word_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use spinwait::SpinWait;
use crate::spinwait::SpinWait;
use crate::thread_parker::ThreadParker;
use std::cell::Cell;
use std::mem;
use std::ptr;
use std::sync::atomic::{fence, AtomicUsize, Ordering};
use thread_parker::ThreadParker;

struct ThreadData {
parker: ThreadParker,
Expand Down
1 change: 1 addition & 0 deletions lock_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license = "Apache-2.0/MIT"
repository = "https://github.com/Amanieu/parking_lot"
keywords = ["mutex", "rwlock", "lock", "no_std"]
categories = ["concurrency", "no-std"]
edition = "2018"

[dependencies]
scopeguard = { version = "1.0", default-features = false }
Expand Down
9 changes: 3 additions & 6 deletions lock_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,17 @@
#[macro_use]
extern crate scopeguard;

#[cfg(feature = "owning_ref")]
extern crate owning_ref;

/// Marker type which indicates that the Guard type for a lock is `Send`.
pub struct GuardSend(());

/// Marker type which indicates that the Guard type for a lock is not `Send`.
pub struct GuardNoSend(*mut ());

mod mutex;
pub use mutex::*;
pub use crate::mutex::*;

mod remutex;
pub use remutex::*;
pub use crate::remutex::*;

mod rwlock;
pub use rwlock::*;
pub use crate::rwlock::*;
26 changes: 13 additions & 13 deletions lock_api/src/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<R: RawMutex, T> Mutex<R, T> {

impl<R: RawMutex, T: ?Sized> Mutex<R, T> {
#[inline]
fn guard(&self) -> MutexGuard<R, T> {
fn guard(&self) -> MutexGuard<'_, R, T> {
MutexGuard {
mutex: self,
marker: PhantomData,
Expand All @@ -144,7 +144,7 @@ impl<R: RawMutex, T: ?Sized> Mutex<R, T> {
/// Attempts to lock a mutex in the thread which already holds the lock will
/// result in a deadlock.
#[inline]
pub fn lock(&self) -> MutexGuard<R, T> {
pub fn lock(&self) -> MutexGuard<'_, R, T> {
self.raw.lock();
self.guard()
}
Expand All @@ -157,7 +157,7 @@ impl<R: RawMutex, T: ?Sized> Mutex<R, T> {
///
/// This function does not block.
#[inline]
pub fn try_lock(&self) -> Option<MutexGuard<R, T>> {
pub fn try_lock(&self) -> Option<MutexGuard<'_, R, T>> {
if self.raw.try_lock() {
Some(self.guard())
} else {
Expand Down Expand Up @@ -230,7 +230,7 @@ impl<R: RawMutexTimed, T: ?Sized> Mutex<R, T> {
/// `None` is returned. Otherwise, an RAII guard is returned. The lock will
/// be unlocked when the guard is dropped.
#[inline]
pub fn try_lock_for(&self, timeout: R::Duration) -> Option<MutexGuard<R, T>> {
pub fn try_lock_for(&self, timeout: R::Duration) -> Option<MutexGuard<'_, R, T>> {
if self.raw.try_lock_for(timeout) {
Some(self.guard())
} else {
Expand All @@ -244,7 +244,7 @@ impl<R: RawMutexTimed, T: ?Sized> Mutex<R, T> {
/// `None` is returned. Otherwise, an RAII guard is returned. The lock will
/// be unlocked when the guard is dropped.
#[inline]
pub fn try_lock_until(&self, timeout: R::Instant) -> Option<MutexGuard<R, T>> {
pub fn try_lock_until(&self, timeout: R::Instant) -> Option<MutexGuard<'_, R, T>> {
if self.raw.try_lock_until(timeout) {
Some(self.guard())
} else {
Expand All @@ -268,13 +268,13 @@ impl<R: RawMutex, T> From<T> for Mutex<R, T> {
}

impl<R: RawMutex, T: ?Sized + fmt::Debug> fmt::Debug for Mutex<R, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.try_lock() {
Some(guard) => f.debug_struct("Mutex").field("data", &&*guard).finish(),
None => {
struct LockedPlaceholder;
impl fmt::Debug for LockedPlaceholder {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("<locked>")
}
}
Expand All @@ -293,7 +293,7 @@ impl<R: RawMutex, T: ?Sized + fmt::Debug> fmt::Debug for Mutex<R, T> {
/// The data protected by the mutex can be accessed through this guard via its
/// `Deref` and `DerefMut` implementations.
#[must_use = "if unused the Mutex will immediately unlock"]
pub struct MutexGuard<'a, R: RawMutex + 'a, T: ?Sized + 'a> {
pub struct MutexGuard<'a, R: RawMutex, T: ?Sized> {
mutex: &'a Mutex<R, T>,
marker: PhantomData<(&'a mut T, R::GuardMarker)>,
}
Expand Down Expand Up @@ -440,13 +440,13 @@ impl<'a, R: RawMutex + 'a, T: ?Sized + 'a> Drop for MutexGuard<'a, R, T> {
}

impl<'a, R: RawMutex + 'a, T: fmt::Debug + ?Sized + 'a> fmt::Debug for MutexGuard<'a, R, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&**self, f)
}
}

impl<'a, R: RawMutex + 'a, T: fmt::Display + ?Sized + 'a> fmt::Display for MutexGuard<'a, R, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
(**self).fmt(f)
}
}
Expand All @@ -462,7 +462,7 @@ unsafe impl<'a, R: RawMutex + 'a, T: ?Sized + 'a> StableAddress for MutexGuard<'
/// could introduce soundness issues if the locked object is modified by another
/// thread.
#[must_use = "if unused the Mutex will immediately unlock"]
pub struct MappedMutexGuard<'a, R: RawMutex + 'a, T: ?Sized + 'a> {
pub struct MappedMutexGuard<'a, R: RawMutex, T: ?Sized> {
raw: &'a R,
data: *mut T,
marker: PhantomData<&'a mut T>,
Expand Down Expand Up @@ -572,15 +572,15 @@ impl<'a, R: RawMutex + 'a, T: ?Sized + 'a> Drop for MappedMutexGuard<'a, R, T> {
}

impl<'a, R: RawMutex + 'a, T: fmt::Debug + ?Sized + 'a> fmt::Debug for MappedMutexGuard<'a, R, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&**self, f)
}
}

impl<'a, R: RawMutex + 'a, T: fmt::Display + ?Sized + 'a> fmt::Display
for MappedMutexGuard<'a, R, T>
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
(**self).fmt(f)
}
}
Expand Down
Loading

0 comments on commit 28bf1aa

Please sign in to comment.