Loading include/tool/coroutine.h +27 −5 Original line number Original line Diff line number Diff line Loading @@ -28,6 +28,7 @@ #include <cstdlib> #include <cstdlib> #include <boost/context/fcontext.hpp> #include <boost/context/fcontext.hpp> #include <boost/version.hpp> #include "delegate.h" #include "delegate.h" Loading Loading @@ -88,6 +89,11 @@ public: if( m_saved ) if( m_saved ) delete m_saved; delete m_saved; #if BOOST_VERSION >= 105600 if( m_self ) delete m_self; #endif if( m_stack ) if( m_stack ) free( m_stack ); free( m_stack ); } } Loading @@ -101,7 +107,7 @@ public: */ */ void Yield() void Yield() { { boost::context::jump_fcontext( m_self, m_saved, 0 ); jump( m_self, m_saved, 0 ); } } /** /** Loading @@ -113,7 +119,7 @@ public: void Yield( ReturnType& aRetVal ) void Yield( ReturnType& aRetVal ) { { m_retVal = aRetVal; m_retVal = aRetVal; boost::context::jump_fcontext( m_self, m_saved, 0 ); jump( m_self, m_saved, 0 ); } } /** /** Loading Loading @@ -147,12 +153,17 @@ public: assert( m_saved == NULL ); assert( m_saved == NULL ); m_args = &aArgs; m_args = &aArgs; #if BOOST_VERSION >= 105600 m_self = new boost::context::fcontext_t(); *m_self = boost::context::make_fcontext( sp, m_stackSize, callerStub ); #else m_self = boost::context::make_fcontext( sp, m_stackSize, callerStub ); m_self = boost::context::make_fcontext( sp, m_stackSize, callerStub ); #endif m_saved = new boost::context::fcontext_t(); m_saved = new boost::context::fcontext_t(); m_running = true; m_running = true; // off we go! // off we go! boost::context::jump_fcontext( m_saved, m_self, reinterpret_cast<intptr_t>( this ) ); jump( m_saved, m_self, reinterpret_cast<intptr_t>( this ) ); return m_running; return m_running; } } Loading @@ -165,7 +176,7 @@ public: */ */ bool Resume() bool Resume() { { boost::context::jump_fcontext( m_saved, m_self, 0 ); jump( m_saved, m_self, 0 ); return m_running; return m_running; } } Loading Loading @@ -204,7 +215,18 @@ private: cor->m_running = false; cor->m_running = false; // go back to wherever we came from. // go back to wherever we came from. boost::context::jump_fcontext( cor->m_self, cor->m_saved, 0 ); // reinterpret_cast<intptr_t>( this )); jump( cor->m_self, cor->m_saved, 0 ); // reinterpret_cast<intptr_t>( this )); } ///> Wrapper for jump_fcontext to assure compatibility between different boost versions static inline intptr_t jump(boost::context::fcontext_t* aOld, boost::context::fcontext_t* aNew, intptr_t aP, bool aPreserveFPU = true ) { #if BOOST_VERSION >= 105600 return boost::context::jump_fcontext( aOld, *aNew, aP, aPreserveFPU ); #else return boost::context::jump_fcontext( aOld, aNew, aP, aPreserveFPU ); #endif } } template <typename T> template <typename T> Loading Loading
include/tool/coroutine.h +27 −5 Original line number Original line Diff line number Diff line Loading @@ -28,6 +28,7 @@ #include <cstdlib> #include <cstdlib> #include <boost/context/fcontext.hpp> #include <boost/context/fcontext.hpp> #include <boost/version.hpp> #include "delegate.h" #include "delegate.h" Loading Loading @@ -88,6 +89,11 @@ public: if( m_saved ) if( m_saved ) delete m_saved; delete m_saved; #if BOOST_VERSION >= 105600 if( m_self ) delete m_self; #endif if( m_stack ) if( m_stack ) free( m_stack ); free( m_stack ); } } Loading @@ -101,7 +107,7 @@ public: */ */ void Yield() void Yield() { { boost::context::jump_fcontext( m_self, m_saved, 0 ); jump( m_self, m_saved, 0 ); } } /** /** Loading @@ -113,7 +119,7 @@ public: void Yield( ReturnType& aRetVal ) void Yield( ReturnType& aRetVal ) { { m_retVal = aRetVal; m_retVal = aRetVal; boost::context::jump_fcontext( m_self, m_saved, 0 ); jump( m_self, m_saved, 0 ); } } /** /** Loading Loading @@ -147,12 +153,17 @@ public: assert( m_saved == NULL ); assert( m_saved == NULL ); m_args = &aArgs; m_args = &aArgs; #if BOOST_VERSION >= 105600 m_self = new boost::context::fcontext_t(); *m_self = boost::context::make_fcontext( sp, m_stackSize, callerStub ); #else m_self = boost::context::make_fcontext( sp, m_stackSize, callerStub ); m_self = boost::context::make_fcontext( sp, m_stackSize, callerStub ); #endif m_saved = new boost::context::fcontext_t(); m_saved = new boost::context::fcontext_t(); m_running = true; m_running = true; // off we go! // off we go! boost::context::jump_fcontext( m_saved, m_self, reinterpret_cast<intptr_t>( this ) ); jump( m_saved, m_self, reinterpret_cast<intptr_t>( this ) ); return m_running; return m_running; } } Loading @@ -165,7 +176,7 @@ public: */ */ bool Resume() bool Resume() { { boost::context::jump_fcontext( m_saved, m_self, 0 ); jump( m_saved, m_self, 0 ); return m_running; return m_running; } } Loading Loading @@ -204,7 +215,18 @@ private: cor->m_running = false; cor->m_running = false; // go back to wherever we came from. // go back to wherever we came from. boost::context::jump_fcontext( cor->m_self, cor->m_saved, 0 ); // reinterpret_cast<intptr_t>( this )); jump( cor->m_self, cor->m_saved, 0 ); // reinterpret_cast<intptr_t>( this )); } ///> Wrapper for jump_fcontext to assure compatibility between different boost versions static inline intptr_t jump(boost::context::fcontext_t* aOld, boost::context::fcontext_t* aNew, intptr_t aP, bool aPreserveFPU = true ) { #if BOOST_VERSION >= 105600 return boost::context::jump_fcontext( aOld, *aNew, aP, aPreserveFPU ); #else return boost::context::jump_fcontext( aOld, aNew, aP, aPreserveFPU ); #endif } } template <typename T> template <typename T> Loading