Commit 92a58cae authored by Dominik Charousset's avatar Dominik Charousset Committed by Dominik Charousset

Make BASP workers reference counted

parent 2a378bfc
...@@ -35,7 +35,9 @@ namespace io { ...@@ -35,7 +35,9 @@ namespace io {
namespace basp { namespace basp {
/// Deserializes payloads for BASP messages asynchronously. /// Deserializes payloads for BASP messages asynchronously.
class worker : public resumable, public remote_message_handler<worker> { class worker : public resumable,
public remote_message_handler<worker>,
public ref_counted {
public: public:
// -- friends ---------------------------------------------------------------- // -- friends ----------------------------------------------------------------
......
...@@ -54,6 +54,7 @@ void worker::launch(const node_id& last_hop, const basp::header& hdr, ...@@ -54,6 +54,7 @@ void worker::launch(const node_id& last_hop, const basp::header& hdr,
last_hop_ = last_hop; last_hop_ = last_hop;
memcpy(&hdr_, &hdr, sizeof(basp::header)); memcpy(&hdr_, &hdr, sizeof(basp::header));
payload_.assign(payload.begin(), payload.end()); payload_.assign(payload.begin(), payload.end());
ref();
system_->scheduler().enqueue(this); system_->scheduler().enqueue(this);
} }
...@@ -71,12 +72,11 @@ resumable::resume_result worker::resume(execution_unit* ctx, size_t) { ...@@ -71,12 +72,11 @@ resumable::resume_result worker::resume(execution_unit* ctx, size_t) {
} }
void worker::intrusive_ptr_add_ref_impl() { void worker::intrusive_ptr_add_ref_impl() {
// The basp::instance owns the hub (which owns this object) and must make ref();
// sure to wait for pending workers at exit.
} }
void worker::intrusive_ptr_release_impl() { void worker::intrusive_ptr_release_impl() {
// nop deref();
} }
} // namespace basp } // namespace basp
......
...@@ -35,7 +35,7 @@ worker_hub::~worker_hub() { ...@@ -35,7 +35,7 @@ worker_hub::~worker_hub() {
auto head = head_.load(); auto head = head_.load();
while (head != nullptr) { while (head != nullptr) {
auto next = head->next_.load(); auto next = head->next_.load();
delete head; head->intrusive_ptr_release_impl();
head = next; head = next;
} }
} }
......
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