drm_hwcomposer: Join UEventListener thread on exit
Ensure that the UEventListener has cleanly stopped and joined in the destructor. Change-Id: I8e5068b67fcdc235870a8fdbbeb09d1dd8f25520
This commit is contained in:
parent
199e090920
commit
5cdddc176e
2 changed files with 20 additions and 12 deletions
|
|
@ -24,7 +24,16 @@
|
|||
|
||||
namespace android {
|
||||
|
||||
UEventListener::~UEventListener() {
|
||||
StopThread();
|
||||
thread_.join();
|
||||
}
|
||||
|
||||
void UEventListener::StopThread() {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
exit_ = true;
|
||||
}
|
||||
uevent_->Stop();
|
||||
}
|
||||
|
||||
|
|
@ -35,19 +44,13 @@ auto UEventListener::CreateInstance() -> std::shared_ptr<UEventListener> {
|
|||
if (!uel->uevent_)
|
||||
return {};
|
||||
|
||||
std::thread(&UEventListener::ThreadFn, uel.get(), uel).detach();
|
||||
|
||||
uel->thread_ = std::thread(&UEventListener::ThreadFn, uel.get());
|
||||
return uel;
|
||||
}
|
||||
|
||||
void UEventListener::ThreadFn(const std::shared_ptr<UEventListener> &uel) {
|
||||
// TODO(nobody): Rework code to allow stopping the thread (low priority)
|
||||
while (true) {
|
||||
if (uel.use_count() == 1)
|
||||
break;
|
||||
|
||||
auto uevent_str = uel->uevent_->ReadNext();
|
||||
|
||||
void UEventListener::ThreadFn() {
|
||||
while (!exit_) {
|
||||
auto uevent_str = uevent_->ReadNext();
|
||||
if (!hotplug_handler_ || !uevent_str)
|
||||
continue;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#include "utils/UEvent.h"
|
||||
|
||||
|
|
@ -24,7 +26,7 @@ namespace android {
|
|||
|
||||
class UEventListener {
|
||||
public:
|
||||
~UEventListener() = default;
|
||||
~UEventListener();
|
||||
|
||||
static auto CreateInstance() -> std::shared_ptr<UEventListener>;
|
||||
|
||||
|
|
@ -37,8 +39,11 @@ class UEventListener {
|
|||
private:
|
||||
UEventListener() = default;
|
||||
|
||||
void ThreadFn(const std::shared_ptr<UEventListener> &uel);
|
||||
void ThreadFn();
|
||||
|
||||
std::thread thread_;
|
||||
std::mutex mutex_;
|
||||
bool exit_ = false;
|
||||
std::unique_ptr<UEvent> uevent_;
|
||||
|
||||
std::function<void()> hotplug_handler_;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue