rovo89/XposedBridge — pull request #24 by cryptyk (2014-09-05 05:43:29+00:00)
Title: Thread safety:  The settings file could be considered loaded before the map is available

The scenario [that actually occurred in my code]:
1) I call prefs.reload();
2) mLoaded is set to false, and a thread (THREAD_2) is started to start loading the prefs file.
3) I call prefs.getBoolean("pref_name", false); //the actual value of "pref_name" in the settings file is true.
4) getBoolean calls awaitLoadedLocked(), which spins waiting for mLoaded to be true before it accesses the mMap.
5) THREAD_2 dutifully loads the prefs file, but sets mLoaded to true just slightly before mMap is available.
6) Since mLoaded is true, awaitLoadedLocked() finishes and getBoolean accesses mMap. Of course it doesn't find the key and returns the default value
7) THREAD_2 sets mMap to the map containing the file contents.

The fix is simple: Don't set mLoaded to true until after mMap has been set.