Skip to content

Commit

Permalink
Make it possible to disable parallel feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Zakarum committed Oct 18, 2018
1 parent faa384b commit 97a74c8
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 13 deletions.
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ travis-ci = { repository = "slide-rs/specs" }
crossbeam = "0.4.1"
derivative = "1"
fnv = "1.0"
hibitset = { version = "0.5.2", features = ["parallel"] }
hibitset = { version = "0.5.2", default-features = false }
log = "0.4"
mopa = "0.2"
shred = "0.7.0"
shred = { version = "0.7.0", default-features = false }
shrev = "1.0.0"
shred-derive = "0.5.0"
tuple_utils = "0.2"
rayon = "1.0.0"
rayon = { version = "1.0.0", optional = true }
nonzero_signed = "1.0.1"

futures = { version = "0.1", optional = true }
Expand All @@ -41,6 +41,8 @@ serde = { version = "1.0", optional = true, features = ["serde_derive"] }
rudy = { version = "0.1", optional = true }

[features]
default = ["parallel"]
parallel = ["rayon", "shred/parallel", "hibitset/parallel"]
common = ["futures"]
nightly = ["shred/nightly"]

Expand Down
5 changes: 4 additions & 1 deletion src/bitset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use hibitset::{AtomicBitSet, BitSet, BitSetAnd, BitSetLike, BitSetNot, BitSetOr, BitSetXor};

use join::{Join, ParJoin};
use join::Join;
#[cfg(feature = "parallel")]
use join::ParJoin;
use world::Index;

macro_rules! define_bit_join {
Expand All @@ -25,6 +27,7 @@ macro_rules! define_bit_join {
}
}

#[cfg(feature = "parallel")]
unsafe impl<$( $lifetime, )* $( $arg ),*> ParJoin for $bitset
where $( $arg: BitSetLike ),*
{ }
Expand Down
20 changes: 19 additions & 1 deletion src/join.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
//! Joining of components for iteration over entities with specific components.

use std;
#[cfg(feature = "parallel")]
use std::cell::UnsafeCell;

use hibitset::{BitIter, BitProducer, BitSetAll, BitSetAnd, BitSetLike};
use hibitset::{BitIter, BitSetAll, BitSetAnd, BitSetLike};

#[cfg(feature = "parallel")]
use hibitset::BitProducer;

#[cfg(feature = "parallel")]
use rayon::iter::plumbing::{bridge_unindexed, Folder, UnindexedConsumer, UnindexedProducer};

#[cfg(feature = "parallel")]
use rayon::iter::ParallelIterator;
use std::ops::{Deref, DerefMut};
use tuple_utils::Split;
Expand Down Expand Up @@ -241,6 +249,7 @@ pub trait Join {
/// The purpose of the `ParJoin` trait is to provide a way
/// to access multiple storages in parallel at the same time with
/// the merged bit set.
#[cfg(feature = "parallel")]
pub unsafe trait ParJoin: Join {
/// Create a joined parallel iterator over the contents.
fn par_join(self) -> JoinParIter<Self>
Expand Down Expand Up @@ -399,9 +408,11 @@ impl<J: Join> std::iter::Iterator for JoinIter<J> {
}

/// `JoinParIter` is a `ParallelIterator` over a group of `Storages`.
#[cfg(feature = "parallel")]
#[must_use]
pub struct JoinParIter<J>(J);

#[cfg(feature = "parallel")]
impl<J> ParallelIterator for JoinParIter<J>
where
J: Join + Send,
Expand All @@ -424,6 +435,7 @@ where
}
}

#[cfg(feature = "parallel")]
struct JoinProducer<'a, J>
where
J: Join + Send,
Expand All @@ -435,6 +447,7 @@ where
values: &'a UnsafeCell<J::Value>,
}

#[cfg(feature = "parallel")]
impl<'a, J> JoinProducer<'a, J>
where
J: Join + Send,
Expand All @@ -447,6 +460,7 @@ where
}
}

#[cfg(feature = "parallel")]
unsafe impl<'a, J> Send for JoinProducer<'a, J>
where
J: Join + Send,
Expand All @@ -455,6 +469,7 @@ where
J::Mask: 'a + Send + Sync,
{}

#[cfg(feature = "parallel")]
impl<'a, J> UnindexedProducer for JoinProducer<'a, J>
where
J: Join + Send,
Expand Down Expand Up @@ -523,6 +538,7 @@ macro_rules! define_open {
unconstrained
}
}
#[cfg(feature = "parallel")]
unsafe impl<$($from,)*> ParJoin for ($($from),*,)
where $($from: ParJoin),*,
($(<$from as Join>::Mask,)*): BitAnd,
Expand Down Expand Up @@ -582,6 +598,7 @@ macro_rules! immutable_resource_join {
}
}

#[cfg(feature = "parallel")]
unsafe impl<'a, 'b, T> ParJoin for &'a $ty
where
&'a T: ParJoin,
Expand Down Expand Up @@ -616,6 +633,7 @@ macro_rules! mutable_resource_join {
}
}

#[cfg(feature = "parallel")]
unsafe impl<'a, 'b, T> ParJoin for &'a mut $ty
where
&'a mut T: ParJoin,
Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ extern crate hibitset;
extern crate log;
extern crate nonzero_signed;
extern crate mopa;
#[cfg(feature = "parallel")]
extern crate rayon;
extern crate shrev;
extern crate tuple_utils;
Expand Down Expand Up @@ -222,12 +223,14 @@ pub mod storage;
pub mod world;

pub use hibitset::BitSet;
pub use join::{Join, ParJoin};
pub use join::Join;
#[cfg(feature = "parallel")]
pub use join::ParJoin;
pub use shred::{Accessor, Dispatcher, DispatcherBuilder, Read, ReadExpect, Resources, RunNow,
StaticAccessor, System, SystemData, Write, WriteExpect};
pub use shrev::ReaderId;

#[cfg(not(target_os = "emscripten"))]
#[cfg(feature = "parallel")]
pub use shred::AsyncDispatcher;

pub use changeset::ChangeSet;
Expand Down
8 changes: 5 additions & 3 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
//! Contains all of the most common traits, structures,

pub use hibitset::BitSet;
pub use join::{Join, ParJoin};
pub use join::Join;
#[cfg(feature = "parallel")]
pub use join::ParJoin;
pub use shred::{Accessor, Dispatcher, DispatcherBuilder, Read, ReadExpect, Resources, RunNow,
StaticAccessor, System, SystemData, Write, WriteExpect};
pub use shrev::ReaderId;

#[cfg(not(target_os = "emscripten"))]
#[cfg(feature = "parallel")]
pub use rayon::iter::ParallelIterator;
#[cfg(not(target_os = "emscripten"))]
#[cfg(feature = "parallel")]
pub use shred::AsyncDispatcher;

pub use changeset::ChangeSet;
Expand Down
7 changes: 6 additions & 1 deletion src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use shred::{CastFrom, Fetch};

use self::drain::Drain;
use error::{Error, WrongGeneration};
use join::{Join, ParJoin};
use join::Join;
#[cfg(feature = "parallel")]
use join::ParJoin;
use world::{Component, EntitiesRes, Entity, Generation, Index};

mod data;
Expand Down Expand Up @@ -52,6 +54,7 @@ impl<'a> Join for AntiStorage<'a> {

unsafe impl<'a> DistinctStorage for AntiStorage<'a> {}

#[cfg(feature = "parallel")]
unsafe impl<'a> ParJoin for AntiStorage<'a> {}

/// A dynamic storage.
Expand Down Expand Up @@ -478,6 +481,7 @@ where
}
}

#[cfg(feature = "parallel")]
unsafe impl<'a, 'e, T, D> ParJoin for &'a Storage<'e, T, D>
where
T: Component,
Expand Down Expand Up @@ -508,6 +512,7 @@ where
}
}

#[cfg(feature = "parallel")]
unsafe impl<'a, 'e, T, D> ParJoin for &'a mut Storage<'e, T, D>
where
T: Component,
Expand Down
7 changes: 6 additions & 1 deletion src/storage/restrict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use std::ops::{Deref, DerefMut};
use hibitset::BitSet;
use shred::Fetch;

use join::{Join, ParJoin};
use join::Join;

#[cfg(feature = "parallel")]
use join::ParJoin;
use storage::{MaskedStorage, Storage, UnprotectedStorage};
use world::{Component, EntitiesRes, Entity, Index};

Expand Down Expand Up @@ -76,6 +79,7 @@ where
phantom: PhantomData<(C, Restrict)>,
}

#[cfg(feature = "parallel")]
unsafe impl<'rf, 'st: 'rf, C, S, B> ParJoin
for &'rf mut RestrictedStorage<'rf, 'st, C, S, B, MutableParallelRestriction>
where
Expand All @@ -85,6 +89,7 @@ where
{
}

#[cfg(feature = "parallel")]
unsafe impl<'rf, 'st: 'rf, C, S, B, Restrict> ParJoin
for &'rf RestrictedStorage<'rf, 'st, C, S, B, Restrict>
where
Expand Down
5 changes: 4 additions & 1 deletion src/world/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use nonzero_signed::NonZeroI32;
use shred::Read;

use error::WrongGeneration;
use join::{Join, ParJoin};
use join::Join;
#[cfg(feature = "parallel")]
use join::ParJoin;
use storage::WriteStorage;
use world::Component;

Expand Down Expand Up @@ -327,6 +329,7 @@ impl<'a> Join for &'a EntitiesRes {
}
}

#[cfg(feature = "parallel")]
unsafe impl<'a> ParJoin for &'a EntitiesRes {}

/// An entity builder from `EntitiesRes`. Allows building an entity with its
Expand Down

0 comments on commit 97a74c8

Please sign in to comment.