Fix wrong initialization order in FAdviser
FAdviser declares thread_ before mutex_. This can cause a race leading
to crash when we start the thread_ (in the initializer list) and the
new thread tries to acquire mutex_ before it is initialized.
Now, we declare mutex_ before thread_ ensuring that mutex_ will always
be initialized before thread_ runs.
Test: m
Bug: 154416156
Change-Id: I9a6ab9bf744c2158fdf14a03c70fe95cf9ad61bc
diff --git a/jni/FuseDaemon.cpp b/jni/FuseDaemon.cpp
index 9a27c5b..0bc19f1 100644
--- a/jni/FuseDaemon.cpp
+++ b/jni/FuseDaemon.cpp
@@ -129,8 +129,6 @@
void Close(int fd) { SendMessage(Message::close, fd); }
private:
- std::thread thread_;
-
struct Message {
enum Type { record, close, quit };
Type type;
@@ -218,8 +216,9 @@
cv_.notify_one();
}
- std::queue<Message> queue_;
std::mutex mutex_;
+ std::thread thread_;
+ std::queue<Message> queue_;
std::condition_variable cv_;
typedef std::multimap<size_t, int> Sizes;