Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class coroutine

#include <boost/coroutine/coroutine.hpp>

template<
    typename Signature,
    typename Allocator = ctx::stack_allocator
>
class coroutine
{
public:
    class self_t
    {
    public:
        T yield( R);

        void yield_break();
    };

    coroutine();

    template< typename Fn >
    coroutine( Fn fn,
               std::size_t size = ctx::default_stacksize(),
               flag_unwind_t do_unwind = stack_unwind,
               bool preserve_fpu = true,
               Allocator alloc = Allocator() );

    template< typename Fn >
    coroutine( Fn && fn,
               std::size_t size = ctx::default_stacksize(),
               flag_unwind_t do_unwind = stack_unwind,
               bool preserve_fpu = true,
               Allocator alloc = Allocator() );

    coroutine( coroutine && other);

    coroutine & operator=( coroutine && other);

    operator unspecified-bool-type() const;

    bool operator!() const;

    void swap( coroutine & other);

    bool is_complete() const;

    R operator()(A0 a0, ..., A9 a9);
};

void swap( coroutine & l, coroutine & r);
coroutine()

Effects:

Creates a coroutine representing a not-a-coroutine.

Throws:

Nothing.

template< typename Fn > coroutine( Fn fn, std::size_t size, flag_unwind_t do_unwind, bool preserve_fpu, Allocator alloc)

Preconditions:

size > ctx::minimum_stacksize(), size < ctx::maximum_stacksize() when ! ctx::is_stack_unbound().

Effects:

Creates a coroutine which will execute fn. If do_unwind is stack_unwind the destructor of *this unwinds the stack before destructing it. If preserve_fpu is true the floating-point registers are preserved between context switches.

Throws:

invalid_argument if a precondition is not satisfied.

coroutine( coroutine && other)

Effects:

Moves the internal data of other to *this. other becomes not-a-coroutine.

Throws:

Nothing.

coroutine & operator=( coroutine && other)

Effects:

Destroys the internal data of *this and moves the internal data of other to *this. other becomes not-a-coroutine.

Throws:

Nothing.

operator unspecified-bool-type() const

Returns:

If *this refers to not-a-coroutine, the function returns false. Otherwise true.

Throws:

Nothing.

bool operator!() const

Returns:

If *this refers not to not-a-coroutine, the function returns true. Otherwise false.

Throws:

Nothing.

void swap( coroutine & other)

Effects:

Swaps the internal data from *this with the values of other.

Throws:

Nothing.

bool is_complete() const

Preconditions:

*this is not a not-a-coroutine.

Effects:

Returns true if coroutine-function of *this has returned.

Throws:

Nothing.

R operator()(A0 a0, A9 a9)

Preconditions:

*this is not a not-a-coroutine, ! is_complete().

Effects:

coroutine-function is entered and the arguments are passed to the coroutine. The return value is the argument passed to coroutine<>::self_t::yield().

Throws:

coroutine_terminated if coroutine<>::self_t::yield_break() was called or other exceptions thrown inside coroutine-function.

T self_t::yield( R)

Effects:

Gives execution control back to calling context by returning a value of type R. The return type of this function is a boost::tuple<> containing the arguments passed to coroutine<>::operator()().

Throws:

Nothing.

void self_t::yield_break()

Effects:

Gives execution control back to calling context and sets the coroutine to be complete. coroutine<>::operator()() in the other coroutine throws exception coroutine_terminated.

Postconditions:

*this is complete, which is is_complete() returns true.

Non-member function swap()
void swap( coroutine & l, coroutine & r);

Effects:

As if 'l.swap( r)'.


PrevUpHomeNext