Fix CPU hog on async methods: Clear the event descriptor by reading from it (#16)

This commit is contained in:
Stanislav Angelovič
2018-07-24 12:54:31 +02:00
committed by Lukáš Ďurfina
parent d8fd053714
commit d3d698f02a
5 changed files with 58 additions and 12 deletions
+12 -4
View File
@@ -107,12 +107,20 @@ protected:
void doOperationAsync(uint32_t param, sdbus::Result<uint32_t> result)
{
// The same as doOperationSync, just written as an asynchronous method callback
std::thread([param, result = std::move(result)]()
if (param == 0)
{
std::this_thread::sleep_for(std::chrono::milliseconds(param));
// Don't sleep and return the result from this thread
result.returnResults(param);
}).detach();
}
else
{
// Process asynchronously in another thread and return the result from there
std::thread([param, result = std::move(result)]()
{
std::this_thread::sleep_for(std::chrono::milliseconds(param));
result.returnResults(param);
}).detach();
}
}
sdbus::Signature getSignature() const { return SIGNATURE_VALUE; }