Fix crashes when logid starts as root
If logid scans every device, it will either SIGSEGV or not work at all. This commit should fix bug #100.
This commit is contained in:
@@ -31,7 +31,7 @@ task::task(const std::function<void()>& function,
|
||||
} catch(std::exception& e) {
|
||||
(*_exception_handler)(e);
|
||||
}
|
||||
})
|
||||
}), _future (_task_pkg.get_future())
|
||||
{
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ void task::run()
|
||||
_status_cv.notify_all();
|
||||
_task_pkg();
|
||||
_status = Completed;
|
||||
_status_cv.notify_all();
|
||||
}
|
||||
|
||||
task::Status task::getStatus()
|
||||
@@ -50,7 +51,13 @@ task::Status task::getStatus()
|
||||
|
||||
void task::wait()
|
||||
{
|
||||
_task_pkg.get_future().wait();
|
||||
if(_future.valid())
|
||||
_future.wait();
|
||||
else {
|
||||
std::mutex wait_start;
|
||||
std::unique_lock<std::mutex> lock(wait_start);
|
||||
_status_cv.wait(lock, [this](){ return _status == Completed; });
|
||||
}
|
||||
}
|
||||
|
||||
void task::waitStart()
|
||||
@@ -62,7 +69,7 @@ void task::waitStart()
|
||||
|
||||
std::future_status task::waitFor(std::chrono::milliseconds ms)
|
||||
{
|
||||
return _task_pkg.get_future().wait_for(ms);
|
||||
return _future.wait_for(ms);
|
||||
}
|
||||
|
||||
void task::spawn(const std::function<void ()>& function,
|
||||
|
@@ -62,6 +62,7 @@ namespace logid
|
||||
std::atomic<Status> _status;
|
||||
std::condition_variable _status_cv;
|
||||
std::packaged_task<void()> _task_pkg;
|
||||
std::future<void> _future;
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user