|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r77321 - in trunk/libs/context: doc example/asio example/continuation example/enumerator test
From: oliver.kowalke_at_[hidden]
Date: 2012-03-13 05:06:39
Author: olli
Date: 2012-03-13 05:06:35 EDT (Tue, 13 Mar 2012)
New Revision: 77321
URL: http://svn.boost.org/trac/boost/changeset/77321
Log:
context: documentation update and check-functions in context public interface
Text files modified:
trunk/libs/context/doc/context_ref.qbk | 14 ++++++++++++++
trunk/libs/context/example/asio/continuation.h | 11 +++--------
trunk/libs/context/example/continuation/continuation.h | 9 ++-------
trunk/libs/context/example/enumerator/enumerator.h | 11 ++---------
trunk/libs/context/test/test_context.cpp | 31 +++++++++++++++++++++----------
5 files changed, 42 insertions(+), 34 deletions(-)
Modified: trunk/libs/context/doc/context_ref.qbk
==============================================================================
--- trunk/libs/context/doc/context_ref.qbk (original)
+++ trunk/libs/context/doc/context_ref.qbk 2012-03-13 05:06:35 EDT (Tue, 13 Mar 2012)
@@ -699,6 +699,20 @@
[[Throws:] [Nothing.]]
]
+[heading `bool is_started() const`]
+[variablelist
+[[Preconditions:] [`*this` is not a __not_a_context__.]]
+[[Effects:] [Returns `true` if context-function of `*this` has started.]]
+[[Throws:] [Nothing.]]
+]
+
+[heading `bool is_resumed() const`]
+[variablelist
+[[Preconditions:] [`*this` is not a __not_a_context__.]]
+[[Effects:] [Returns `true` if context-function of `*this` has resumed.]]
+[[Throws:] [Nothing.]]
+]
+
[heading `intptr_t start()`]
[variablelist
[[Preconditions:] [`*this` is not a __not_a_context__, `! is_complete()` and
Modified: trunk/libs/context/example/asio/continuation.h
==============================================================================
--- trunk/libs/context/example/asio/continuation.h (original)
+++ trunk/libs/context/example/asio/continuation.h 2012-03-13 05:06:35 EDT (Tue, 13 Mar 2012)
@@ -21,9 +21,8 @@
class continuation
{
private:
- boost::contexts::context ctx_;
+ boost::contexts::context ctx_;
boost::function< void( continuation &) > fn_;
- bool started_;
void trampoline_()
{ fn_( * this); }
@@ -34,16 +33,12 @@
& continuation::trampoline_, this,
boost::contexts::default_stacksize(),
boost::contexts::no_stack_unwind, boost::contexts::return_to_caller),
- fn_( fn), started_( false)
+ fn_( fn)
{}
void resume()
{
- if ( ! started_)
- {
- started_ = true;
- ctx_.start();
- }
+ if ( ! ctx_.is_started() ) ctx_.start();
else ctx_.resume();
}
Modified: trunk/libs/context/example/continuation/continuation.h
==============================================================================
--- trunk/libs/context/example/continuation/continuation.h (original)
+++ trunk/libs/context/example/continuation/continuation.h 2012-03-13 05:06:35 EDT (Tue, 13 Mar 2012)
@@ -23,7 +23,6 @@
private:
boost::contexts::context ctx_;
boost::function< void( continuation &) > fn_;
- bool started_;
void trampoline_()
{ fn_( * this); }
@@ -34,16 +33,12 @@
& continuation::trampoline_, this,
boost::contexts::default_stacksize(),
boost::contexts::no_stack_unwind, boost::contexts::return_to_caller),
- fn_( fn), started_( false)
+ fn_( fn)
{}
void resume()
{
- if ( ! started_)
- {
- started_ = true;
- ctx_.start();
- }
+ if ( ! ctx_.is_started() ) ctx_.start();
else ctx_.resume();
}
Modified: trunk/libs/context/example/enumerator/enumerator.h
==============================================================================
--- trunk/libs/context/example/enumerator/enumerator.h (original)
+++ trunk/libs/context/example/enumerator/enumerator.h 2012-03-13 05:06:35 EDT (Tue, 13 Mar 2012)
@@ -23,7 +23,6 @@
boost::contexts::context ctx_;
bool complete_;
bool do_unwind_;
- bool started_;
static void run( enumerator * self)
{ self->enumerate(); }
@@ -50,8 +49,7 @@
boost::contexts::default_stacksize(),
boost::contexts::no_stack_unwind, boost::contexts::return_to_caller),
complete_( false),
- do_unwind_( do_unwind),
- started_( false)
+ do_unwind_( do_unwind)
{}
~enumerator()
@@ -63,15 +61,10 @@
bool get( T & result)
{
intptr_t vp = 0;
- if ( ! started_)
- {
- started_ = true;
+ if ( ! ctx_.is_started() )
vp = ctx_.start();
- }
else
- {
vp = ctx_.resume();
- }
if ( vp) result = * reinterpret_cast< T * >( vp);
return ! ( complete_ || ctx_.is_complete() );
}
Modified: trunk/libs/context/test/test_context.cpp
==============================================================================
--- trunk/libs/context/test/test_context.cpp (original)
+++ trunk/libs/context/test/test_context.cpp 2012-03-13 05:06:35 EDT (Tue, 13 Mar 2012)
@@ -53,6 +53,7 @@
X x( str);
intptr_t vp = gctx.suspend( value1);
value1 = vp;
+ BOOST_ASSERT( gctx.is_running() );
gctx.suspend();
}
@@ -88,6 +89,7 @@
fn0,
boost::contexts::default_stacksize(),
boost::contexts::stack_unwind, boost::contexts::return_to_caller);
+ BOOST_CHECK( ! ctx.is_started() );
BOOST_CHECK( ! ctx.is_complete() );
ctx.start();
BOOST_CHECK( ctx.is_complete() );
@@ -101,6 +103,7 @@
fn1, i,
boost::contexts::default_stacksize(),
boost::contexts::stack_unwind, boost::contexts::return_to_caller);
+ BOOST_CHECK( ! ctx.is_started() );
BOOST_CHECK( ! ctx.is_complete() );
ctx.start();
BOOST_CHECK( ctx.is_complete() );
@@ -114,6 +117,7 @@
fn2, "abc",
boost::contexts::default_stacksize(),
boost::contexts::stack_unwind, boost::contexts::return_to_caller);
+ BOOST_CHECK( ! ctx.is_started() );
BOOST_CHECK( ! ctx.is_complete() );
ctx.start();
BOOST_CHECK( ctx.is_complete() );
@@ -129,17 +133,21 @@
fn3, "abc",
boost::contexts::default_stacksize(),
boost::contexts::stack_unwind, boost::contexts::return_to_caller);
+ BOOST_CHECK( ! gctx.is_started() );
BOOST_CHECK( ! gctx.is_complete() );
intptr_t vp = gctx.start();
+ BOOST_CHECK( gctx.is_started() );
+ BOOST_CHECK( ! gctx.is_resumed() );
+ BOOST_CHECK( ! gctx.is_complete() );
BOOST_CHECK_EQUAL( vp, value1);
BOOST_CHECK_EQUAL( 1, value1);
- BOOST_CHECK( ! gctx.is_complete() );
int x = 7;
vp = 0;
vp = gctx.resume( x);
BOOST_CHECK_EQUAL( 7, value1);
BOOST_CHECK( ! vp);
BOOST_CHECK( ! gctx.is_complete() );
+ BOOST_CHECK( gctx.is_resumed() );
BOOST_CHECK_EQUAL( std::string(""), value3);
gctx.unwind_stack();
BOOST_CHECK( gctx.is_complete() );
@@ -158,21 +166,23 @@
boost::contexts::context ctx1(
fn4, "abc", "xyz",
boost::contexts::default_stacksize(),
- boost::contexts::stack_unwind, boost::contexts::return_to_caller);
+ boost::contexts::stack_unwind,
+ boost::contexts::return_to_caller);
boost::contexts::context ctx2(
fn1, 7,
boost::contexts::default_stacksize(),
- boost::contexts::stack_unwind, ctx1);
+ boost::contexts::stack_unwind,
+ ctx1);
BOOST_CHECK( ! ctx1.is_complete() );
BOOST_CHECK( ! ctx2.is_complete() );
ctx2.start();
-// BOOST_CHECK( ctx1.is_complete() );
-// BOOST_CHECK( ctx2.is_complete() );
-//
-// BOOST_CHECK_EQUAL( 7, value1);
-// BOOST_CHECK_EQUAL( "abc", value2);
-// BOOST_CHECK_EQUAL( "xyz", value3);
+ BOOST_CHECK( ctx1.is_complete() );
+ BOOST_CHECK( ctx2.is_complete() );
+
+ BOOST_CHECK_EQUAL( 7, value1);
+ BOOST_CHECK_EQUAL( "abc", value2);
+ BOOST_CHECK_EQUAL( "xyz", value3);
}
void test_case_7()
@@ -180,7 +190,8 @@
boost::contexts::context ctx(
fn5, 7.34,
boost::contexts::default_stacksize(),
- boost::contexts::stack_unwind, boost::contexts::return_to_caller);
+ boost::contexts::stack_unwind,
+ boost::contexts::return_to_caller);
BOOST_CHECK( ! ctx.is_complete() );
ctx.start();
BOOST_CHECK( ctx.is_complete() );
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