Commit 585a8091 authored by Dominik Charousset's avatar Dominik Charousset

all actors use `memory::create` instead of `new`

parent 4cdba90f
...@@ -58,7 +58,7 @@ class actor_companion_mixin : public Base { ...@@ -58,7 +58,7 @@ class actor_companion_mixin : public Base {
template<typename... Args> template<typename... Args>
actor_companion_mixin(Args&&... args) : super(std::forward<Args>(args)...) { actor_companion_mixin(Args&&... args) : super(std::forward<Args>(args)...) {
m_self.reset(new companion(this)); m_self.reset(detail::memory::create<companion>(this));
} }
~actor_companion_mixin() { ~actor_companion_mixin() {
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "cppa/event_based_actor.hpp" #include "cppa/event_based_actor.hpp"
#include "cppa/detail/tdata.hpp" #include "cppa/detail/tdata.hpp"
#include "cppa/detail/memory.hpp"
#include "cppa/util/type_list.hpp" #include "cppa/util/type_list.hpp"
namespace cppa { namespace detail { namespace cppa { namespace detail {
...@@ -103,7 +104,7 @@ class event_based_actor_factory { ...@@ -103,7 +104,7 @@ class event_based_actor_factory {
template<typename... Args> template<typename... Args>
actor_ptr spawn(Args&&... args) { actor_ptr spawn(Args&&... args) {
return get_scheduler()->spawn(new impl(m_init, m_on_exit, return get_scheduler()->spawn(memory::create<impl>(m_init, m_on_exit,
std::forward<Args>(args)...)); std::forward<Args>(args)...));
} }
......
...@@ -127,10 +127,12 @@ class scheduler_helper { ...@@ -127,10 +127,12 @@ class scheduler_helper {
typedef intrusive_ptr<thread_mapped_actor> ptr_type; typedef intrusive_ptr<thread_mapped_actor> ptr_type;
void start() { void start() {
ptr_type mtimer{new thread_mapped_actor}; ptr_type mtimer{detail::memory::create<thread_mapped_actor>()};
ptr_type mprinter{new thread_mapped_actor}; ptr_type mprinter{detail::memory::create<thread_mapped_actor>()};
// launch threads
m_timer_thread = std::thread(&scheduler_helper::timer_loop, mtimer); m_timer_thread = std::thread(&scheduler_helper::timer_loop, mtimer);
m_printer_thread = std::thread(&scheduler_helper::printer_loop, mprinter); m_printer_thread = std::thread(&scheduler_helper::printer_loop, mprinter);
// set member variables
m_timer = mtimer; m_timer = mtimer;
m_printer = mprinter; m_printer = mprinter;
} }
...@@ -291,9 +293,10 @@ void scheduler_helper::printer_loop(ptr_type m_self) { ...@@ -291,9 +293,10 @@ void scheduler_helper::printer_loop(ptr_type m_self) {
); );
} }
scheduler::scheduler() : m_helper(new scheduler_helper) { } scheduler::scheduler() : m_helper(nullptr) { }
void scheduler::initialize() { void scheduler::initialize() {
m_helper = new scheduler_helper;
m_helper->start(); m_helper->start();
} }
......
...@@ -44,7 +44,7 @@ pthread_key_t s_key; ...@@ -44,7 +44,7 @@ pthread_key_t s_key;
pthread_once_t s_key_once = PTHREAD_ONCE_INIT; pthread_once_t s_key_once = PTHREAD_ONCE_INIT;
local_actor* tss_constructor() { local_actor* tss_constructor() {
local_actor* result = new thread_mapped_actor; local_actor* result = detail::memory::create<thread_mapped_actor>();
result->ref(); result->ref();
get_scheduler()->register_converted_context(result); get_scheduler()->register_converted_context(result);
return result; return result;
......
...@@ -205,7 +205,7 @@ actor_ptr thread_pool_scheduler::spawn_as_thread(void_function fun, ...@@ -205,7 +205,7 @@ actor_ptr thread_pool_scheduler::spawn_as_thread(void_function fun,
init_callback cb, init_callback cb,
bool hidden) { bool hidden) {
if (!hidden) inc_actor_count(); if (!hidden) inc_actor_count();
thread_mapped_actor_ptr ptr{new thread_mapped_actor(std::move(fun))}; thread_mapped_actor_ptr ptr{detail::memory::create<thread_mapped_actor>(std::move(fun))};
ptr->init(); ptr->init();
ptr->initialized(true); ptr->initialized(true);
cb(ptr.get()); cb(ptr.get());
...@@ -257,7 +257,7 @@ actor_ptr thread_pool_scheduler::spawn(scheduled_actor* raw, ...@@ -257,7 +257,7 @@ actor_ptr thread_pool_scheduler::spawn(scheduled_actor* raw,
actor_ptr thread_pool_scheduler::spawn(void_function fun, scheduling_hint hint) { actor_ptr thread_pool_scheduler::spawn(void_function fun, scheduling_hint hint) {
if (hint == scheduled || hint == scheduled_and_hidden) { if (hint == scheduled || hint == scheduled_and_hidden) {
scheduled_actor_ptr ptr{new context_switching_actor(std::move(fun))}; scheduled_actor_ptr ptr{detail::memory::create<context_switching_actor>(std::move(fun))};
ptr->attach_to_scheduler(this, hint == scheduled_and_hidden); ptr->attach_to_scheduler(this, hint == scheduled_and_hidden);
return spawn_impl(std::move(ptr)); return spawn_impl(std::move(ptr));
} }
...@@ -267,11 +267,12 @@ actor_ptr thread_pool_scheduler::spawn(void_function fun, scheduling_hint hint) ...@@ -267,11 +267,12 @@ actor_ptr thread_pool_scheduler::spawn(void_function fun, scheduling_hint hint)
hint == detached_and_hidden); hint == detached_and_hidden);
} }
} }
actor_ptr thread_pool_scheduler::spawn(void_function fun, actor_ptr thread_pool_scheduler::spawn(void_function fun,
init_callback init_cb, init_callback init_cb,
scheduling_hint hint) { scheduling_hint hint) {
if (hint == scheduled || hint == scheduled_and_hidden) { if (hint == scheduled || hint == scheduled_and_hidden) {
scheduled_actor_ptr ptr{new context_switching_actor(std::move(fun))}; scheduled_actor_ptr ptr{detail::memory::create<context_switching_actor>(std::move(fun))};
ptr->attach_to_scheduler(this, hint == scheduled_and_hidden); ptr->attach_to_scheduler(this, hint == scheduled_and_hidden);
init_cb(ptr.get()); init_cb(ptr.get());
return spawn_impl(std::move(ptr)); return spawn_impl(std::move(ptr));
......
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