|
| Fiber () noexcept=default |
| Creates an invalid fiber. More...
|
|
| Fiber (Fiber &&other) noexcept |
| Moves the state of other to *this . More...
|
|
template<class F , class = typename ::std::enable_if<!::std::is_same< typename ::std::decay<F>::type, Fiber>::value>::type> |
| Fiber (F &&f) |
| Equivalent to Fiber::Fiber(f, static_cast<FiberFlag>(0), 0) .
|
|
template<class F > |
| Fiber (F &&f, FiberFlag flags) |
| Equivalent to Fiber::Fiber(f, flags, 0) .
|
|
template<class F > |
| Fiber (F &&f, ::std::size_t stack_size) |
| Equivalent to Fiber::Fiber(f, static_cast<FiberFlag>(0), stack_size) .
|
|
template<class F , class = typename ::std::enable_if<compat::is_invocable_r< Fiber, F, Fiber&&>::value>::type> |
| Fiber (F &&f, FiberFlag flags, ::std::size_t stack_size) |
| Constructs a fiber with a newly allocated stack. More...
|
|
Fiber & | operator= (Fiber &&other) noexcept |
| Moves the state of other to *this . More...
|
|
| ~Fiber () |
| Destroys a Fiber instance. More...
|
|
| operator bool () const noexcept |
| Checks whether *this is a valid fiber.
|
|
Fiber | resume () && |
| Suspends the calling fiber and resumes *this . More...
|
|
template<class F > |
Fiber | resume_with (F &&f) && |
| Suspends the calling fiber and resumes *this , but calls f(other) in the resumed fiber as if called by the suspended callable object, where other is the fiber that has been suspended in order to resume the current fiber. More...
|
|
void | swap (Fiber &other) noexcept |
| Swaps the states of *this and other.
|
|
A fiber.
- See also
- fiber_t
Definition at line 193 of file fiber.hpp.
template<class F , class = typename ::std::enable_if<compat::is_invocable_r< Fiber, F, Fiber&&>::value>::type>
lely::util::Fiber::Fiber |
( |
F && |
f, |
|
|
FiberFlag |
flags, |
|
|
::std::size_t |
stack_size |
|
) |
| |
|
inline |
Constructs a fiber with a newly allocated stack.
The specified callable object is not invoked until the first call to resume() or resume_with().
- Parameters
-
f | a callable object with signature Fiber(Fiber&&) . |
flags | any supported combination of FiberFlag::SAVE_MASK, FiberFlag::SAVE_FENV, FiberFlag::SAVE_ERROR and FiberFlag::GUARD_STACK. |
stack_size | the size (in bytes) of the stack frame to be allocated for the fiber. If 0, the default size (LELY_FIBER_STKSZ) is used. The size of the allocated stack is always at least LELY_FIBER_MINSTKSZ bytes. |
Definition at line 242 of file fiber.hpp.
lely::util::Fiber::~Fiber |
( |
| ) |
|
|
inline |
Destroys a Fiber instance.
If the instance represents a fiber of execution (operator bool() returns true), then the fiber of execution is destroyed also. If the callable object with which the fiber was created has not yet terminated, its stack is unwound as if by
::std::move(*this).resume_with([](
Fiber&& f) ->
Fiber {
throw fiber_unwind(::std::move(f));
return {};
});
To ensure proper destruction, the callable MUST NOT catch the lely::util::fiber_unwind exception (or rethrow it if it does).
Definition at line 289 of file fiber.hpp.
template<class F >
Fiber lely::util::Fiber::resume_with |
( |
F && |
f | ) |
&& |
|
inline |
Suspends the calling fiber and resumes *this
, but calls f(other) in the resumed fiber as if called by the suspended callable object, where other is the fiber that has been suspended in order to resume the current fiber.
If *this
is an invalid fiber (operator bool() returns false), the fiber associated with the calling thread is resumed.
- Returns
- the result of f().
- Precondition
- the calling thread is the thread on which
*this
was created.
- Postcondition
*this
is an invalid fiber (operator bool() returns false).
- Exceptions
-
fiber_unwind | if the fiber is being destroyed. This exception MUST NOT be caught (or rethrown if it is). |
Definition at line 346 of file fiber.hpp.