yield.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2003-2013 Christopher M. Kohlhoff
  2. // Copyright Oliver Kowalke, Nat Goodspeed 2015.
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_FIBERS_ASIO_YIELD_HPP
  7. #define BOOST_FIBERS_ASIO_YIELD_HPP
  8. #include <boost/config.hpp>
  9. #ifdef BOOST_HAS_ABI_HEADERS
  10. # include BOOST_ABI_PREFIX
  11. #endif
  12. namespace boost {
  13. namespace fibers {
  14. namespace asio {
  15. //[fibers_asio_yield_t
  16. class yield_t {
  17. public:
  18. yield_t() = default;
  19. /**
  20. * @code
  21. * static yield_t yield;
  22. * boost::system::error_code myec;
  23. * func(yield[myec]);
  24. * @endcode
  25. * @c yield[myec] returns an instance of @c yield_t whose @c ec_ points
  26. * to @c myec. The expression @c yield[myec] "binds" @c myec to that
  27. * (anonymous) @c yield_t instance, instructing @c func() to store any
  28. * @c error_code it might produce into @c myec rather than throwing @c
  29. * boost::system::system_error.
  30. */
  31. yield_t operator[]( boost::system::error_code & ec) const {
  32. yield_t tmp;
  33. tmp.ec_ = & ec;
  34. return tmp;
  35. }
  36. //private:
  37. // ptr to bound error_code instance if any
  38. boost::system::error_code * ec_{ nullptr };
  39. };
  40. //]
  41. //[fibers_asio_yield
  42. // canonical instance
  43. thread_local yield_t yield{};
  44. //]
  45. }}}
  46. #ifdef BOOST_HAS_ABI_HEADERS
  47. # include BOOST_ABI_SUFFIX
  48. #endif
  49. #include "detail/yield.hpp"
  50. #endif // BOOST_FIBERS_ASIO_YIELD_HPP