Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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() {
+5 −1
Original line number Diff line number Diff line
@@ -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();
};