Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59103 - trunk/libs/asio/example/http/server4
From: chris_at_[hidden]
Date: 2010-01-17 16:42:36


Author: chris_kohlhoff
Date: 2010-01-17 16:42:36 EST (Sun, 17 Jan 2010)
New Revision: 59103
URL: http://svn.boost.org/trac/boost/changeset/59103

Log:
Add coroutine::is_complete() and support for "yield break;".

Text files modified:
   trunk/libs/asio/example/http/server4/coroutine.hpp | 21 +++++++++++++++------
   1 files changed, 15 insertions(+), 6 deletions(-)

Modified: trunk/libs/asio/example/http/server4/coroutine.hpp
==============================================================================
--- trunk/libs/asio/example/http/server4/coroutine.hpp (original)
+++ trunk/libs/asio/example/http/server4/coroutine.hpp 2010-01-17 16:42:36 EST (Sun, 17 Jan 2010)
@@ -17,6 +17,7 @@
   coroutine() : value_(0) {}
   bool is_child() const { return value_ < 0; }
   bool is_parent() const { return !is_child(); }
+ bool is_complete() const { return value_ == -1; }
 private:
   friend class coroutine_ref;
   int value_;
@@ -25,19 +26,24 @@
 class coroutine_ref
 {
 public:
- coroutine_ref(coroutine& c) : value_(c.value_) {}
- coroutine_ref(coroutine* c) : value_(c->value_) {}
+ coroutine_ref(coroutine& c) : value_(c.value_), modified_(false) {}
+ coroutine_ref(coroutine* c) : value_(c->value_), modified_(false) {}
+ ~coroutine_ref() { if (!modified_) value_ = -1; }
   operator int() const { return value_; }
- int& operator=(int v) { return value_ = v; }
+ int& operator=(int v) { modified_ = true; return value_ = v; }
 private:
   void operator=(const coroutine_ref&);
   int& value_;
+ bool modified_;
 };
 
 #define CORO_REENTER(c) \
   switch (coroutine_ref _coro_value = c) \
     case -1: if (_coro_value) \
     { \
+ goto terminate_coroutine; \
+ terminate_coroutine: \
+ _coro_value = -1; \
       goto bail_out_of_coroutine; \
       bail_out_of_coroutine: \
       break; \
@@ -54,9 +60,12 @@
     else \
       switch (_coro_value ? 0 : 1) \
         for (;;) \
- case 1: if (_coro_value) \
- goto bail_out_of_coroutine; \
- else case 0:
+ case -1: if (_coro_value) \
+ goto terminate_coroutine; \
+ else for (;;) \
+ case 1: if (_coro_value) \
+ goto bail_out_of_coroutine; \
+ else case 0:
 
 #define CORO_FORK \
   for (_coro_value = -__LINE__;; _coro_value = __LINE__) \


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