Commit e72725b5 authored by Dominik Charousset's avatar Dominik Charousset

new function: to_string(detail::yield_state)

parent bf30622e
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#ifndef CPPA_YIELD_INTERFACE_HPP #ifndef CPPA_YIELD_INTERFACE_HPP
#define CPPA_YIELD_INTERFACE_HPP #define CPPA_YIELD_INTERFACE_HPP
#include <string>
#include "cppa/util/fiber.hpp" #include "cppa/util/fiber.hpp"
namespace cppa { namespace detail { namespace cppa { namespace detail {
...@@ -54,4 +56,10 @@ yield_state call(util::fiber* what, util::fiber* from); ...@@ -54,4 +56,10 @@ yield_state call(util::fiber* what, util::fiber* from);
} } // namespace cppa::detail } } // namespace cppa::detail
namespace cppa {
std::string to_string(detail::yield_state ys);
} // namespace cppa
#endif // CPPA_YIELD_INTERFACE_HPP #endif // CPPA_YIELD_INTERFACE_HPP
...@@ -40,6 +40,13 @@ __thread detail::yield_state* t_ystate = nullptr; ...@@ -40,6 +40,13 @@ __thread detail::yield_state* t_ystate = nullptr;
__thread util::fiber* t_caller = nullptr; __thread util::fiber* t_caller = nullptr;
__thread util::fiber* t_callee = nullptr; __thread util::fiber* t_callee = nullptr;
constexpr const char* names_table[] = {
"yield_state::invalid",
"yield_state::ready",
"yield_state::blocked",
"yield_state::done"
};
} // namespace <anonymous> } // namespace <anonymous>
namespace cppa { namespace detail { namespace cppa { namespace detail {
...@@ -59,3 +66,12 @@ yield_state call(util::fiber* what, util::fiber* from) { ...@@ -59,3 +66,12 @@ yield_state call(util::fiber* what, util::fiber* from) {
} }
} } // namespace cppa::detail } } // namespace cppa::detail
namespace cppa {
std::string to_string(detail::yield_state ys) {
auto i = static_cast<size_t>(ys);
return (i < sizeof(names_table)) ? names_table[i] : "{illegal yield_state}";
}
} // namespace cppa
...@@ -8,28 +8,6 @@ ...@@ -8,28 +8,6 @@
#include "cppa/util/fiber.hpp" #include "cppa/util/fiber.hpp"
#include "cppa/detail/yield_interface.hpp" #include "cppa/detail/yield_interface.hpp"
#include <boost/context/all.hpp>
namespace cppa { namespace detail {
std::ostream& operator<<(std::ostream& o, yield_state ys) {
switch (ys) {
case yield_state::invalid:
return (o << "yield_state::invalid");
case yield_state::ready:
return (o << "yield_state::ready");
case yield_state::blocked:
return (o << "yield_state::blocked");
case yield_state::done:
return (o << "yield_state::done");
default:
return (o << "{{{invalid yield_state}}}");
}
}
} } // namespace cppa::detail
using namespace cppa; using namespace cppa;
using namespace cppa::util; using namespace cppa::util;
using namespace cppa::detail; using namespace cppa::detail;
...@@ -55,8 +33,7 @@ struct pseudo_worker { ...@@ -55,8 +33,7 @@ struct pseudo_worker {
}; };
void coroutine(void* worker) { (*reinterpret_cast<pseudo_worker*>(worker))(); void coroutine(void* worker) { (*reinterpret_cast<pseudo_worker*>(worker))(); }
}
size_t test__yield_interface() { size_t test__yield_interface() {
CPPA_TEST(test__yield_interface); CPPA_TEST(test__yield_interface);
...@@ -76,7 +53,7 @@ size_t test__yield_interface() { ...@@ -76,7 +53,7 @@ size_t test__yield_interface() {
++i; ++i;
} }
while (ys != yield_state::done && i < 12); while (ys != yield_state::done && i < 12);
CPPA_CHECK_EQUAL(yield_state::done, ys); CPPA_CHECK_EQUAL("yield_state::done", to_string(ys));
CPPA_CHECK_EQUAL(10, worker.m_count); CPPA_CHECK_EQUAL(10, worker.m_count);
CPPA_CHECK_EQUAL(12, i); CPPA_CHECK_EQUAL(12, i);
# endif # endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment