Commit ffd73d2a authored by neverlord's avatar neverlord

Merge branch 'master' of github.com:Neverlord/libcppa

parents cfcfedfb 0242637b
...@@ -11,6 +11,7 @@ namespace cppa { ...@@ -11,6 +11,7 @@ namespace cppa {
class context; class context;
class actor_behavior; class actor_behavior;
class scheduler_helper;
/** /**
* @brief * @brief
...@@ -18,8 +19,12 @@ class actor_behavior; ...@@ -18,8 +19,12 @@ class actor_behavior;
class scheduler class scheduler
{ {
scheduler_helper* m_helper;
protected: protected:
scheduler();
/** /**
* @brief Calls {@link context::exit(std::uint32_t) context::exit}. * @brief Calls {@link context::exit(std::uint32_t) context::exit}.
*/ */
......
...@@ -8,14 +8,15 @@ ...@@ -8,14 +8,15 @@
#include "cppa/context.hpp" #include "cppa/context.hpp"
#include "cppa/scheduler.hpp" #include "cppa/scheduler.hpp"
#include "cppa/detail/actor_count.hpp" #include "cppa/detail/actor_count.hpp"
//#include "cppa/detail/mock_scheduler.hpp" #include "cppa/detail/mock_scheduler.hpp"
#include "cppa/detail/thread_pool_scheduler.hpp" #include "cppa/detail/thread_pool_scheduler.hpp"
#include "cppa/detail/converted_thread_context.hpp"
namespace { namespace {
//std::mutex m_instance_mtx;
std::atomic<cppa::scheduler*> m_instance; std::atomic<cppa::scheduler*> m_instance;
/*
struct static_cleanup_helper struct static_cleanup_helper
{ {
~static_cleanup_helper() ~static_cleanup_helper()
...@@ -32,13 +33,46 @@ struct static_cleanup_helper ...@@ -32,13 +33,46 @@ struct static_cleanup_helper
} }
} }
s_cleanup_helper; s_cleanup_helper;
*/
} // namespace <anonymous> } // namespace <anonymous>
namespace cppa { namespace cppa {
class scheduler_helper
{
cppa::intrusive_ptr<cppa::context> m_worker;
static void worker_loop(cppa::intrusive_ptr<cppa::context> m_self);
public:
scheduler_helper() : m_worker(new detail::converted_thread_context)
{
// do NOT increase actor count; worker is "invisible"
boost::thread(&scheduler_helper::worker_loop, m_worker).detach();
}
~scheduler_helper()
{
m_worker->enqueue(message(m_worker, m_worker, atom(":_DIE")));
}
};
void scheduler_helper::worker_loop(cppa::intrusive_ptr<cppa::context> m_self)
{
set_self(m_self.get());
}
scheduler::scheduler() : m_helper(new scheduler_helper)
{
}
scheduler::~scheduler() scheduler::~scheduler()
{ {
delete m_helper;
} }
void scheduler::await_others_done() void scheduler::await_others_done()
...@@ -71,7 +105,7 @@ void set_scheduler(scheduler* sched) ...@@ -71,7 +105,7 @@ void set_scheduler(scheduler* sched)
scheduler* s = nullptr; scheduler* s = nullptr;
if (m_instance.compare_exchange_weak(s, sched) == false) if (m_instance.compare_exchange_weak(s, sched) == false)
{ {
throw std::runtime_error("cannot set scheduler"); throw std::runtime_error("scheduler already set");
} }
} }
......
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