Skip to content

Commit

Permalink
Rollup merge of #65416 - spastorino:minor-sync-changes, r=Mark-Simula…
Browse files Browse the repository at this point in the history
…crum

Minor sync changes

r? @Mark-Simulacrum
  • Loading branch information
tmandry authored Oct 15, 2019
2 parents ae5093d + b9bc431 commit 9422feb
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions src/librustc_data_structures/sync.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This module defines types which are thread safe if cfg!(parallel_compiler) is true.
//!
//! `Lrc` is an alias of either Rc or Arc.
//! `Lrc` is an alias of `Arc` if cfg!(parallel_compiler) is true, `Rc` otherwise.
//!
//! `Lock` is a mutex.
//! It internally uses `parking_lot::Mutex` if cfg!(parallel_compiler) is true,
Expand All @@ -12,7 +12,7 @@
//!
//! `MTLock` is a mutex which disappears if cfg!(parallel_compiler) is false.
//!
//! `MTRef` is a immutable reference if cfg!(parallel_compiler), and an mutable reference otherwise.
//! `MTRef` is an immutable reference if cfg!(parallel_compiler), and a mutable reference otherwise.
//!
//! `rustc_erase_owner!` erases a OwningRef owner into Erased or Erased + Send + Sync
//! depending on the value of cfg!(parallel_compiler).
Expand All @@ -23,29 +23,6 @@ use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
use crate::owning_ref::{Erased, OwningRef};

pub fn serial_join<A, B, RA, RB>(oper_a: A, oper_b: B) -> (RA, RB)
where A: FnOnce() -> RA,
B: FnOnce() -> RB
{
(oper_a(), oper_b())
}

pub struct SerialScope;

impl SerialScope {
pub fn spawn<F>(&self, f: F)
where F: FnOnce(&SerialScope)
{
f(self)
}
}

pub fn serial_scope<F, R>(f: F) -> R
where F: FnOnce(&SerialScope) -> R
{
f(&SerialScope)
}

pub use std::sync::atomic::Ordering::SeqCst;
pub use std::sync::atomic::Ordering;

Expand Down Expand Up @@ -176,8 +153,28 @@ cfg_if! {
pub type AtomicU32 = Atomic<u32>;
pub type AtomicU64 = Atomic<u64>;

pub use self::serial_join as join;
pub use self::serial_scope as scope;
pub fn join<A, B, RA, RB>(oper_a: A, oper_b: B) -> (RA, RB)
where A: FnOnce() -> RA,
B: FnOnce() -> RB
{
(oper_a(), oper_b())
}

pub struct SerialScope;

impl SerialScope {
pub fn spawn<F>(&self, f: F)
where F: FnOnce(&SerialScope)
{
f(self)
}
}

pub fn scope<F, R>(f: F) -> R
where F: FnOnce(&SerialScope) -> R
{
f(&SerialScope)
}

#[macro_export]
macro_rules! parallel {
Expand Down

0 comments on commit 9422feb

Please sign in to comment.