1 //
2 //          Copyright Oliver Kowalke 2013.
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 
7 // based on boost.thread
8 
9 #ifndef BOOST_fiber_errorS_H
10 #define BOOST_fiber_errorS_H
11 
12 #include <future>
13 #include <stdexcept>
14 #include <string>
15 #include <system_error>
16 
17 #include <boost/config.hpp>
18 
19 #include <boost/fiber/detail/config.hpp>
20 
21 #ifdef BOOST_HAS_ABI_HEADERS
22 #  include BOOST_ABI_PREFIX
23 #endif
24 
25 namespace boost {
26 namespace fibers {
27 
28 class fiber_error : public std::system_error {
29 public:
fiber_error(std::error_code ec)30     fiber_error( std::error_code ec) :
31         std::system_error( ec) {
32     }
33 
fiber_error(std::error_code ec,const char * what_arg)34     fiber_error( std::error_code ec, const char * what_arg) :
35         std::system_error( ec, what_arg) {
36     }
37 
fiber_error(std::error_code ec,std::string const & what_arg)38     fiber_error( std::error_code ec, std::string const& what_arg) :
39         std::system_error( ec, what_arg) {
40     }
41 
42     virtual ~fiber_error() = default;
43 };
44 
45 class lock_error : public fiber_error {
46 public:
lock_error(std::error_code ec)47     lock_error( std::error_code ec) :
48         fiber_error( ec) {
49     }
50 
lock_error(std::error_code ec,const char * what_arg)51     lock_error( std::error_code ec, const char * what_arg) :
52         fiber_error( ec, what_arg) {
53     }
54 
lock_error(std::error_code ec,std::string const & what_arg)55     lock_error( std::error_code ec, std::string const& what_arg) :
56         fiber_error( ec, what_arg) {
57     }
58 };
59 
60 enum class future_errc {
61     broken_promise = 1,
62     future_already_retrieved,
63     promise_already_satisfied,
64     no_state
65 };
66 
67 BOOST_FIBERS_DECL
68 std::error_category const& future_category() noexcept;
69 
70 }}
71 
72 namespace std {
73 
74 template<>
75 struct is_error_code_enum< boost::fibers::future_errc > : public true_type {
76 };
77 
78 inline
make_error_code(boost::fibers::future_errc e)79 std::error_code make_error_code( boost::fibers::future_errc e) noexcept {
80     return std::error_code( static_cast< int >( e), boost::fibers::future_category() );
81 }
82 
83 inline
make_error_condition(boost::fibers::future_errc e)84 std::error_condition make_error_condition( boost::fibers::future_errc e) noexcept {
85     return std::error_condition( static_cast< int >( e), boost::fibers::future_category() );
86 }
87 
88 }
89 
90 namespace boost {
91 namespace fibers {
92 
93 class future_error : public fiber_error {
94 public:
future_error(std::error_code ec)95     future_error( std::error_code ec) :
96         fiber_error( ec) {
97     }
98 };
99 
100 class future_uninitialized : public future_error {
101 public:
future_uninitialized()102     future_uninitialized() :
103         future_error( std::make_error_code( future_errc::no_state) ) {
104     }
105 };
106 
107 class future_already_retrieved : public future_error {
108 public:
future_already_retrieved()109     future_already_retrieved() :
110         future_error( std::make_error_code( future_errc::future_already_retrieved) ) {
111     }
112 };
113 
114 class broken_promise : public future_error {
115 public:
broken_promise()116     broken_promise() :
117         future_error( std::make_error_code( future_errc::broken_promise) ) {
118     }
119 };
120 
121 class promise_already_satisfied : public future_error {
122 public:
promise_already_satisfied()123     promise_already_satisfied() :
124         future_error( std::make_error_code( future_errc::promise_already_satisfied) ) {
125     }
126 };
127 
128 class promise_uninitialized : public future_error {
129 public:
promise_uninitialized()130     promise_uninitialized() :
131         future_error( std::make_error_code( future_errc::no_state) ) {
132     }
133 };
134 
135 class packaged_task_uninitialized : public future_error {
136 public:
packaged_task_uninitialized()137     packaged_task_uninitialized() :
138         future_error( std::make_error_code( future_errc::no_state) ) {
139     }
140 };
141 
142 }}
143 
144 #ifdef BOOST_HAS_ABI_HEADERS
145 #  include BOOST_ABI_SUFFIX
146 #endif
147 
148 #endif // BOOST_fiber_errorS_H
149