Commit Graph

23 Commits

Author SHA1 Message Date
edef 661872f725 Don't implement Send at all
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.
2017-03-06 09:21:08 +01:00
whitequark 243e9ffc6c Implement Eq on generator::State. 2016-10-01 18:25:32 -04:00
Amanieu d'Antras f9b6cd17f6 Allow Generator to have !Send inputs and outputs
close #55
2016-09-30 21:41:26 -04:00
edef 1783c25c46 Implement Send for Generator 2016-09-22 14:03:46 -04:00
edef 19ec5ef45b Make the passed Yielder borrow immutable [breaking-change]
Yielder::suspend only requires an immutable reference, and allowing
mem::replace on the yielder isn't very useful.
2016-09-22 14:03:46 -04:00
edef 045ad33785 Ensure that the Input/Output types outlive the generator [breaking-change]
Previously, it was possible to cause unsafety by sending a short-lived
value into or out of the generator.
2016-09-22 14:03:46 -04:00
edef 59f28e92cb Ensure that the closure outlives the generator [breaking-change]
Previously, it was possible to cause unsafety by having the closure
refer to values with lifetimes that weren't enclosed by the generator's
lifetime.
2016-09-22 14:03:46 -04:00
edef adb29eade7 Fix the variance of Input/Output 2016-09-22 13:43:34 -04:00
edef 4e55e2b651 Use PhantomData-of-tuple instead of tuple-of-PhantomData 2016-09-22 13:02:35 -04:00
Amanieu d'Antras fff625767c Clean up and simplify the implementation of generators 2016-09-09 10:59:35 -04:00
whitequark 231bc3cc46 Yielder: use Cell internally to allow suspending via multiple borrows.
The use case is as follows: let's say I have a scheduler that uses
libfringe for context switching. A single thread may open several
sockets, each of which presents a std::io::Read interface, and
waiting in Read::read requires having a reference to the yielder
inside the socket.

This could be worked around with RefCell in the API consumer, but
there is no real reason to not implement it in libfringe.

close #48
2016-09-06 23:37:33 -04:00
whitequark 0ca4bc86ff doc: explicitly state the contracts of Stack and GuardedStack. 2016-09-02 14:51:29 -04:00
edef 1994ffee27 don't drop yielded values in the generator
fix #31
2016-08-30 18:17:52 -04:00
whitequark 4b32c18f70 Rename Yielder::generate to Yielder::suspend.
This makes more sense, because "generate" implies *running*
a generator, not *returning* from a generator. That name was
a vestige of the time when libfringe only really provided a .next()
implementation, which made marginally more sense together with
.generate(), but it doesn't anymore when we have .resume().
2016-08-30 12:20:34 -04:00
edef f21b8dc936 Update the license headers for MIT/Apache 2016-08-20 23:45:01 +02:00
whitequark d4b7c427c9 impl Iterator for Generator<Input=()>. 2016-08-13 13:38:04 +02:00
whitequark ddbf9a5afe Reimplement Generator to pass both input and output values around. 2016-08-13 13:38:04 +02:00
whitequark 308df32ac2 Use a more semantically correct PhantomData field in Generator. 2016-08-13 13:38:04 +02:00
whitequark a5d3430e63 Make Generator safe in presence of destructors. 2016-08-13 13:38:04 +02:00
edef bb699c0f6e Allow inlining Generator::state 2016-08-13 12:52:12 +02:00
whitequark 15d2fbaf51 Add an inline hint on Generator::next().
This improves the generate benchmark by about 1ns.
2016-07-17 13:56:03 -04:00
whitequark 16c674b4f4 Implement the GuardedStack marker trait. 2016-07-17 13:56:03 -04:00
whitequark 7ffad26cfd Implement the safe Generator abstraction.
close #24
2016-07-17 13:55:56 -04:00