coroutine: coroutine_error + coroutine_errc

[SVN r85139]
This commit is contained in:
Oliver Kowalke
2013-07-23 19:49:38 +00:00
parent 01235d2ee7
commit 4c4f2afbd5
20 changed files with 279 additions and 71 deletions

View File

@@ -14,31 +14,31 @@
typedef boost::coroutines::coroutine< void >::pull_type pull_coro_t;
typedef boost::coroutines::coroutine< void >::push_type push_coro_t;
void echo( pull_coro_t & c, int i)
void echo( pull_coro_t & source, int i)
{
std::cout << i;
c();
source();
}
void runit( push_coro_t & ca)
void runit( push_coro_t & sink1)
{
std::cout << "started! ";
for ( int i = 0; i < 10; ++i)
{
push_coro_t c( boost::bind( echo, _1, i) );
while ( c)
c();
ca();
push_coro_t sink2( boost::bind( echo, _1, i) );
while ( sink2)
sink2();
sink1();
}
}
int main( int argc, char * argv[])
{
{
pull_coro_t c( runit);
while ( c) {
pull_coro_t source( runit);
while ( source) {
std::cout << "-";
c();
source();
}
}

View File

@@ -11,26 +11,26 @@
#include <boost/coroutine/all.hpp>
#ifdef BOOST_COROUTINES_UNIDIRECT
void fibonacci( boost::coroutines::coroutine< int >::push_type & c)
void fibonacci( boost::coroutines::coroutine< int >::push_type & sink)
{
int first = 1, second = 1;
c( first);
c( second);
sink( first);
sink( second);
while ( true)
{
int third = first + second;
first = second;
second = third;
c( third);
sink( third);
}
}
int main()
{
boost::coroutines::coroutine< int >::pull_type c( fibonacci);
boost::coroutines::coroutine< int >::pull_type source( fibonacci);
boost::range_iterator<
boost::coroutines::coroutine< int >::pull_type
>::type it( boost::begin( c) );
>::type it( boost::begin( source) );
for ( int i = 0; i < 10; ++i)
{
std::cout << * it << " ";

View File

@@ -11,22 +11,22 @@
#include <boost/coroutine/all.hpp>
#ifdef BOOST_COROUTINES_UNIDIRECT
void first( boost::coroutines::coroutine< void >::push_type & c)
void first( boost::coroutines::coroutine< void >::push_type & sink)
{
std::cout << "started first! ";
for ( int i = 0; i < 10; ++i)
{
c();
sink();
std::cout << "a" << i;
}
}
void second( boost::coroutines::coroutine< void >::push_type & c)
void second( boost::coroutines::coroutine< void >::push_type & sink)
{
std::cout << "started second! ";
for ( int i = 0; i < 10; ++i)
{
c();
sink();
std::cout << "b" << i;
}
}
@@ -34,12 +34,12 @@ void second( boost::coroutines::coroutine< void >::push_type & c)
int main( int argc, char * argv[])
{
{
boost::coroutines::coroutine< void >::pull_type c1( boost::bind( first, _1) );
boost::coroutines::coroutine< void >::pull_type c2( boost::bind( second, _1) );
while ( c1 && c2) {
c1();
boost::coroutines::coroutine< void >::pull_type source1( boost::bind( first, _1) );
boost::coroutines::coroutine< void >::pull_type source2( boost::bind( second, _1) );
while ( source1 && source2) {
source1();
std::cout << " ";
c2();
source2();
std::cout << " ";
}
}

View File

@@ -13,14 +13,14 @@
#include <boost/coroutine/all.hpp>
#ifdef BOOST_COROUTINES_UNIDIRECT
void power( boost::coroutines::coroutine< int >::push_type & c, int number, int exponent)
void power( boost::coroutines::coroutine< int >::push_type & sink, int number, int exponent)
{
int counter = 0;
int result = 1;
while ( counter++ < exponent)
{
result = result * number;
c( result);
sink( result);
}
}
@@ -28,17 +28,17 @@ int main()
{
{
std::cout << "using range functions" << std::endl;
boost::coroutines::coroutine< int >::pull_type c( boost::bind( power, _1, 2, 8) );
boost::coroutines::coroutine< int >::pull_type::iterator e( boost::end( c) );
for ( boost::coroutines::coroutine< int >::pull_type::iterator i( boost::begin( c) );
boost::coroutines::coroutine< int >::pull_type source( boost::bind( power, _1, 2, 8) );
boost::coroutines::coroutine< int >::pull_type::iterator e( boost::end( source) );
for ( boost::coroutines::coroutine< int >::pull_type::iterator i( boost::begin( source) );
i != e; ++i)
std::cout << * i << " ";
}
{
std::cout << "\nusing BOOST_FOREACH" << std::endl;
boost::coroutines::coroutine< int >::pull_type c( boost::bind( power, _1, 2, 8) );
BOOST_FOREACH( int i, c)
boost::coroutines::coroutine< int >::pull_type source( boost::bind( power, _1, 2, 8) );
BOOST_FOREACH( int i, source)
{ std::cout << i << " "; }
}

View File

@@ -32,17 +32,17 @@ void bar( int i)
}
#ifdef BOOST_COROUTINES_UNIDIRECT
void foo( boost::coroutines::coroutine< void >::pull_type & c)
void foo( boost::coroutines::coroutine< void >::pull_type & source)
{
bar( count);
c();
source();
}
void thread_fn()
{
{
boost::coroutines::coroutine< void >::push_type c( foo);
c();
boost::coroutines::coroutine< void >::push_type sink( foo);
sink();
}
}
#else

View File

@@ -17,24 +17,24 @@ struct X : private boost::noncopyable
~X() { std::cout << "~X()" << std::endl; }
};
void fn( boost::coroutines::coroutine< void >::push_type & c)
void fn( boost::coroutines::coroutine< void >::push_type & sink)
{
X x;
int i = 0;
while ( true)
{
std::cout << "fn() : " << ++i << std::endl;
c();
sink();
}
}
int main( int argc, char * argv[])
{
{
boost::coroutines::coroutine< void >::pull_type c( fn);
boost::coroutines::coroutine< void >::pull_type source( fn);
for ( int k = 0; k < 3; ++k)
{
c();
source();
}
std::cout << "destroying coroutine and unwinding stack" << std::endl;
}