Commit 7feab2ad authored by Dominik Charousset's avatar Dominik Charousset

added runtime-check to spawn for fiber impl

this patch adds a new static member function to `fiber` that
queries whether libcppa was compiled without fiber support
parent 776fa09f
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
#include "cppa/typed_actor.hpp" #include "cppa/typed_actor.hpp"
#include "cppa/spawn_options.hpp" #include "cppa/spawn_options.hpp"
#include "cppa/util/fiber.hpp"
#include "cppa/detail/proper_actor.hpp" #include "cppa/detail/proper_actor.hpp"
#include "cppa/detail/functor_based_actor.hpp" #include "cppa/detail/functor_based_actor.hpp"
#include "cppa/detail/implicit_conversions.hpp" #include "cppa/detail/implicit_conversions.hpp"
...@@ -65,6 +67,15 @@ actor spawn_impl(BeforeLaunch before_launch_fun, Ts&&... args) { ...@@ -65,6 +67,15 @@ actor spawn_impl(BeforeLaunch before_launch_fun, Ts&&... args) {
static_assert(is_unbound(Options), static_assert(is_unbound(Options),
"top-level spawns cannot have monitor or link flag"); "top-level spawns cannot have monitor or link flag");
CPPA_LOGF_TRACE("spawn " << detail::demangle<Impl>()); CPPA_LOGF_TRACE("spawn " << detail::demangle<Impl>());
// runtime check wheter context_switching_resume can be used,
// i.e., add the detached flag if libcppa compiled without fiber support
// when using the blocking API
if (has_blocking_api_flag(Options)
&& !has_detach_flag(Options)
&& util::fiber::is_disabled_feature()) {
return spawn_impl<Impl, Options + detached>(before_launch_fun,
std::forward<Ts>(args)...);
}
/* /*
using scheduling_policy = typename std::conditional< using scheduling_policy = typename std::conditional<
has_detach_flag(Options), has_detach_flag(Options),
...@@ -83,7 +94,7 @@ actor spawn_impl(BeforeLaunch before_launch_fun, Ts&&... args) { ...@@ -83,7 +94,7 @@ actor spawn_impl(BeforeLaunch before_launch_fun, Ts&&... args) {
typename std::conditional< typename std::conditional<
has_detach_flag(Options), has_detach_flag(Options),
policy::no_resume, policy::no_resume,
policy::no_resume //policy::context_switching_resume policy::context_switching_resume
>::type, >::type,
policy::event_based_resume policy::event_based_resume
>::type; >::type;
......
...@@ -35,16 +35,37 @@ namespace cppa { namespace util { ...@@ -35,16 +35,37 @@ namespace cppa { namespace util {
struct fiber_impl; struct fiber_impl;
/**
* @brief A 'lightweight thread' supporting manual context switching.
*/
struct fiber { struct fiber {
/**
* @brief Queries whether libcppa was compiled without
* fiber support on this platform.
*/
static bool is_disabled_feature();
/**
* @brief Creates a new fiber that describes stores the context
* of the calling (kernel) thread.
*/
fiber(); fiber();
/**
* @brief Creates a fiber that executes the given function @p func
* using the argument @p arg1.
*/
fiber(void (*func)(void*), void* arg1); fiber(void (*func)(void*), void* arg1);
~fiber(); ~fiber();
static void swap(fiber& from, fiber& to); /**
* @brief Swaps the context from @p source to @p target.
*/
static void swap(fiber& source, fiber& target);
// pimpl
fiber_impl* m_impl; fiber_impl* m_impl;
}; };
......
...@@ -47,6 +47,10 @@ void fiber::swap(fiber&, fiber&) { ...@@ -47,6 +47,10 @@ void fiber::swap(fiber&, fiber&) {
"CPPA_DISABLE_CONTEXT_SWITCHING"); "CPPA_DISABLE_CONTEXT_SWITCHING");
} }
bool fiber::is_disabled_feature() {
return true;
}
} } // namespace cppa::util } } // namespace cppa::util
#else // ifdef CPPA_DISABLE_CONTEXT_SWITCHING #else // ifdef CPPA_DISABLE_CONTEXT_SWITCHING
...@@ -192,6 +196,10 @@ fiber::~fiber() { ...@@ -192,6 +196,10 @@ fiber::~fiber() {
delete m_impl; delete m_impl;
} }
bool fiber::is_disabled_feature() {
return false;
}
} } // namespace cppa::util } } // namespace cppa::util
#endif // CPPA_DISABLE_CONTEXT_SWITCHING #endif // CPPA_DISABLE_CONTEXT_SWITCHING
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