Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

valgrind: fix leaks of aio_provider #180

Merged
merged 6 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/core/tools/common/native_aio_provider.linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,17 @@ native_linux_aio_provider::~native_linux_aio_provider()
{
auto ret = io_destroy(_ctx);
dassert(ret == 0, "io_destroy error, ret = %d", ret);

if (!_is_running) {
return;
}
_is_running = false;
_worker.join();
}

void native_linux_aio_provider::start()
{
_is_running = true;
_worker = std::thread([this]() {
task::set_tls_dsn_context(node(), nullptr);
get_event();
Expand Down Expand Up @@ -119,6 +126,9 @@ void native_linux_aio_provider::get_event()
task_worker::set_name(buffer);

while (true) {
if (dsn_unlikely(!_is_running.load(std::memory_order_relaxed))) {
break;
}
ret = io_getevents(_ctx, 1, 1, events, NULL);
if (ret > 0) // should be 1
{
Expand Down Expand Up @@ -221,6 +231,7 @@ error_code native_linux_aio_provider::aio_internal(aio_task *aio_tsk,
}
}
}
}
} // end namespace dsn::tools

} // namespace tools
} // namespace dsn
#endif
17 changes: 3 additions & 14 deletions src/core/tools/common/native_aio_provider.linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,8 @@
* THE SOFTWARE.
*/

/*
* Description:
* What is this file about?
*
* Revision history:
* xxxx-xx-xx, author, first version
* xxxx-xx-xx, author, fix bug about xxx
*/

#pragma once

#ifdef __linux__

#include <dsn/tool_api.h>
#include <dsn/utility/synchronize.h>
#include <queue>
Expand Down Expand Up @@ -81,9 +70,9 @@ class native_linux_aio_provider : public aio_provider

private:
io_context_t _ctx;
std::atomic<bool> _is_running{false};
std::thread _worker;
};
}
}

#endif
} // namespace tools
} // namespace dsn
Loading