Remove pre 1.36 backwards compatibility code

This commit is contained in:
Linus Färnstrand
2019-11-05 21:37:32 +01:00
parent a7f115d348
commit 84c703395b
11 changed files with 23 additions and 98 deletions
-7
View File
@@ -1,7 +0,0 @@
fn main() {
let cfg = autocfg::new();
if cfg.probe_rustc_version(1, 34) {
println!("cargo:rustc-cfg=has_sized_atomics");
println!("cargo:rustc-cfg=has_checked_instant");
}
}
-9
View File
@@ -1,9 +0,0 @@
fn main() {
let cfg = autocfg::new();
if cfg.probe_rustc_version(1, 34) {
println!("cargo:rustc-cfg=has_sized_atomics");
}
if cfg.probe_rustc_version(1, 36) {
println!("cargo:rustc-cfg=has_maybe_uninit");
}
}
-1
View File
@@ -56,7 +56,6 @@
feature(thread_local, checked_duration_since)
)]
mod maybe_uninit;
mod parking_lot;
mod spinwait;
mod thread_parker;
-41
View File
@@ -1,41 +0,0 @@
//! This module contains a re-export or vendored version of `core::mem::MaybeUninit` depending
//! on which Rust version it's compiled for.
//!
//! Remove this module and use `core::mem::MaybeUninit` directly when dropping support for <1.36
#![allow(dead_code)]
#[cfg(has_maybe_uninit)]
pub use core::mem::MaybeUninit;
#[cfg(not(has_maybe_uninit))]
use core::mem::ManuallyDrop;
/// Copied from `core::mem::MaybeUninit` to support Rust older than 1.36
#[cfg(not(has_maybe_uninit))]
pub union MaybeUninit<T: Copy> {
uninit: (),
value: ManuallyDrop<T>,
}
#[cfg(not(has_maybe_uninit))]
impl<T: Copy> MaybeUninit<T> {
#[inline]
pub fn uninit() -> MaybeUninit<T> {
MaybeUninit { uninit: () }
}
#[inline]
pub fn as_ptr(&self) -> *const T {
unsafe { &*self.value as *const T }
}
#[inline]
pub fn as_mut_ptr(&mut self) -> *mut T {
unsafe { &mut *self.value as *mut T }
}
#[inline]
pub unsafe fn assume_init(self) -> T {
ManuallyDrop::into_inner(self.value)
}
}
+1 -2
View File
@@ -5,11 +5,10 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
use crate::maybe_uninit::MaybeUninit;
use cloudabi as abi;
use core::{
cell::Cell,
mem,
mem::{self, MaybeUninit},
sync::atomic::{AtomicU32, Ordering},
};
use std::{convert::TryFrom, thread, time::Instant};
+2 -2
View File
@@ -51,7 +51,7 @@ pub trait UnparkHandleT {
}
cfg_if! {
if #[cfg(all(has_sized_atomics, any(target_os = "linux", target_os = "android")))] {
if #[cfg(any(target_os = "linux", target_os = "android"))] {
#[path = "linux.rs"]
mod imp;
} else if #[cfg(unix)] {
@@ -60,7 +60,7 @@ cfg_if! {
} else if #[cfg(windows)] {
#[path = "windows/mod.rs"]
mod imp;
} else if #[cfg(all(has_sized_atomics, target_os = "redox"))] {
} else if #[cfg(target_os = "redox")] {
#[path = "redox.rs"]
mod imp;
} else if #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] {
+4 -2
View File
@@ -5,10 +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 crate::maybe_uninit::MaybeUninit;
use core::cell::{Cell, UnsafeCell};
#[cfg(any(target_os = "macos", target_os = "ios"))]
use core::ptr;
use core::{
cell::{Cell, UnsafeCell},
mem::MaybeUninit,
};
use libc;
use std::{
thread,
@@ -5,8 +5,10 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
use crate::maybe_uninit::MaybeUninit;
use core::{mem, ptr};
use core::{
mem::{self, MaybeUninit},
ptr,
};
use std::{
sync::atomic::{AtomicUsize, Ordering},
time::Instant,
+5 -14
View File
@@ -6,25 +6,16 @@
// copied, modified, or distributed except according to those terms.
use crate::util::UncheckedOptionExt;
#[cfg(has_sized_atomics)]
use core::sync::atomic::AtomicU8;
#[cfg(not(has_sized_atomics))]
use core::sync::atomic::AtomicUsize as AtomicU8;
use core::{
fmt, mem,
sync::atomic::{fence, Ordering},
sync::atomic::{fence, AtomicU8, Ordering},
};
use parking_lot_core::{self, SpinWait, DEFAULT_PARK_TOKEN, DEFAULT_UNPARK_TOKEN};
#[cfg(has_sized_atomics)]
type U8 = u8;
#[cfg(not(has_sized_atomics))]
type U8 = usize;
const DONE_BIT: U8 = 1;
const POISON_BIT: U8 = 2;
const LOCKED_BIT: U8 = 4;
const PARKED_BIT: U8 = 8;
const DONE_BIT: u8 = 1;
const POISON_BIT: u8 = 2;
const LOCKED_BIT: u8 = 4;
const PARKED_BIT: u8 = 8;
/// Current state of a `Once`.
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
+6 -12
View File
@@ -6,20 +6,14 @@
// copied, modified, or distributed except according to those terms.
use crate::{deadlock, util};
#[cfg(has_sized_atomics)]
use core::sync::atomic::AtomicU8;
#[cfg(not(has_sized_atomics))]
use core::sync::atomic::AtomicUsize as AtomicU8;
use core::{sync::atomic::Ordering, time::Duration};
use core::{
sync::atomic::{AtomicU8, Ordering},
time::Duration,
};
use lock_api::{GuardNoSend, RawMutex as RawMutex_};
use parking_lot_core::{self, ParkResult, SpinWait, UnparkResult, UnparkToken, DEFAULT_PARK_TOKEN};
use std::time::Instant;
#[cfg(has_sized_atomics)]
type U8 = u8;
#[cfg(not(has_sized_atomics))]
type U8 = usize;
// UnparkToken used to indicate that that the target thread should attempt to
// lock the mutex again as soon as it is unparked.
pub(crate) const TOKEN_NORMAL: UnparkToken = UnparkToken(0);
@@ -29,10 +23,10 @@ pub(crate) const TOKEN_NORMAL: UnparkToken = UnparkToken(0);
pub(crate) const TOKEN_HANDOFF: UnparkToken = UnparkToken(1);
/// This bit is set in the `state` of a `RawMutex` when that mutex is locked by some thread.
const LOCKED_BIT: U8 = 0b01;
const LOCKED_BIT: u8 = 0b01;
/// This bit is set in the `state` of a `RawMutex` just before parking a thread. A thread is being
/// parked if it wants to lock the mutex, but it is currently being held by some other thread.
const PARKED_BIT: U8 = 0b10;
const PARKED_BIT: u8 = 0b10;
/// Raw mutex type backed by the parking lot.
pub struct RawMutex {
+1 -6
View File
@@ -34,10 +34,5 @@ unsafe fn unreachable() -> ! {
#[inline]
pub fn to_deadline(timeout: Duration) -> Option<Instant> {
#[cfg(has_checked_instant)]
let deadline = Instant::now().checked_add(timeout);
#[cfg(not(has_checked_instant))]
let deadline = Some(Instant::now() + timeout);
deadline
Instant::now().checked_add(timeout)
}