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.
This commit is contained in:
Thomas Zimmermann 2014-11-17 10:23:49 +01:00
parent b73863ab04
commit 7fffbfb146

View File

@ -10,6 +10,7 @@
#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"
@ -19,6 +20,8 @@
#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
@ -161,9 +164,10 @@ public:
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;