Skip to content

Commit

Permalink
Don't implement Send at all
Browse files Browse the repository at this point in the history
On hosted platforms, libstd allows safely borrowing values from TLS with
'thread lifetime and without a Sync bound. As a result, we can't
guarantee that sending a generator across threads won't create dangling
references or data races. In freestanding environments, the notion of
thread-safety is likely to be defined by the consumer of libfringe,
so our Send bounds and implementation are unlikely to be meaningful
anyway.
  • Loading branch information
edef1c committed Mar 5, 2017
1 parent 34ab0dc commit 78969bb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,14 @@ pub struct Generator<'a, Input: 'a, Output: 'a, Stack: stack::Stack> {
phantom: PhantomData<(&'a (), *mut Input, *const Output)>
}

unsafe impl<'a, Input, Output, Stack> Send for Generator<'a, Input, Output, Stack>
where Input: Send + 'a, Output: Send + 'a, Stack: stack::Stack + Send {}

impl<'a, Input, Output, Stack> Generator<'a, Input, Output, Stack>
where Input: 'a, Output: 'a, Stack: stack::Stack {
/// Creates a new generator.
///
/// See also the [contract](../trait.GuardedStack.html) that needs to be fulfilled by `stack`.
pub fn new<F>(stack: Stack, f: F) -> Generator<'a, Input, Output, Stack>
where Stack: stack::GuardedStack,
F: FnOnce(&Yielder<Input, Output>, Input) + Send + 'a {
F: FnOnce(&Yielder<Input, Output>, Input) + 'a {
unsafe { Generator::unsafe_new(stack, f) }
}

Expand All @@ -110,7 +107,7 @@ impl<'a, Input, Output, Stack> Generator<'a, Input, Output, Stack>
///
/// See also the [contract](../trait.Stack.html) that needs to be fulfilled by `stack`.
pub unsafe fn unsafe_new<F>(stack: Stack, f: F) -> Generator<'a, Input, Output, Stack>
where F: FnOnce(&Yielder<Input, Output>, Input) + Send + 'a {
where F: FnOnce(&Yielder<Input, Output>, Input) + 'a {
unsafe extern "C" fn generator_wrapper<Input, Output, Stack, F>(env: usize, stack_ptr: StackPointer) -> !
where Stack: stack::Stack, F: FnOnce(&Yielder<Input, Output>, Input) {
// Retrieve our environment from the callee and return control to it.
Expand Down
2 changes: 0 additions & 2 deletions tests/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ fn with_owned_stack() {
fn forget_yielded() {
struct Dropper(*mut bool);

unsafe impl Send for Dropper {}

impl Drop for Dropper {
fn drop(&mut self) {
unsafe {
Expand Down

0 comments on commit 78969bb

Please sign in to comment.