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 {
template<typename... 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() {
......
......@@ -37,6 +37,7 @@
#include "cppa/event_based_actor.hpp"
#include "cppa/detail/tdata.hpp"
#include "cppa/detail/memory.hpp"
#include "cppa/util/type_list.hpp"
namespace cppa { namespace detail {
......@@ -103,8 +104,8 @@ class event_based_actor_factory {
template<typename... Args>
actor_ptr spawn(Args&&... args) {
return get_scheduler()->spawn(new impl(m_init, m_on_exit,
std::forward<Args>(args)...));
return get_scheduler()->spawn(memory::create<impl>(m_init, m_on_exit,
std::forward<Args>(args)...));
}
private:
......
......@@ -127,10 +127,12 @@ class scheduler_helper {
typedef intrusive_ptr<thread_mapped_actor> ptr_type;
void start() {
ptr_type mtimer{new thread_mapped_actor};
ptr_type mprinter{new thread_mapped_actor};
ptr_type mtimer{detail::memory::create<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_printer_thread = std::thread(&scheduler_helper::printer_loop, mprinter);
// set member variables
m_timer = mtimer;
m_printer = mprinter;
}
......@@ -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() {
m_helper = new scheduler_helper;
m_helper->start();
}
......
......@@ -44,7 +44,7 @@ pthread_key_t s_key;
pthread_once_t s_key_once = PTHREAD_ONCE_INIT;
local_actor* tss_constructor() {
local_actor* result = new thread_mapped_actor;
local_actor* result = detail::memory::create<thread_mapped_actor>();
result->ref();
get_scheduler()->register_converted_context(result);
return result;
......
......@@ -205,7 +205,7 @@ actor_ptr thread_pool_scheduler::spawn_as_thread(void_function fun,
init_callback cb,
bool hidden) {
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->initialized(true);
cb(ptr.get());
......@@ -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) {
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);
return spawn_impl(std::move(ptr));
}
......@@ -267,11 +267,12 @@ actor_ptr thread_pool_scheduler::spawn(void_function fun, scheduling_hint hint)
hint == detached_and_hidden);
}
}
actor_ptr thread_pool_scheduler::spawn(void_function fun,
init_callback init_cb,
scheduling_hint hint) {
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);
init_cb(ptr.get());
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