Bug 1053173: Use |LazyIdleThread| for FM tuning, r=mwu
authorThomas Zimmermann <tdz@users.sourceforge.net>
Mon, 17 Nov 2014 10:23:49 +0100
changeset 240350 3d4cf044cf6b17e8ce841297a8e28286300b1c10
parent 240349 d0ec4a4eeae0c4e33e6ec059c541f6b5acba0fb0
child 240351 d696cfef766a8bb97e8b01a6bd0e2822e5d96fbb
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu
bugs1053173
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1053173: Use |LazyIdleThread| for FM tuning, r=mwu FM tuning is performed rarely, usually only when switching stations on the radio, or at irregular intervals. Most of the time, the FM tune thread is idle. This patch converts the FM tune thread to be a |LazyIdleThread|. It get's cleaned up after a small timeout (currently 5 seconds), so it won't occupy resources while the user is actually listening to the radio.
dom/fmradio/FMRadioService.cpp
--- a/dom/fmradio/FMRadioService.cpp
+++ b/dom/fmradio/FMRadioService.cpp
@@ -5,25 +5,28 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "FMRadioService.h"
 #include "mozilla/Hal.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "nsIAudioManager.h"
 #include "AudioManager.h"
 #include "nsDOMClassInfo.h"
+#include "mozilla/LazyIdleThread.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/dom/FMRadioChild.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "nsIObserverService.h"
 #include "nsISettingsService.h"
 #include "nsJSUtils.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/SettingChangeNotificationBinding.h"
 
+#define TUNE_THREAD_TIMEOUT_MS  5000
+
 #define BAND_87500_108000_kHz 1
 #define BAND_76000_108000_kHz 2
 #define BAND_76000_90000_kHz  3
 
 #define MOZSETTINGS_CHANGED_ID "mozsettings-changed"
 #define SETTING_KEY_AIRPLANEMODE_ENABLED "airplaneMode.enabled"
 
 #define DOM_PARSED_RDS_GROUPS ((0x2 << 30) | (0x3 << 4) | (0x3 << 0))
@@ -156,19 +159,20 @@ public:
     info.lowerLimit() = mLowerLimit;
     info.spaceType() = mSpaceType;
     info.preEmphasis() = mPreemphasis;
 
     EnableFMRadio(info);
 
     FMRadioService* fmRadioService = FMRadioService::Singleton();
     if (!fmRadioService->mTuneThread) {
-      // SeekRunnable and SetFrequencyRunnable run on this thread.
-      // These call ioctls that can stall the main thread, so we run them here.
-      NS_NewNamedThread("FM Tuning", getter_AddRefs(fmRadioService->mTuneThread));
+      // SeekRunnable and SetFrequencyRunnable run on this thread. These
+      // call ioctls that can stall the main thread, so we run them here.
+      fmRadioService->mTuneThread = new LazyIdleThread(
+        TUNE_THREAD_TIMEOUT_MS, NS_LITERAL_CSTRING("FM Tuning"));
     }
 
     return NS_OK;
   }
 
 private:
   uint32_t mUpperLimit;
   uint32_t mLowerLimit;