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