|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r84996 - in trunk: boost/coroutine/detail libs/coroutine/build libs/coroutine/example libs/coroutine/example/asio libs/coroutine/example/c++11 libs/coroutine/example/cpp03 libs/coroutine/example/cpp11 libs/coroutine/performance libs/coroutine/src/detail
From: oliver.kowalke_at_[hidden]
Date: 2013-07-10 02:44:14
Author: olli
Date: 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013)
New Revision: 84996
URL: http://svn.boost.org/trac/boost/changeset/84996
Log:
coroutine: fix auto-link in config.hpp and update examples
Added:
trunk/libs/coroutine/example/cpp03/
trunk/libs/coroutine/example/cpp03/Jamfile.v2 (contents, props changed)
trunk/libs/coroutine/example/cpp03/echo.cpp (contents, props changed)
trunk/libs/coroutine/example/cpp03/echosse.cpp (contents, props changed)
trunk/libs/coroutine/example/cpp03/fibonacci.cpp (contents, props changed)
trunk/libs/coroutine/example/cpp03/parallel.cpp (contents, props changed)
trunk/libs/coroutine/example/cpp03/power.cpp (contents, props changed)
trunk/libs/coroutine/example/cpp03/same_fringe.cpp (contents, props changed)
trunk/libs/coroutine/example/cpp03/segmented_stack.cpp (contents, props changed)
trunk/libs/coroutine/example/cpp03/tree.h (contents, props changed)
trunk/libs/coroutine/example/cpp03/unwind.cpp (contents, props changed)
trunk/libs/coroutine/example/cpp11/
trunk/libs/coroutine/example/cpp11/Jamfile.v2 (contents, props changed)
trunk/libs/coroutine/example/cpp11/await_emu.cpp (contents, props changed)
trunk/libs/coroutine/example/cpp11/fibonacci.cpp (contents, props changed)
trunk/libs/coroutine/example/cpp11/same_fringe.cpp (contents, props changed)
trunk/libs/coroutine/example/cpp11/tree.h (contents, props changed)
Deleted:
trunk/libs/coroutine/example/Jamfile.v2
trunk/libs/coroutine/example/asio/
trunk/libs/coroutine/example/c++11/
trunk/libs/coroutine/example/echo.cpp
trunk/libs/coroutine/example/fibonacci.cpp
trunk/libs/coroutine/example/parallel.cpp
trunk/libs/coroutine/example/power.cpp
trunk/libs/coroutine/example/same_fringe.cpp
trunk/libs/coroutine/example/segmented_stack.cpp
trunk/libs/coroutine/example/tree.h
trunk/libs/coroutine/example/unwind.cpp
Text files modified:
trunk/boost/coroutine/detail/config.hpp | 22 ++--
trunk/libs/coroutine/build/Jamfile.v2 | 10 -
/dev/null | 86 -----------------
trunk/libs/coroutine/example/cpp03/Jamfile.v2 | 70 ++++++++++++++
trunk/libs/coroutine/example/cpp03/echo.cpp | 84 +++++++++++++++++
trunk/libs/coroutine/example/cpp03/echosse.cpp | 60 ++++++++++++
trunk/libs/coroutine/example/cpp03/fibonacci.cpp | 71 ++++++++++++++
trunk/libs/coroutine/example/cpp03/parallel.cpp | 91 ++++++++++++++++++
trunk/libs/coroutine/example/cpp03/power.cpp | 86 +++++++++++++++++
trunk/libs/coroutine/example/cpp03/same_fringe.cpp | 115 +++++++++++++++++++++++
trunk/libs/coroutine/example/cpp03/segmented_stack.cpp | 81 ++++++++++++++++
trunk/libs/coroutine/example/cpp03/tree.h | 155 +++++++++++++++++++++++++++++++
trunk/libs/coroutine/example/cpp03/unwind.cpp | 81 ++++++++++++++++
trunk/libs/coroutine/example/cpp11/Jamfile.v2 | 54 ++++++++++
trunk/libs/coroutine/example/cpp11/await_emu.cpp | 197 ++++++++++++++++++++++++++++++++++++++++
trunk/libs/coroutine/example/cpp11/fibonacci.cpp | 56 +++++++++++
trunk/libs/coroutine/example/cpp11/same_fringe.cpp | 123 ++++++++++++++++++++++++
trunk/libs/coroutine/example/cpp11/tree.h | 98 +++++++++++++++++++
/dev/null | 84 -----------------
/dev/null | 71 --------------
/dev/null | 91 ------------------
/dev/null | 86 -----------------
/dev/null | 115 -----------------------
/dev/null | 81 ----------------
/dev/null | 155 -------------------------------
/dev/null | 81 ----------------
trunk/libs/coroutine/performance/Jamfile.v2 | 2
trunk/libs/coroutine/src/detail/coroutine_context.cpp | 2
trunk/libs/coroutine/src/detail/segmented_stack_allocator.cpp | 2
trunk/libs/coroutine/src/detail/standard_stack_allocator_posix.cpp | 2
trunk/libs/coroutine/src/detail/standard_stack_allocator_windows.cpp | 2
31 files changed, 1438 insertions(+), 876 deletions(-)
Modified: trunk/boost/coroutine/detail/config.hpp
==============================================================================
--- trunk/boost/coroutine/detail/config.hpp Wed Jul 10 02:37:39 2013 (r84995)
+++ trunk/boost/coroutine/detail/config.hpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -14,16 +14,12 @@
# undef BOOST_COROUTINES_DECL
#endif
-#if defined(BOOST_HAS_DECLSPEC)
-# if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_COROUTINES_DYN_LINK)
-# if ! defined(BOOST_DYN_LINK)
-# define BOOST_DYN_LINK
-# endif
-# if defined(BOOST_COROUTINES_SOURCE)
-# define BOOST_COROUTINES_DECL BOOST_SYMBOL_EXPORT
-# else
-# define BOOST_COROUTINES_DECL BOOST_SYMBOL_IMPORT
-# endif
+#if (defined(BOOST_ALL_DYN_LINK) || defined(BOOST_COROUTINES_DYN_LINK) ) && ! defined(BOOST_COROUTINES_STATIC_LINK)
+# if defined(BOOST_COROUTINES_SOURCE)
+# define BOOST_COROUTINES_DECL BOOST_SYMBOL_EXPORT
+# define BOOST_COROUTINES_BUILD_DLL
+# else
+# define BOOST_COROUTINES_DECL BOOST_SYMBOL_IMPORT
# endif
#endif
@@ -32,7 +28,7 @@
#endif
#if ! defined(BOOST_COROUTINES_SOURCE) && ! defined(BOOST_ALL_NO_LIB) && ! defined(BOOST_COROUTINES_NO_LIB)
-# define BOOST_LIB_NAME boost_context
+# define BOOST_LIB_NAME boost_coroutine
# if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_COROUTINES_DYN_LINK)
# define BOOST_DYN_LINK
# endif
@@ -54,6 +50,10 @@
# define BOOST_COROUTINES_OLD
#endif
+#if defined(BOOST_COROUTINES_BIDIRECT)
+# define BOOST_COROUTINES_OLD
+#endif
+
#if ! defined(BOOST_COROUTINES_OLD)
# define BOOST_COROUTINES_UNIDIRECT
#endif
Modified: trunk/libs/coroutine/build/Jamfile.v2
==============================================================================
--- trunk/libs/coroutine/build/Jamfile.v2 Wed Jul 10 02:37:39 2013 (r84995)
+++ trunk/libs/coroutine/build/Jamfile.v2 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -18,11 +18,11 @@
<toolset>gcc-4.7,<segmented-stacks>on:<linkflags>"-static-libgcc"
<toolset>gcc-4.8,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>gcc-4.8,<segmented-stacks>on:<linkflags>"-static-libgcc"
- <link>static
- <threading>multi
- : source-location ../src
+ <link>shared:<define>BOOST_COROUTINES_DYN_LINK=1
+ <define>BOOST_COROUTINES_SOURCE
: usage-requirements
- <link>shared:<define>BOOST_COROUTINES_DYN_LINK=1
+ <link>shared:<define>BOOST_COROUTINES_DYN_LINK=1
+ : source-location ../src
;
alias allocator_sources
@@ -45,8 +45,6 @@
lib boost_coroutine
: allocator_sources
detail/coroutine_context.cpp
- : <link>shared:<define>BOOST_COROUTINES_DYN_LINK=1
- :
: <link>shared:<library>../../context/build//boost_context
;
Deleted: trunk/libs/coroutine/example/Jamfile.v2
==============================================================================
--- trunk/libs/coroutine/example/Jamfile.v2 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84995)
+++ /dev/null 00:00:00 1970 (deleted)
@@ -1,86 +0,0 @@
-# Boost.Coroutine Library Examples Jamfile
-
-# Copyright Oliver Kowalke 2009.
-# Distributed under the Boost Software License, Version 1.0.
-# (See accompanying file LICENSE_1_0.txt or copy at
-# http://www.boost.org/LICENSE_1_0.txt)
-
-# For more information, see http://www.boost.org/
-
-import common ;
-import feature ;
-import indirect ;
-import modules ;
-import os ;
-import toolset ;
-
-if [ os.name ] = SOLARIS
-{
- lib socket ;
- lib nsl ;
-}
-else if [ os.name ] = NT
-{
- lib ws2_32 ;
- lib mswsock ;
-}
-else if [ os.name ] = HPUX
-{
- lib ipv6 ;
-}
-
-project boost/coroutine/example
- : requirements
- <library>../build//boost_coroutine
- <library>/boost/program_options//boost_program_options
- <library>/boost/system//boost_system
- <library>/boost/thread//boost_thread
- <toolset>gcc-4.7,<segmented-stacks>on:<cxxflags>-fsplit-stack
- <toolset>gcc-4.8,<segmented-stacks>on:<cxxflags>-fsplit-stack
- <threading>multi
- <link>static
- ;
-
-exe segmented_stack
- : segmented_stack.cpp
- ;
-
-exe fibonacci
- : fibonacci.cpp
- ;
-
-exe echo
- : echo.cpp
- ;
-
-exe power
- : power.cpp
- ;
-
-exe parallel
- : parallel.cpp
- ;
-
-exe unwind
- : unwind.cpp
- ;
-
-exe same_fringe
- : same_fringe.cpp
- ;
-
-#exe asio/stream_client
-# : asio/stream_client.cpp
-# ;
-#
-#exe asio/stream_server
-# : asio/stream_server.cpp
-# ;
-
-#exe same_fringe11
-# : c++11/same_fringe.cpp
-# ;
-#
-#exe fibonacci11
-# : c++11/fibonacci.cpp
-# ;
Added: trunk/libs/coroutine/example/cpp03/Jamfile.v2
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/coroutine/example/cpp03/Jamfile.v2 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -0,0 +1,70 @@
+# Boost.Coroutine Library Examples Jamfile
+
+# Copyright Oliver Kowalke 2009.
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+# For more information, see http://www.boost.org/
+
+import common ;
+import feature ;
+import indirect ;
+import modules ;
+import os ;
+import toolset ;
+
+if [ os.name ] = SOLARIS
+{
+ lib socket ;
+ lib nsl ;
+}
+else if [ os.name ] = NT
+{
+ lib ws2_32 ;
+ lib mswsock ;
+}
+else if [ os.name ] = HPUX
+{
+ lib ipv6 ;
+}
+
+project boost/coroutine/example
+ : requirements
+ <library>../../build//boost_coroutine
+ <library>/boost/program_options//boost_program_options
+ <library>/boost/system//boost_system
+ <library>/boost/thread//boost_thread
+ <toolset>gcc-4.7,<segmented-stacks>on:<cxxflags>-fsplit-stack
+ <toolset>gcc-4.8,<segmented-stacks>on:<cxxflags>-fsplit-stack
+ <link>static
+ <threading>multi
+ ;
+
+exe segmented_stack
+ : segmented_stack.cpp
+ ;
+
+exe fibonacci
+ : fibonacci.cpp
+ ;
+
+exe echo
+ : echo.cpp
+ ;
+
+exe power
+ : power.cpp
+ ;
+
+exe parallel
+ : parallel.cpp
+ ;
+
+exe unwind
+ : unwind.cpp
+ ;
+
+exe same_fringe
+ : same_fringe.cpp
+ ;
Added: trunk/libs/coroutine/example/cpp03/echo.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/coroutine/example/cpp03/echo.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -0,0 +1,84 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+
+#include <boost/bind.hpp>
+#include <boost/coroutine/all.hpp>
+
+#ifdef BOOST_COROUTINES_UNIDIRECT
+typedef boost::coroutines::pull_coroutine< void > pull_coro_t;
+typedef boost::coroutines::push_coroutine< void > push_coro_t;
+
+void echo( pull_coro_t & c, int i)
+{
+ std::cout << i;
+ c();
+}
+
+void runit( push_coro_t & ca)
+{
+ std::cout << "started! ";
+ for ( int i = 0; i < 10; ++i)
+ {
+ push_coro_t c( boost::bind( echo, _1, i) );
+ while ( c)
+ c();
+ ca();
+ }
+}
+
+int main( int argc, char * argv[])
+{
+ {
+ pull_coro_t c( runit);
+ while ( c) {
+ std::cout << "-";
+ c();
+ }
+ }
+
+ std::cout << "\nDone" << std::endl;
+
+ return EXIT_SUCCESS;
+}
+#else
+typedef boost::coroutines::coroutine< void() > coro_t;
+
+void echo( coro_t & ca, int i)
+{
+ std::cout << i;
+ ca();
+}
+
+void runit( coro_t & ca)
+{
+ std::cout << "started! ";
+ for ( int i = 0; i < 10; ++i)
+ {
+ coro_t c( boost::bind( echo, _1, i) );
+ while ( c)
+ c();
+ ca();
+ }
+}
+
+int main( int argc, char * argv[])
+{
+ {
+ coro_t c( runit);
+ while ( c) {
+ std::cout << "-";
+ c();
+ }
+ }
+
+ std::cout << "\nDone" << std::endl;
+
+ return EXIT_SUCCESS;
+}
+#endif
Added: trunk/libs/coroutine/example/cpp03/echosse.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/coroutine/example/cpp03/echosse.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -0,0 +1,60 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+#include <emmintrin.h>
+
+#include <boost/bind.hpp>
+#include <boost/coroutine/all.hpp>
+
+void echoSSE( int i)
+{
+ __m128i xmm;
+ xmm = _mm_set_epi32(i, i+1, i+2, i+3);
+ uint32_t v32[4];
+
+ memcpy(&v32, &xmm, 16);
+
+ std::cout << v32[0];
+ std::cout << v32[1];
+ std::cout << v32[2];
+ std::cout << v32[3];
+}
+
+void echo( boost::coroutines::push_coroutine< void > & c, int i)
+{
+ std::cout << i << ":";
+ echoSSE(i);
+ c();
+}
+
+void runit( boost::coroutines::push_coroutine< void > & ca)
+{
+ std::cout << "started! ";
+ for ( int i = 0; i < 10; ++i)
+ {
+ boost::coroutines::pull_coroutine< void > c( boost::bind( echo, _1, i) );
+ while ( c)
+ c();
+ ca();
+ }
+}
+
+int main( int argc, char * argv[])
+{
+ {
+ boost::coroutines::pull_coroutine< void > c( runit);
+ while ( c) {
+ std::cout << "-";
+ c();
+ }
+ }
+
+ std::cout << "\nDone" << std::endl;
+
+ return EXIT_SUCCESS;
+}
Added: trunk/libs/coroutine/example/cpp03/fibonacci.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/coroutine/example/cpp03/fibonacci.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -0,0 +1,71 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+
+#include <boost/range.hpp>
+#include <boost/coroutine/all.hpp>
+
+#ifdef BOOST_COROUTINES_UNIDIRECT
+void fibonacci( boost::coroutines::push_coroutine< int > & c)
+{
+ int first = 1, second = 1;
+ while ( true)
+ {
+ int third = first + second;
+ first = second;
+ second = third;
+ c( third);
+ }
+}
+
+int main()
+{
+ boost::coroutines::pull_coroutine< int > c( fibonacci);
+ boost::range_iterator<
+ boost::coroutines::pull_coroutine< int >
+ >::type it( boost::begin( c) );
+ for ( int i = 0; i < 10; ++i)
+ {
+ std::cout << * it << " ";
+ ++it;
+ }
+
+ std::cout << "\nDone" << std::endl;
+
+ return EXIT_SUCCESS;
+}
+#else
+void fibonacci( boost::coroutines::coroutine< void( int) > & c)
+{
+ int first = 1, second = 1;
+ while ( true)
+ {
+ int third = first + second;
+ first = second;
+ second = third;
+ c( third);
+ }
+}
+
+int main()
+{
+ boost::coroutines::coroutine< int() > c( fibonacci);
+ boost::range_iterator<
+ boost::coroutines::coroutine< int() >
+ >::type it( boost::begin( c) );
+ for ( int i = 0; i < 10; ++i)
+ {
+ std::cout << * it << " ";
+ ++it;
+ }
+
+ std::cout << "\nDone" << std::endl;
+
+ return EXIT_SUCCESS;
+}
+#endif
Added: trunk/libs/coroutine/example/cpp03/parallel.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/coroutine/example/cpp03/parallel.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -0,0 +1,91 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+
+#include <boost/bind.hpp>
+#include <boost/coroutine/all.hpp>
+
+#ifdef BOOST_COROUTINES_UNIDIRECT
+void first( boost::coroutines::push_coroutine< void > & c)
+{
+ std::cout << "started first! ";
+ for ( int i = 0; i < 10; ++i)
+ {
+ c();
+ std::cout << "a" << i;
+ }
+}
+
+void second( boost::coroutines::push_coroutine< void > & c)
+{
+ std::cout << "started second! ";
+ for ( int i = 0; i < 10; ++i)
+ {
+ c();
+ std::cout << "b" << i;
+ }
+}
+
+int main( int argc, char * argv[])
+{
+ {
+ boost::coroutines::pull_coroutine< void > c1( boost::bind( first, _1) );
+ boost::coroutines::pull_coroutine< void > c2( boost::bind( second, _1) );
+ while ( c1 && c2) {
+ c1();
+ std::cout << " ";
+ c2();
+ std::cout << " ";
+ }
+ }
+
+ std::cout << "\nDone" << std::endl;
+
+ return EXIT_SUCCESS;
+}
+#else
+typedef boost::coroutines::coroutine< void() > coroutine_t;
+
+void first( coroutine_t::caller_type & self)
+{
+ std::cout << "started first! ";
+ for ( int i = 0; i < 10; ++i)
+ {
+ self();
+ std::cout << "a" << i;
+ }
+}
+
+void second( coroutine_t::caller_type & self)
+{
+ std::cout << "started second! ";
+ for ( int i = 0; i < 10; ++i)
+ {
+ self();
+ std::cout << "b" << i;
+ }
+}
+
+int main( int argc, char * argv[])
+{
+ {
+ coroutine_t c1( boost::bind( first, _1) );
+ coroutine_t c2( boost::bind( second, _1) );
+ while ( c1 && c2) {
+ c1();
+ std::cout << " ";
+ c2();
+ std::cout << " ";
+ }
+ }
+
+ std::cout << "\nDone" << std::endl;
+
+ return EXIT_SUCCESS;
+}
+#endif
Added: trunk/libs/coroutine/example/cpp03/power.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/coroutine/example/cpp03/power.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -0,0 +1,86 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+
+#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
+#include <boost/range.hpp>
+#include <boost/coroutine/all.hpp>
+
+#ifdef BOOST_COROUTINES_UNIDIRECT
+void power( boost::coroutines::push_coroutine< int > & c, int number, int exponent)
+{
+ int counter = 0;
+ int result = 1;
+ while ( counter++ < exponent)
+ {
+ result = result * number;
+ c( result);
+ }
+}
+
+int main()
+{
+ {
+ std::cout << "using range functions" << std::endl;
+ boost::coroutines::pull_coroutine< int > c( boost::bind( power, _1, 2, 8) );
+ boost::coroutines::pull_coroutine< int >::iterator e( boost::end( c) );
+ for ( boost::coroutines::pull_coroutine< int >::iterator i( boost::begin( c) );
+ i != e; ++i)
+ std::cout << * i << " ";
+ }
+
+ {
+ std::cout << "\nusing BOOST_FOREACH" << std::endl;
+ boost::coroutines::pull_coroutine< int > c( boost::bind( power, _1, 2, 8) );
+ BOOST_FOREACH( int i, c)
+ { std::cout << i << " "; }
+ }
+
+ std::cout << "\nDone" << std::endl;
+
+ return EXIT_SUCCESS;
+}
+#else
+typedef boost::coroutines::coroutine< int() > coro1_t;
+typedef boost::coroutines::coroutine< void( int) > coro2_t;
+typedef boost::range_iterator< coro1_t >::type iterator_t;
+
+void power( coro2_t & c, int number, int exponent)
+{
+ int counter = 0;
+ int result = 1;
+ while ( counter++ < exponent)
+ {
+ result = result * number;
+ c( result);
+ }
+}
+
+int main()
+{
+ {
+ std::cout << "using range functions" << std::endl;
+ coro1_t c( boost::bind( power, _1, 2, 8) );
+ iterator_t e( boost::end( c) );
+ for ( iterator_t i( boost::begin( c) ); i != e; ++i)
+ std::cout << * i << " ";
+ }
+
+ {
+ std::cout << "\nusing BOOST_FOREACH" << std::endl;
+ coro1_t c( boost::bind( power, _1, 2, 8) );
+ BOOST_FOREACH( int i, c)
+ { std::cout << i << " "; }
+ }
+
+ std::cout << "\nDone" << std::endl;
+
+ return EXIT_SUCCESS;
+}
+#endif
Added: trunk/libs/coroutine/example/cpp03/same_fringe.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/coroutine/example/cpp03/same_fringe.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -0,0 +1,115 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstddef>
+#include <cstdlib>
+#include <iostream>
+#include <string>
+#include <utility>
+
+#include <boost/bind.hpp>
+#include <boost/range.hpp>
+
+#include "tree.h"
+
+std::pair< node::ptr_t, node::ptr_t > create_eq_trees()
+{
+ branch::ptr_t tree1 = branch::create(
+ leaf::create( "A"),
+ branch::create(
+ leaf::create( "B"),
+ leaf::create( "C") ) );
+
+ branch::ptr_t tree2 = branch::create(
+ branch::create(
+ leaf::create( "A"),
+ leaf::create( "B") ),
+ leaf::create( "C") );
+
+ return std::make_pair( tree1, tree2);
+}
+
+std::pair< node::ptr_t, node::ptr_t > create_diff_trees()
+{
+ branch::ptr_t tree1 = branch::create(
+ leaf::create( "A"),
+ branch::create(
+ leaf::create( "B"),
+ leaf::create( "C") ) );
+
+ branch::ptr_t tree2 = branch::create(
+ branch::create(
+ leaf::create( "A"),
+ leaf::create( "X") ),
+ leaf::create( "C") );
+
+ return std::make_pair( tree1, tree2);
+}
+
+#ifdef BOOST_COROUTINES_UNIDIRECT
+bool match_trees( boost::coroutines::pull_coroutine< leaf & > & c1,
+ boost::coroutines::pull_coroutine< leaf & > & c2)
+{
+ typedef boost::range_iterator< boost::coroutines::pull_coroutine< leaf & > >::type iterator_t;
+ iterator_t i1( boost::begin( c1) );
+ iterator_t e1( boost::end( c1) );
+ iterator_t i2( boost::begin( c2) );
+ return std::equal( i1, e1, i2);
+}
+
+int main()
+{
+ {
+ std::pair< node::ptr_t, node::ptr_t > pt = create_eq_trees();
+ boost::coroutines::pull_coroutine< leaf & > te1( boost::bind( enumerate_leafs, _1, pt.first) );
+ boost::coroutines::pull_coroutine< leaf & > te2( boost::bind( enumerate_leafs, _1, pt.second) );
+ bool result = match_trees( te1, te2);
+ std::cout << std::boolalpha << "eq. trees matched == " << result << std::endl;
+ }
+ {
+ std::pair< node::ptr_t, node::ptr_t > pt = create_diff_trees();
+ boost::coroutines::pull_coroutine< leaf & > te1( boost::bind( enumerate_leafs, _1, pt.first) );
+ boost::coroutines::pull_coroutine< leaf & > te2( boost::bind( enumerate_leafs, _1, pt.second) );
+ bool result = match_trees( te1, te2);
+ std::cout << std::boolalpha << "diff. trees matched == " << result << std::endl;
+ }
+
+ std::cout << "Done" << std::endl;
+
+ return EXIT_SUCCESS;
+}
+#else
+bool match_trees( coro_t & c1, coro_t & c2)
+{
+ typedef boost::range_iterator< coro_t >::type iterator_t;
+ iterator_t i1( boost::begin( c1) );
+ iterator_t e1( boost::end( c1) );
+ iterator_t i2( boost::begin( c2) );
+ return std::equal( i1, e1, i2);
+}
+
+int main()
+{
+ {
+ std::pair< node::ptr_t, node::ptr_t > pt = create_eq_trees();
+ coro_t te1( boost::bind( enumerate_leafs, _1, pt.first) );
+ coro_t te2( boost::bind( enumerate_leafs, _1, pt.second) );
+ bool result = match_trees( te1, te2);
+ std::cout << std::boolalpha << "eq. trees matched == " << result << std::endl;
+ }
+ {
+ std::pair< node::ptr_t, node::ptr_t > pt = create_diff_trees();
+ coro_t te1( boost::bind( enumerate_leafs, _1, pt.first) );
+ coro_t te2( boost::bind( enumerate_leafs, _1, pt.second) );
+ bool result = match_trees( te1, te2);
+ std::cout << std::boolalpha << "diff. trees matched == " << result << std::endl;
+ }
+
+ std::cout << "Done" << std::endl;
+
+ return EXIT_SUCCESS;
+}
+#endif
Added: trunk/libs/coroutine/example/cpp03/segmented_stack.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/coroutine/example/cpp03/segmented_stack.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -0,0 +1,81 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <iostream>
+
+#include <boost/assert.hpp>
+#include <boost/coroutine/all.hpp>
+#include <boost/thread.hpp>
+
+int count = 20;
+#if defined(BOOST_USE_SEGMENTED_STACKS)
+void access( char *buf) __attribute__ ((noinline));
+#endif
+void access( char *buf)
+{
+ buf[0] = '\0';
+}
+
+void bar( int i)
+{
+ char buf[4 * 1024];
+
+ if ( i > 0)
+ {
+ access( buf);
+ std::cout << i << ". iteration" << std::endl;
+ bar( i - 1);
+ }
+}
+
+#ifdef BOOST_COROUTINES_UNIDIRECT
+void foo( boost::coroutines::pull_coroutine< void > & c)
+{
+ bar( count);
+ c();
+}
+
+void thread_fn()
+{
+ {
+ boost::coroutines::push_coroutine< void > c( foo);
+ c();
+ }
+}
+#else
+typedef boost::coroutines::coroutine< void() > coro_t;
+
+void foo( coro_t & c)
+{
+ bar( count);
+ c();
+}
+
+void thread_fn()
+{
+ {
+ coro_t c( foo);
+ c();
+ }
+}
+#endif
+
+int main( int argc, char * argv[])
+{
+#if defined(BOOST_USE_SEGMENTED_STACKS)
+ std::cout << "using segmented stacks: allocates " << count << " * 4kB on stack, ";
+ std::cout << "initial stack size = " << boost::coroutines::stack_allocator::default_stacksize() / 1024 << "kB" << std::endl;
+ std::cout << "application should not fail" << std::endl;
+#else
+ std::cout << "using standard stacks: allocates " << count << " * 4kB on stack, ";
+ std::cout << "initial stack size = " << boost::coroutines::stack_allocator::default_stacksize() / 1024 << "kB" << std::endl;
+ std::cout << "application might fail" << std::endl;
+#endif
+
+ boost::thread( thread_fn).join();
+
+ return 0;
+}
Added: trunk/libs/coroutine/example/cpp03/tree.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/coroutine/example/cpp03/tree.h 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -0,0 +1,155 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef TREE_H
+#define TREE_H
+
+#include <cstddef>
+#include <string>
+
+#include <boost/assert.hpp>
+#include <boost/config.hpp>
+#include <boost/coroutine/all.hpp>
+#include <boost/intrusive_ptr.hpp>
+
+# if defined(BOOST_MSVC)
+# pragma warning(push)
+# pragma warning(disable:4355)
+# endif
+
+struct branch;
+struct leaf;
+
+struct visitor
+{
+ virtual ~visitor() {};
+
+ virtual void visit( branch & b) = 0;
+ virtual void visit( leaf & l) = 0;
+};
+
+struct node
+{
+ typedef boost::intrusive_ptr< node > ptr_t;
+
+ std::size_t use_count;
+
+ node() :
+ use_count( 0)
+ {}
+
+ virtual ~node() {}
+
+ virtual void accept( visitor & v) = 0;
+
+ friend inline void intrusive_ptr_add_ref( node * p)
+ { ++p->use_count; }
+
+ friend inline void intrusive_ptr_release( node * p)
+ { if ( 0 == --p->use_count) delete p; }
+};
+
+struct branch : public node
+{
+ node::ptr_t left;
+ node::ptr_t right;
+
+ static ptr_t create( node::ptr_t left_, node::ptr_t right_)
+ { return ptr_t( new branch( left_, right_) ); }
+
+ branch( node::ptr_t left_, node::ptr_t right_) :
+ left( left_), right( right_)
+ {}
+
+ void accept( visitor & v)
+ { v.visit( * this); }
+};
+
+struct leaf : public node
+{
+ std::string value;
+
+ static ptr_t create( std::string const& value_)
+ { return ptr_t( new leaf( value_) ); }
+
+ leaf( std::string const& value_) :
+ value( value_)
+ {}
+
+ void accept( visitor & v)
+ { v.visit( * this); }
+};
+
+inline
+bool operator==( leaf const& l, leaf const& r)
+{ return l.value == r.value; }
+
+inline
+bool operator!=( leaf const& l, leaf const& r)
+{ return l.value != r.value; }
+
+#ifdef BOOST_COROUTINES_UNIDIRECT
+class tree_visitor : public visitor
+{
+private:
+ boost::coroutines::push_coroutine< leaf & > & c_;
+
+public:
+ tree_visitor( boost::coroutines::push_coroutine< leaf & > & c) :
+ c_( c)
+ {}
+
+ void visit( branch & b)
+ {
+ if ( b.left) b.left->accept( * this);
+ if ( b.right) b.right->accept( * this);
+ }
+
+ void visit( leaf & l)
+ { c_( l); }
+};
+
+void enumerate_leafs( boost::coroutines::push_coroutine< leaf & > & c, node::ptr_t root)
+{
+ tree_visitor v( c);
+ root->accept( v);
+}
+#else
+typedef boost::coroutines::coroutine< leaf&() > coro_t;
+
+class tree_visitor : public visitor
+{
+private:
+ coro_t::caller_type & c_;
+
+public:
+ tree_visitor( coro_t::caller_type & c) :
+ c_( c)
+ {}
+
+ void visit( branch & b)
+ {
+ if ( b.left) b.left->accept( * this);
+ if ( b.right) b.right->accept( * this);
+ }
+
+ void visit( leaf & l)
+ { c_( l); }
+};
+
+void enumerate_leafs( coro_t::caller_type & c, node::ptr_t root)
+{
+ tree_visitor v( c);
+ root->accept( v);
+}
+#endif
+
+# if defined(BOOST_MSVC)
+# pragma warning(pop)
+# endif
+
+
+#endif // TREE_H
Added: trunk/libs/coroutine/example/cpp03/unwind.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/coroutine/example/cpp03/unwind.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -0,0 +1,81 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+
+#include <boost/bind.hpp>
+#include <boost/coroutine/all.hpp>
+
+#ifdef BOOST_COROUTINES_UNIDIRECT
+struct X : private boost::noncopyable
+{
+ X() { std::cout << "X()" << std::endl; }
+ ~X() { std::cout << "~X()" << std::endl; }
+};
+
+void fn( boost::coroutines::push_coroutine< void > & c)
+{
+ X x;
+ int i = 0;
+ while ( true)
+ {
+ std::cout << "fn() : " << ++i << std::endl;
+ c();
+ }
+}
+
+int main( int argc, char * argv[])
+{
+ {
+ boost::coroutines::pull_coroutine< void > c( fn);
+ for ( int k = 0; k < 3; ++k)
+ {
+ c();
+ }
+ std::cout << "destroying coroutine and unwinding stack" << std::endl;
+ }
+
+ std::cout << "\nDone" << std::endl;
+
+ return EXIT_SUCCESS;
+}
+#else
+typedef boost::coroutines::coroutine< void() > coro_t;
+
+struct X : private boost::noncopyable
+{
+ X() { std::cout << "X()" << std::endl; }
+ ~X() { std::cout << "~X()" << std::endl; }
+};
+
+void fn( coro_t & ca)
+{
+ X x;
+ int i = 0;
+ while ( true)
+ {
+ std::cout << "fn() : " << ++i << std::endl;
+ ca();
+ }
+}
+
+int main( int argc, char * argv[])
+{
+ {
+ coro_t c( fn);
+ for ( int k = 0; k < 3; ++k)
+ {
+ c();
+ }
+ std::cout << "destroying coroutine and unwinding stack" << std::endl;
+ }
+
+ std::cout << "\nDone" << std::endl;
+
+ return EXIT_SUCCESS;
+}
+#endif
Added: trunk/libs/coroutine/example/cpp11/Jamfile.v2
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/coroutine/example/cpp11/Jamfile.v2 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -0,0 +1,54 @@
+# Boost.Coroutine Library Examples Jamfile
+
+# Copyright Oliver Kowalke 2009.
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+# For more information, see http://www.boost.org/
+
+import common ;
+import feature ;
+import indirect ;
+import modules ;
+import os ;
+import toolset ;
+
+if [ os.name ] = SOLARIS
+{
+ lib socket ;
+ lib nsl ;
+}
+else if [ os.name ] = NT
+{
+ lib ws2_32 ;
+ lib mswsock ;
+}
+else if [ os.name ] = HPUX
+{
+ lib ipv6 ;
+}
+
+project boost/coroutine/example
+ : requirements
+ <library>../../build//boost_coroutine
+ <library>/boost/program_options//boost_program_options
+ <library>/boost/system//boost_system
+ <library>/boost/thread//boost_thread
+ <toolset>gcc-4.7,<segmented-stacks>on:<cxxflags>-fsplit-stack
+ <toolset>gcc-4.8,<segmented-stacks>on:<cxxflags>-fsplit-stack
+ <link>static
+ <threading>multi
+ ;
+
+exe same_fringe
+ : same_fringe.cpp
+ ;
+
+exe fibonacci
+ : fibonacci.cpp
+ ;
+
+exe await_emu
+ : await_emu.cpp
+ ;
Added: trunk/libs/coroutine/example/cpp11/await_emu.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/coroutine/example/cpp11/await_emu.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -0,0 +1,197 @@
+// Copyright Evgeny Panasyuk 2013.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// e-mail: E?????[dot]P???????[at]gmail.???
+
+// Full emulation of await feature from C# language in C++ based on Stackful Coroutines from
+// Boost.Coroutine library.
+// This proof-of-concept shows that exact syntax of await feature can be emulated with help of
+// Stackful Coroutines, demonstrating that it is superior mechanism.
+// Main aim of this proof-of-concept is to draw attention to Stackful Coroutines.
+
+#define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
+#define BOOST_THREAD_PROVIDES_FUTURE
+#define BOOST_RESULT_OF_USE_DECLTYPE
+
+#include <boost/coroutine/all.hpp>
+#include <boost/foreach.hpp>
+#include <boost/thread.hpp>
+#include <boost/chrono.hpp>
+
+#include <functional>
+#include <iostream>
+#include <cstddef>
+#include <utility>
+#include <cstdlib>
+#include <memory>
+#include <vector>
+#include <stack>
+#include <queue>
+#include <ctime>
+
+using namespace std;
+using namespace boost;
+
+// ___________________________________________________________ //
+
+template<typename T>
+class concurrent_queue
+{
+ queue<T> q;
+ mutex m;
+ condition_variable c;
+public:
+ template<typename U>
+ void push(U &&u)
+ {
+ lock_guard<mutex> l(m);
+ q.push( forward<U>(u) );
+ c.notify_one();
+ }
+ void pop(T &result)
+ {
+ unique_lock<mutex> u(m);
+ c.wait(u, [&]{return !q.empty();} );
+ result = move_if_noexcept(q.front());
+ q.pop();
+ }
+};
+
+typedef std::function<void()> Task;
+concurrent_queue<Task> main_tasks;
+auto finished = false;
+
+void reschedule()
+{
+ this_thread::sleep_for(chrono::milliseconds( rand() % 2000 ));
+}
+
+// ___________________________________________________________ //
+
+#ifdef BOOST_COROUTINES_UNIDIRECT
+typedef coroutines::pull_coroutine<void> coro_pull;
+typedef coroutines::push_coroutine<void> coro_push;
+#else
+typedef coroutines::coroutine<void()> coro_pull;
+typedef coroutines::coroutine<void()>::caller_type coro_push;
+#endif
+struct CurrentCoro
+{
+ std::shared_ptr<coro_pull> coro;
+ coro_push *caller;
+};
+/*should be thread_local*/ stack<CurrentCoro> coro_stack;
+
+template<typename F>
+auto asynchronous(F f) -> future<decltype(f())>
+{
+ typedef promise<decltype(f())> CoroPromise;
+
+ CoroPromise coro_promise;
+ auto coro_future = coro_promise.get_future();
+
+ // It is possible to avoid shared_ptr and use move-semantic,
+ // but it would require to refuse use of std::function (it requires CopyConstructable),
+ // and would lead to further complication and is unjustified
+ // for purposes of this proof-of-concept
+ CurrentCoro current_coro =
+ {
+ make_shared<coro_pull>(std::bind( [f](CoroPromise &coro_promise, coro_push &caller)
+ {
+ caller();
+ coro_stack.top().caller = &caller;
+ coro_promise.set_value( f() );
+ }, std::move(coro_promise), placeholders::_1 ))
+ };
+
+ coro_stack.push( std::move(current_coro) );
+ (*coro_stack.top().coro)();
+ coro_stack.pop();
+
+#ifdef _MSC_VER
+ return std::move( coro_future );
+#else
+ return coro_future;
+#endif
+}
+
+struct Awaiter
+{
+ template<typename Future>
+ auto operator*(Future &&ft) -> decltype(ft.get())
+ {
+ typedef decltype(ft.get()) Result;
+
+ auto &¤t_coro = coro_stack.top();
+ auto result = ft.then([current_coro](Future &ft) -> Result
+ {
+ main_tasks.push([current_coro]
+ {
+ coro_stack.push(std::move(current_coro));
+ (*coro_stack.top().coro)();
+ coro_stack.pop();
+ });
+ return ft.get();
+ });
+ (*coro_stack.top().caller)();
+ return result.get();
+ }
+};
+#define await Awaiter()*
+
+// ___________________________________________________________ //
+
+void async_user_handler();
+
+int main()
+{
+ srand(time(0));
+
+ // Custom scheduling is not required - can be integrated
+ // to other systems transparently
+ main_tasks.push([]
+ {
+ asynchronous([]
+ {
+ return async_user_handler(),
+ finished = true;
+ });
+ });
+
+ Task task;
+ while(!finished)
+ {
+ main_tasks.pop(task);
+ task();
+ }
+}
+
+// __________________________________________________________________ //
+
+int bar(int i)
+{
+ // await is not limited by "one level" as in C#
+ auto result = await async([i]{ return reschedule(), i*100; });
+ return result + i*10;
+}
+
+int foo(int i)
+{
+ cout << i << ":\tbegin" << endl;
+ cout << await async([i]{ return reschedule(), i*10; }) << ":\tbody" << endl;
+ cout << bar(i) << ":\tend" << endl;
+ return i*1000;
+}
+
+void async_user_handler()
+{
+ vector<future<int>> fs;
+
+ for(auto i=0; i!=5; ++i)
+ fs.push_back( asynchronous([i]{ return foo(i+1); }) );
+
+ BOOST_FOREACH(auto &&f, fs)
+ cout << await f << ":\tafter end" << endl;
+}
Added: trunk/libs/coroutine/example/cpp11/fibonacci.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/coroutine/example/cpp11/fibonacci.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -0,0 +1,56 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+
+#include <boost/coroutine/all.hpp>
+
+#ifdef BOOST_COROUTINES_UNIDIRECT
+int main()
+{
+ boost::coroutines::pull_coroutine< int > c(
+ [&]( boost::coroutines::push_coroutine< int > & c) {
+ int first = 1, second = 1;
+ for ( int i = 0; i < 10; ++i)
+ {
+ int third = first + second;
+ first = second;
+ second = third;
+ c( third);
+ }
+ });
+
+ for ( auto i : c)
+ std::cout << i << " ";
+
+ std::cout << "\nDone" << std::endl;
+
+ return EXIT_SUCCESS;
+}
+#else
+int main()
+{
+ boost::coroutines::coroutine< int() > c(
+ [&]( boost::coroutines::coroutine< void( int) > & c) {
+ int first = 1, second = 1;
+ for ( int i = 0; i < 10; ++i)
+ {
+ int third = first + second;
+ first = second;
+ second = third;
+ c( third);
+ }
+ });
+
+ for ( auto i : c)
+ std::cout << i << " ";
+
+ std::cout << "\nDone" << std::endl;
+
+ return EXIT_SUCCESS;
+}
+#endif
Added: trunk/libs/coroutine/example/cpp11/same_fringe.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/coroutine/example/cpp11/same_fringe.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -0,0 +1,123 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstddef>
+#include <cstdlib>
+#include <iostream>
+
+#include "tree.h"
+
+node::ptr_t create_tree1()
+{
+ return branch::create(
+ leaf::create( "A"),
+ branch::create(
+ leaf::create( "B"),
+ leaf::create( "C") ) );
+}
+
+node::ptr_t create_tree2()
+{
+ return branch::create(
+ branch::create(
+ leaf::create( "A"),
+ leaf::create( "B") ),
+ leaf::create( "C") );
+}
+
+#ifdef BOOST_COROUTINES_UNIDIRECT
+class coro_visitor : public visitor
+{
+private:
+ boost::coroutines::push_coroutine< leaf& > & c_;
+
+public:
+ coro_visitor( boost::coroutines::push_coroutine< leaf& > & c) :
+ c_( c)
+ {}
+
+ void visit( branch & b)
+ {
+ if ( b.left) b.left->accept( * this);
+ if ( b.right) b.right->accept( * this);
+ }
+
+ void visit( leaf & l)
+ { c_( l); }
+};
+
+int main()
+{
+ node::ptr_t t1 = create_tree1();
+ boost::coroutines::pull_coroutine< leaf& > c1(
+ [&]( boost::coroutines::push_coroutine< leaf & > & c) {
+ coro_visitor v( c);
+ t1->accept( v);
+ });
+
+ node::ptr_t t2 = create_tree2();
+ boost::coroutines::pull_coroutine< leaf& > c2(
+ [&]( boost::coroutines::push_coroutine< leaf & > & c) {
+ coro_visitor v( c);
+ t2->accept( v);
+ });
+
+ bool result = std::equal(
+ boost::begin( c1),
+ boost::end( c1),
+ boost::begin( c2) );
+
+ std::cout << std::boolalpha << "same fringe == " << result << "\nDone" << std::endl;
+
+ return EXIT_SUCCESS;
+}
+#else
+class coro_visitor : public visitor
+{
+private:
+ boost::coroutines::coroutine< void( leaf&) > & c_;
+
+public:
+ coro_visitor( boost::coroutines::coroutine< void( leaf&) > & c) :
+ c_( c)
+ {}
+
+ void visit( branch & b)
+ {
+ if ( b.left) b.left->accept( * this);
+ if ( b.right) b.right->accept( * this);
+ }
+
+ void visit( leaf & l)
+ { c_( l); }
+};
+
+int main()
+{
+ node::ptr_t t1 = create_tree1();
+ boost::coroutines::coroutine< leaf&() > c1(
+ [&]( boost::coroutines::coroutine< void( leaf &) > & c) {
+ coro_visitor v( c);
+ t1->accept( v);
+ });
+
+ node::ptr_t t2 = create_tree2();
+ boost::coroutines::coroutine< leaf&() > c2(
+ [&]( boost::coroutines::coroutine< void( leaf &) > & c) {
+ coro_visitor v( c);
+ t2->accept( v);
+ });
+
+ bool result = std::equal(
+ boost::begin( c1),
+ boost::end( c1),
+ boost::begin( c2) );
+
+ std::cout << std::boolalpha << "same fringe == " << result << "\nDone" << std::endl;
+
+ return EXIT_SUCCESS;
+}
+#endif
Added: trunk/libs/coroutine/example/cpp11/tree.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/coroutine/example/cpp11/tree.h 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -0,0 +1,98 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef TREE_H
+#define TREE_H
+
+#include <cstddef>
+#include <string>
+
+#include <boost/assert.hpp>
+#include <boost/config.hpp>
+#include <boost/coroutine/all.hpp>
+#include <boost/intrusive_ptr.hpp>
+
+# if defined(BOOST_MSVC)
+# pragma warning(push)
+# pragma warning(disable:4355)
+# endif
+
+struct branch;
+struct leaf;
+
+struct visitor
+{
+ virtual ~visitor() {};
+
+ virtual void visit( branch & b) = 0;
+ virtual void visit( leaf & l) = 0;
+};
+
+struct node
+{
+ typedef boost::intrusive_ptr< node > ptr_t;
+
+ std::size_t use_count;
+
+ node() :
+ use_count( 0)
+ {}
+
+ virtual ~node() {}
+
+ virtual void accept( visitor & v) = 0;
+
+ friend inline void intrusive_ptr_add_ref( node * p)
+ { ++p->use_count; }
+
+ friend inline void intrusive_ptr_release( node * p)
+ { if ( 0 == --p->use_count) delete p; }
+};
+
+struct branch : public node
+{
+ node::ptr_t left;
+ node::ptr_t right;
+
+ static ptr_t create( node::ptr_t left_, node::ptr_t right_)
+ { return ptr_t( new branch( left_, right_) ); }
+
+ branch( node::ptr_t left_, node::ptr_t right_) :
+ left( left_), right( right_)
+ {}
+
+ void accept( visitor & v)
+ { v.visit( * this); }
+};
+
+struct leaf : public node
+{
+ std::string value;
+
+ static ptr_t create( std::string const& value_)
+ { return ptr_t( new leaf( value_) ); }
+
+ leaf( std::string const& value_) :
+ value( value_)
+ {}
+
+ void accept( visitor & v)
+ { v.visit( * this); }
+};
+
+inline
+bool operator==( leaf const& l, leaf const& r)
+{ return l.value == r.value; }
+
+inline
+bool operator!=( leaf const& l, leaf const& r)
+{ return l.value != r.value; }
+
+# if defined(BOOST_MSVC)
+# pragma warning(pop)
+# endif
+
+#endif // TREE_H
Deleted: trunk/libs/coroutine/example/echo.cpp
==============================================================================
--- trunk/libs/coroutine/example/echo.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84995)
+++ /dev/null 00:00:00 1970 (deleted)
@@ -1,84 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include <cstdlib>
-#include <iostream>
-
-#include <boost/bind.hpp>
-#include <boost/coroutine/all.hpp>
-
-#ifdef BOOST_COROUTINES_UNIDIRECT
-typedef boost::coroutines::pull_coroutine< void > pull_coro_t;
-typedef boost::coroutines::push_coroutine< void > push_coro_t;
-
-void echo( pull_coro_t & c, int i)
-{
- std::cout << i;
- c();
-}
-
-void runit( push_coro_t & ca)
-{
- std::cout << "started! ";
- for ( int i = 0; i < 10; ++i)
- {
- push_coro_t c( boost::bind( echo, _1, i) );
- while ( c)
- c();
- ca();
- }
-}
-
-int main( int argc, char * argv[])
-{
- {
- pull_coro_t c( runit);
- while ( c) {
- std::cout << "-";
- c();
- }
- }
-
- std::cout << "\nDone" << std::endl;
-
- return EXIT_SUCCESS;
-}
-#else
-typedef boost::coroutines::coroutine< void() > coro_t;
-
-void echo( coro_t & ca, int i)
-{
- std::cout << i;
- ca();
-}
-
-void runit( coro_t & ca)
-{
- std::cout << "started! ";
- for ( int i = 0; i < 10; ++i)
- {
- coro_t c( boost::bind( echo, _1, i) );
- while ( c)
- c();
- ca();
- }
-}
-
-int main( int argc, char * argv[])
-{
- {
- coro_t c( runit);
- while ( c) {
- std::cout << "-";
- c();
- }
- }
-
- std::cout << "\nDone" << std::endl;
-
- return EXIT_SUCCESS;
-}
-#endif
Deleted: trunk/libs/coroutine/example/fibonacci.cpp
==============================================================================
--- trunk/libs/coroutine/example/fibonacci.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84995)
+++ /dev/null 00:00:00 1970 (deleted)
@@ -1,71 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include <cstdlib>
-#include <iostream>
-
-#include <boost/range.hpp>
-#include <boost/coroutine/all.hpp>
-
-#ifdef BOOST_COROUTINES_UNIDIRECT
-void fibonacci( boost::coroutines::push_coroutine< int > & c)
-{
- int first = 1, second = 1;
- while ( true)
- {
- int third = first + second;
- first = second;
- second = third;
- c( third);
- }
-}
-
-int main()
-{
- boost::coroutines::pull_coroutine< int > c( fibonacci);
- boost::range_iterator<
- boost::coroutines::pull_coroutine< int >
- >::type it( boost::begin( c) );
- for ( int i = 0; i < 10; ++i)
- {
- std::cout << * it << " ";
- ++it;
- }
-
- std::cout << "\nDone" << std::endl;
-
- return EXIT_SUCCESS;
-}
-#else
-void fibonacci( boost::coroutines::coroutine< void( int) > & c)
-{
- int first = 1, second = 1;
- while ( true)
- {
- int third = first + second;
- first = second;
- second = third;
- c( third);
- }
-}
-
-int main()
-{
- boost::coroutines::coroutine< int() > c( fibonacci);
- boost::range_iterator<
- boost::coroutines::coroutine< int() >
- >::type it( boost::begin( c) );
- for ( int i = 0; i < 10; ++i)
- {
- std::cout << * it << " ";
- ++it;
- }
-
- std::cout << "\nDone" << std::endl;
-
- return EXIT_SUCCESS;
-}
-#endif
Deleted: trunk/libs/coroutine/example/parallel.cpp
==============================================================================
--- trunk/libs/coroutine/example/parallel.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84995)
+++ /dev/null 00:00:00 1970 (deleted)
@@ -1,91 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include <cstdlib>
-#include <iostream>
-
-#include <boost/bind.hpp>
-#include <boost/coroutine/all.hpp>
-
-#ifdef BOOST_COROUTINES_UNIDIRECT
-void first( boost::coroutines::push_coroutine< void > & c)
-{
- std::cout << "started first! ";
- for ( int i = 0; i < 10; ++i)
- {
- c();
- std::cout << "a" << i;
- }
-}
-
-void second( boost::coroutines::push_coroutine< void > & c)
-{
- std::cout << "started second! ";
- for ( int i = 0; i < 10; ++i)
- {
- c();
- std::cout << "b" << i;
- }
-}
-
-int main( int argc, char * argv[])
-{
- {
- boost::coroutines::pull_coroutine< void > c1( boost::bind( first, _1) );
- boost::coroutines::pull_coroutine< void > c2( boost::bind( second, _1) );
- while ( c1 && c2) {
- c1();
- std::cout << " ";
- c2();
- std::cout << " ";
- }
- }
-
- std::cout << "\nDone" << std::endl;
-
- return EXIT_SUCCESS;
-}
-#else
-typedef boost::coroutines::coroutine< void() > coroutine_t;
-
-void first( coroutine_t::caller_type & self)
-{
- std::cout << "started first! ";
- for ( int i = 0; i < 10; ++i)
- {
- self();
- std::cout << "a" << i;
- }
-}
-
-void second( coroutine_t::caller_type & self)
-{
- std::cout << "started second! ";
- for ( int i = 0; i < 10; ++i)
- {
- self();
- std::cout << "b" << i;
- }
-}
-
-int main( int argc, char * argv[])
-{
- {
- coroutine_t c1( boost::bind( first, _1) );
- coroutine_t c2( boost::bind( second, _1) );
- while ( c1 && c2) {
- c1();
- std::cout << " ";
- c2();
- std::cout << " ";
- }
- }
-
- std::cout << "\nDone" << std::endl;
-
- return EXIT_SUCCESS;
-}
-#endif
Deleted: trunk/libs/coroutine/example/power.cpp
==============================================================================
--- trunk/libs/coroutine/example/power.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84995)
+++ /dev/null 00:00:00 1970 (deleted)
@@ -1,86 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include <cstdlib>
-#include <iostream>
-
-#include <boost/bind.hpp>
-#include <boost/foreach.hpp>
-#include <boost/range.hpp>
-#include <boost/coroutine/all.hpp>
-
-#ifdef BOOST_COROUTINES_UNIDIRECT
-void power( boost::coroutines::push_coroutine< int > & c, int number, int exponent)
-{
- int counter = 0;
- int result = 1;
- while ( counter++ < exponent)
- {
- result = result * number;
- c( result);
- }
-}
-
-int main()
-{
- {
- std::cout << "using range functions" << std::endl;
- boost::coroutines::pull_coroutine< int > c( boost::bind( power, _1, 2, 8) );
- boost::coroutines::pull_coroutine< int >::iterator e( boost::end( c) );
- for ( boost::coroutines::pull_coroutine< int >::iterator i( boost::begin( c) );
- i != e; ++i)
- std::cout << * i << " ";
- }
-
- {
- std::cout << "\nusing BOOST_FOREACH" << std::endl;
- boost::coroutines::pull_coroutine< int > c( boost::bind( power, _1, 2, 8) );
- BOOST_FOREACH( int i, c)
- { std::cout << i << " "; }
- }
-
- std::cout << "\nDone" << std::endl;
-
- return EXIT_SUCCESS;
-}
-#else
-typedef boost::coroutines::coroutine< int() > coro1_t;
-typedef boost::coroutines::coroutine< void( int) > coro2_t;
-typedef boost::range_iterator< coro1_t >::type iterator_t;
-
-void power( coro2_t & c, int number, int exponent)
-{
- int counter = 0;
- int result = 1;
- while ( counter++ < exponent)
- {
- result = result * number;
- c( result);
- }
-}
-
-int main()
-{
- {
- std::cout << "using range functions" << std::endl;
- coro1_t c( boost::bind( power, _1, 2, 8) );
- iterator_t e( boost::end( c) );
- for ( iterator_t i( boost::begin( c) ); i != e; ++i)
- std::cout << * i << " ";
- }
-
- {
- std::cout << "\nusing BOOST_FOREACH" << std::endl;
- coro1_t c( boost::bind( power, _1, 2, 8) );
- BOOST_FOREACH( int i, c)
- { std::cout << i << " "; }
- }
-
- std::cout << "\nDone" << std::endl;
-
- return EXIT_SUCCESS;
-}
-#endif
Deleted: trunk/libs/coroutine/example/same_fringe.cpp
==============================================================================
--- trunk/libs/coroutine/example/same_fringe.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84995)
+++ /dev/null 00:00:00 1970 (deleted)
@@ -1,115 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include <cstddef>
-#include <cstdlib>
-#include <iostream>
-#include <string>
-#include <utility>
-
-#include <boost/bind.hpp>
-#include <boost/range.hpp>
-
-#include "tree.h"
-
-std::pair< node::ptr_t, node::ptr_t > create_eq_trees()
-{
- branch::ptr_t tree1 = branch::create(
- leaf::create( "A"),
- branch::create(
- leaf::create( "B"),
- leaf::create( "C") ) );
-
- branch::ptr_t tree2 = branch::create(
- branch::create(
- leaf::create( "A"),
- leaf::create( "B") ),
- leaf::create( "C") );
-
- return std::make_pair( tree1, tree2);
-}
-
-std::pair< node::ptr_t, node::ptr_t > create_diff_trees()
-{
- branch::ptr_t tree1 = branch::create(
- leaf::create( "A"),
- branch::create(
- leaf::create( "B"),
- leaf::create( "C") ) );
-
- branch::ptr_t tree2 = branch::create(
- branch::create(
- leaf::create( "A"),
- leaf::create( "X") ),
- leaf::create( "C") );
-
- return std::make_pair( tree1, tree2);
-}
-
-#ifdef BOOST_COROUTINES_UNIDIRECT
-bool match_trees( boost::coroutines::pull_coroutine< leaf & > & c1,
- boost::coroutines::pull_coroutine< leaf & > & c2)
-{
- typedef boost::range_iterator< boost::coroutines::pull_coroutine< leaf & > >::type iterator_t;
- iterator_t i1( boost::begin( c1) );
- iterator_t e1( boost::end( c1) );
- iterator_t i2( boost::begin( c2) );
- return std::equal( i1, e1, i2);
-}
-
-int main()
-{
- {
- std::pair< node::ptr_t, node::ptr_t > pt = create_eq_trees();
- boost::coroutines::pull_coroutine< leaf & > te1( boost::bind( enumerate_leafs, _1, pt.first) );
- boost::coroutines::pull_coroutine< leaf & > te2( boost::bind( enumerate_leafs, _1, pt.second) );
- bool result = match_trees( te1, te2);
- std::cout << std::boolalpha << "eq. trees matched == " << result << std::endl;
- }
- {
- std::pair< node::ptr_t, node::ptr_t > pt = create_diff_trees();
- boost::coroutines::pull_coroutine< leaf & > te1( boost::bind( enumerate_leafs, _1, pt.first) );
- boost::coroutines::pull_coroutine< leaf & > te2( boost::bind( enumerate_leafs, _1, pt.second) );
- bool result = match_trees( te1, te2);
- std::cout << std::boolalpha << "diff. trees matched == " << result << std::endl;
- }
-
- std::cout << "Done" << std::endl;
-
- return EXIT_SUCCESS;
-}
-#else
-bool match_trees( coro_t & c1, coro_t & c2)
-{
- typedef boost::range_iterator< coro_t >::type iterator_t;
- iterator_t i1( boost::begin( c1) );
- iterator_t e1( boost::end( c1) );
- iterator_t i2( boost::begin( c2) );
- return std::equal( i1, e1, i2);
-}
-
-int main()
-{
- {
- std::pair< node::ptr_t, node::ptr_t > pt = create_eq_trees();
- coro_t te1( boost::bind( enumerate_leafs, _1, pt.first) );
- coro_t te2( boost::bind( enumerate_leafs, _1, pt.second) );
- bool result = match_trees( te1, te2);
- std::cout << std::boolalpha << "eq. trees matched == " << result << std::endl;
- }
- {
- std::pair< node::ptr_t, node::ptr_t > pt = create_diff_trees();
- coro_t te1( boost::bind( enumerate_leafs, _1, pt.first) );
- coro_t te2( boost::bind( enumerate_leafs, _1, pt.second) );
- bool result = match_trees( te1, te2);
- std::cout << std::boolalpha << "diff. trees matched == " << result << std::endl;
- }
-
- std::cout << "Done" << std::endl;
-
- return EXIT_SUCCESS;
-}
-#endif
Deleted: trunk/libs/coroutine/example/segmented_stack.cpp
==============================================================================
--- trunk/libs/coroutine/example/segmented_stack.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84995)
+++ /dev/null 00:00:00 1970 (deleted)
@@ -1,81 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include <iostream>
-
-#include <boost/assert.hpp>
-#include <boost/coroutine/all.hpp>
-#include <boost/thread.hpp>
-
-int count = 20;
-#if defined(BOOST_USE_SEGMENTED_STACKS)
-void access( char *buf) __attribute__ ((noinline));
-#endif
-void access( char *buf)
-{
- buf[0] = '\0';
-}
-
-void bar( int i)
-{
- char buf[4 * 1024];
-
- if ( i > 0)
- {
- access( buf);
- std::cout << i << ". iteration" << std::endl;
- bar( i - 1);
- }
-}
-
-#ifdef BOOST_COROUTINES_UNIDIRECT
-void foo( boost::coroutines::pull_coroutine< void > & c)
-{
- bar( count);
- c();
-}
-
-void thread_fn()
-{
- {
- boost::coroutines::push_coroutine< void > c( foo);
- c();
- }
-}
-#else
-typedef boost::coroutines::coroutine< void() > coro_t;
-
-void foo( coro_t & c)
-{
- bar( count);
- c();
-}
-
-void thread_fn()
-{
- {
- coro_t c( foo);
- c();
- }
-}
-#endif
-
-int main( int argc, char * argv[])
-{
-#if defined(BOOST_USE_SEGMENTED_STACKS)
- std::cout << "using segmented stacks: allocates " << count << " * 4kB on stack, ";
- std::cout << "initial stack size = " << boost::coroutines::stack_allocator::default_stacksize() / 1024 << "kB" << std::endl;
- std::cout << "application should not fail" << std::endl;
-#else
- std::cout << "using standard stacks: allocates " << count << " * 4kB on stack, ";
- std::cout << "initial stack size = " << boost::coroutines::stack_allocator::default_stacksize() / 1024 << "kB" << std::endl;
- std::cout << "application might fail" << std::endl;
-#endif
-
- boost::thread( thread_fn).join();
-
- return 0;
-}
Deleted: trunk/libs/coroutine/example/tree.h
==============================================================================
--- trunk/libs/coroutine/example/tree.h 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84995)
+++ /dev/null 00:00:00 1970 (deleted)
@@ -1,155 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#ifndef TREE_H
-#define TREE_H
-
-#include <cstddef>
-#include <string>
-
-#include <boost/assert.hpp>
-#include <boost/config.hpp>
-#include <boost/coroutine/all.hpp>
-#include <boost/intrusive_ptr.hpp>
-
-# if defined(BOOST_MSVC)
-# pragma warning(push)
-# pragma warning(disable:4355)
-# endif
-
-struct branch;
-struct leaf;
-
-struct visitor
-{
- virtual ~visitor() {};
-
- virtual void visit( branch & b) = 0;
- virtual void visit( leaf & l) = 0;
-};
-
-struct node
-{
- typedef boost::intrusive_ptr< node > ptr_t;
-
- std::size_t use_count;
-
- node() :
- use_count( 0)
- {}
-
- virtual ~node() {}
-
- virtual void accept( visitor & v) = 0;
-
- friend inline void intrusive_ptr_add_ref( node * p)
- { ++p->use_count; }
-
- friend inline void intrusive_ptr_release( node * p)
- { if ( 0 == --p->use_count) delete p; }
-};
-
-struct branch : public node
-{
- node::ptr_t left;
- node::ptr_t right;
-
- static ptr_t create( node::ptr_t left_, node::ptr_t right_)
- { return ptr_t( new branch( left_, right_) ); }
-
- branch( node::ptr_t left_, node::ptr_t right_) :
- left( left_), right( right_)
- {}
-
- void accept( visitor & v)
- { v.visit( * this); }
-};
-
-struct leaf : public node
-{
- std::string value;
-
- static ptr_t create( std::string const& value_)
- { return ptr_t( new leaf( value_) ); }
-
- leaf( std::string const& value_) :
- value( value_)
- {}
-
- void accept( visitor & v)
- { v.visit( * this); }
-};
-
-inline
-bool operator==( leaf const& l, leaf const& r)
-{ return l.value == r.value; }
-
-inline
-bool operator!=( leaf const& l, leaf const& r)
-{ return l.value != r.value; }
-
-#ifdef BOOST_COROUTINES_UNIDIRECT
-class tree_visitor : public visitor
-{
-private:
- boost::coroutines::push_coroutine< leaf & > & c_;
-
-public:
- tree_visitor( boost::coroutines::push_coroutine< leaf & > & c) :
- c_( c)
- {}
-
- void visit( branch & b)
- {
- if ( b.left) b.left->accept( * this);
- if ( b.right) b.right->accept( * this);
- }
-
- void visit( leaf & l)
- { c_( l); }
-};
-
-void enumerate_leafs( boost::coroutines::push_coroutine< leaf & > & c, node::ptr_t root)
-{
- tree_visitor v( c);
- root->accept( v);
-}
-#else
-typedef boost::coroutines::coroutine< leaf&() > coro_t;
-
-class tree_visitor : public visitor
-{
-private:
- coro_t::caller_type & c_;
-
-public:
- tree_visitor( coro_t::caller_type & c) :
- c_( c)
- {}
-
- void visit( branch & b)
- {
- if ( b.left) b.left->accept( * this);
- if ( b.right) b.right->accept( * this);
- }
-
- void visit( leaf & l)
- { c_( l); }
-};
-
-void enumerate_leafs( coro_t::caller_type & c, node::ptr_t root)
-{
- tree_visitor v( c);
- root->accept( v);
-}
-#endif
-
-# if defined(BOOST_MSVC)
-# pragma warning(pop)
-# endif
-
-
-#endif // TREE_H
Deleted: trunk/libs/coroutine/example/unwind.cpp
==============================================================================
--- trunk/libs/coroutine/example/unwind.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84995)
+++ /dev/null 00:00:00 1970 (deleted)
@@ -1,81 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include <cstdlib>
-#include <iostream>
-
-#include <boost/bind.hpp>
-#include <boost/coroutine/all.hpp>
-
-#ifdef BOOST_COROUTINES_UNIDIRECT
-struct X : private boost::noncopyable
-{
- X() { std::cout << "X()" << std::endl; }
- ~X() { std::cout << "~X()" << std::endl; }
-};
-
-void fn( boost::coroutines::push_coroutine< void > & c)
-{
- X x;
- int i = 0;
- while ( true)
- {
- std::cout << "fn() : " << ++i << std::endl;
- c();
- }
-}
-
-int main( int argc, char * argv[])
-{
- {
- boost::coroutines::pull_coroutine< void > c( fn);
- for ( int k = 0; k < 3; ++k)
- {
- c();
- }
- std::cout << "destroying coroutine and unwinding stack" << std::endl;
- }
-
- std::cout << "\nDone" << std::endl;
-
- return EXIT_SUCCESS;
-}
-#else
-typedef boost::coroutines::coroutine< void() > coro_t;
-
-struct X : private boost::noncopyable
-{
- X() { std::cout << "X()" << std::endl; }
- ~X() { std::cout << "~X()" << std::endl; }
-};
-
-void fn( coro_t & ca)
-{
- X x;
- int i = 0;
- while ( true)
- {
- std::cout << "fn() : " << ++i << std::endl;
- ca();
- }
-}
-
-int main( int argc, char * argv[])
-{
- {
- coro_t c( fn);
- for ( int k = 0; k < 3; ++k)
- {
- c();
- }
- std::cout << "destroying coroutine and unwinding stack" << std::endl;
- }
-
- std::cout << "\nDone" << std::endl;
-
- return EXIT_SUCCESS;
-}
-#endif
Modified: trunk/libs/coroutine/performance/Jamfile.v2
==============================================================================
--- trunk/libs/coroutine/performance/Jamfile.v2 Wed Jul 10 02:37:39 2013 (r84995)
+++ trunk/libs/coroutine/performance/Jamfile.v2 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -19,8 +19,8 @@
<library>/boost/coroutine//boost_coroutine
<toolset>gcc-4.7,<segmented-stacks>on:<cxxflags>-fsplit-stack
<toolset>gcc-4.8,<segmented-stacks>on:<cxxflags>-fsplit-stack
- <link>static
<linkflags>"-lrt"
+ <link>static
<threading>multi
;
Modified: trunk/libs/coroutine/src/detail/coroutine_context.cpp
==============================================================================
--- trunk/libs/coroutine/src/detail/coroutine_context.cpp Wed Jul 10 02:37:39 2013 (r84995)
+++ trunk/libs/coroutine/src/detail/coroutine_context.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -4,8 +4,6 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#define BOOST_COROUTINES_SOURCE
-
#include "boost/coroutine/detail/coroutine_context.hpp"
#ifdef BOOST_MSVC
Modified: trunk/libs/coroutine/src/detail/segmented_stack_allocator.cpp
==============================================================================
--- trunk/libs/coroutine/src/detail/segmented_stack_allocator.cpp Wed Jul 10 02:37:39 2013 (r84995)
+++ trunk/libs/coroutine/src/detail/segmented_stack_allocator.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -4,8 +4,6 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#define BOOST_COROUTINES_SOURCE
-
#include <boost/coroutine/detail/segmented_stack_allocator.hpp>
#include <boost/assert.hpp>
Modified: trunk/libs/coroutine/src/detail/standard_stack_allocator_posix.cpp
==============================================================================
--- trunk/libs/coroutine/src/detail/standard_stack_allocator_posix.cpp Wed Jul 10 02:37:39 2013 (r84995)
+++ trunk/libs/coroutine/src/detail/standard_stack_allocator_posix.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -4,8 +4,6 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#define BOOST_COROUTINES_SOURCE
-
#include "boost/coroutine/detail/standard_stack_allocator.hpp"
extern "C" {
Modified: trunk/libs/coroutine/src/detail/standard_stack_allocator_windows.cpp
==============================================================================
--- trunk/libs/coroutine/src/detail/standard_stack_allocator_windows.cpp Wed Jul 10 02:37:39 2013 (r84995)
+++ trunk/libs/coroutine/src/detail/standard_stack_allocator_windows.cpp 2013-07-10 02:44:14 EDT (Wed, 10 Jul 2013) (r84996)
@@ -4,8 +4,6 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#define BOOST_COROUTINES_SOURCE
-
#include "boost/coroutine/detail/standard_stack_allocator.hpp"
extern "C" {
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk