Skip to content
Snippets Groups Projects
Commit 1cdb2fab authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

InputTracer: Ensure tracer thread is destructed first

InputThread stops when its destructor is called. Initialize it
last in ThreadedBackend so that it is the first thing to be
destructed. This will guarantee the thread will not access other
members that have already been destructed.

Bug: 330211703
Change-Id: Ia50585d8276fe87d40d5528b3eb9480a64ea9854
Test: None
parent 8127c23d
No related branches found
No related tags found
No related merge requests found
......@@ -38,10 +38,10 @@ struct Visitor : V... {
template <typename Backend>
ThreadedBackend<Backend>::ThreadedBackend(Backend&& innerBackend)
: mTracerThread(
: mBackend(std::move(innerBackend)),
mTracerThread(
"InputTracer", [this]() { threadLoop(); },
[this]() { mThreadWakeCondition.notify_all(); }),
mBackend(std::move(innerBackend)) {}
[this]() { mThreadWakeCondition.notify_all(); }) {}
template <typename Backend>
ThreadedBackend<Backend>::~ThreadedBackend() {
......
......@@ -44,7 +44,6 @@ public:
private:
std::mutex mLock;
InputThread mTracerThread;
bool mThreadExit GUARDED_BY(mLock){false};
std::condition_variable mThreadWakeCondition;
Backend mBackend;
......@@ -53,6 +52,11 @@ private:
TracedEventArgs>;
std::vector<TraceEntry> mQueue GUARDED_BY(mLock);
// InputThread stops when its destructor is called. Initialize it last so that it is the
// first thing to be destructed. This will guarantee the thread will not access other
// members that have already been destructed.
InputThread mTracerThread;
void threadLoop();
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment