Bug 1350169 - Part 2. Remove Alarm API backend from HAL. r?gsvelto
By
bug 130884, we removed alarm API, so we should remove alarm backend from HAL.
MozReview-Commit-ID: EBiMJSUfUHu
--- a/hal/Hal.cpp
+++ b/hal/Hal.cpp
@@ -845,53 +845,16 @@ NotifySwitchChange(const SwitchEvent& aE
// first. We should check if this pointer is valid.
if (!sSwitchObserverLists)
return;
SwitchObserverList& observer = GetSwitchObserverList(aEvent.device());
observer.Broadcast(aEvent);
}
-static AlarmObserver* sAlarmObserver;
-
-bool
-RegisterTheOneAlarmObserver(AlarmObserver* aObserver)
-{
- MOZ_ASSERT(!InSandbox());
- MOZ_ASSERT(!sAlarmObserver);
-
- sAlarmObserver = aObserver;
- RETURN_PROXY_IF_SANDBOXED(EnableAlarm(), false);
-}
-
-void
-UnregisterTheOneAlarmObserver()
-{
- if (sAlarmObserver) {
- sAlarmObserver = nullptr;
- PROXY_IF_SANDBOXED(DisableAlarm());
- }
-}
-
-void
-NotifyAlarmFired()
-{
- if (sAlarmObserver) {
- sAlarmObserver->Notify(void_t());
- }
-}
-
-bool
-SetAlarm(int32_t aSeconds, int32_t aNanoseconds)
-{
- // It's pointless to program an alarm nothing is going to observe ...
- MOZ_ASSERT(sAlarmObserver);
- RETURN_PROXY_IF_SANDBOXED(SetAlarm(aSeconds, aNanoseconds), false);
-}
-
void
SetProcessPriority(int aPid, ProcessPriority aPriority, uint32_t aLRU)
{
// n.b. The sandboxed implementation crashes; SetProcessPriority works only
// from the main process.
PROXY_IF_SANDBOXED(SetProcessPriority(aPid, aPriority, aLRU));
}
--- a/hal/Hal.h
+++ b/hal/Hal.h
@@ -37,18 +37,16 @@ class nsPIDOMWindowInner;
# define MOZ_HAL_NAMESPACE hal
# define MOZ_DEFINED_HAL_NAMESPACE 1
#endif
namespace mozilla {
namespace hal {
-typedef Observer<void_t> AlarmObserver;
-
class WindowIdentifier;
typedef Observer<int64_t> SystemClockChangeObserver;
typedef Observer<SystemTimezoneChangeInformation> SystemTimezoneChangeObserver;
} // namespace hal
namespace MOZ_HAL_NAMESPACE {
@@ -428,51 +426,16 @@ hal::SwitchState GetCurrentSwitchState(h
/**
* Notify switch status change from input device.
*/
void NotifySwitchStateFromInputDevice(hal::SwitchDevice aDevice,
hal::SwitchState aState);
/**
- * Register an observer that is notified when a programmed alarm
- * expires.
- *
- * Currently, there can only be 0 or 1 alarm observers.
- */
-MOZ_MUST_USE bool RegisterTheOneAlarmObserver(hal::AlarmObserver* aObserver);
-
-/**
- * Unregister the alarm observer. Doing so will implicitly cancel any
- * programmed alarm.
- */
-void UnregisterTheOneAlarmObserver();
-
-/**
- * Notify that the programmed alarm has expired.
- *
- * This API is internal to hal; clients shouldn't call it directly.
- */
-void NotifyAlarmFired();
-
-/**
- * Program the real-time clock to expire at the time |aSeconds|,
- * |aNanoseconds|. These specify a point in real time relative to the
- * UNIX epoch. The alarm will fire at this time point even if the
- * real-time clock is changed; that is, this alarm respects changes to
- * the real-time clock. Return true iff the alarm was programmed.
- *
- * The alarm can be reprogrammed at any time.
- *
- * This API is currently only allowed to be used from non-sandboxed
- * contexts.
- */
-MOZ_MUST_USE bool SetAlarm(int32_t aSeconds, int32_t aNanoseconds);
-
-/**
* Set the priority of the given process.
*
* Exactly what this does will vary between platforms. On *nix we might give
* background processes higher nice values. On other platforms, we might
* ignore this call entirely.
*/
void SetProcessPriority(int aPid,
hal::ProcessPriority aPriority,
--- a/hal/HalInternal.h
+++ b/hal/HalInternal.h
@@ -60,26 +60,16 @@ void DisableScreenConfigurationNotificat
void EnableSwitchNotifications(hal::SwitchDevice aDevice);
/**
* Disable switch notifications from the backend
*/
void DisableSwitchNotifications(hal::SwitchDevice aDevice);
/**
- * Enable alarm notifications from the backend.
- */
-MOZ_MUST_USE bool EnableAlarm();
-
-/**
- * Disable alarm notifications from the backend.
- */
-void DisableAlarm();
-
-/**
* Enable system clock change notifications from the backend.
*/
void EnableSystemClockChangeNotifications();
/**
* Disable system clock change notifications from the backend.
*/
void DisableSystemClockChangeNotifications();
deleted file mode 100644
--- a/hal/fallback/FallbackAlarm.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "Hal.h"
-
-#include <algorithm>
-
-#include "mozilla/ClearOnShutdown.h"
-#include "mozilla/StaticPtr.h"
-#include "nsComponentManagerUtils.h"
-#include "nsITimer.h"
-#include "nsThreadUtils.h"
-
-namespace mozilla {
-namespace hal_impl {
-
-static void
-TimerCallbackFunc(nsITimer *aTimer, void *aClosure)
-{
- hal::NotifyAlarmFired();
-}
-
-static StaticRefPtr<nsITimer> sTimer;
-
-bool
-EnableAlarm()
-{
- static bool initialized = false;
- if (!initialized) {
- initialized = true;
- ClearOnShutdown(&sTimer);
- }
-
- nsCOMPtr<nsITimer> timer = do_CreateInstance("@mozilla.org/timer;1");
- sTimer = timer;
- MOZ_ASSERT(sTimer);
- return true;
-}
-
-void
-DisableAlarm()
-{
- /*
- * DisableAlarm() may be called after sTimer has been set to null by
- * ClearOnShutdown().
- */
- if (sTimer) {
- sTimer->Cancel();
- }
-}
-
-bool
-SetAlarm(int32_t aSeconds, int32_t aNanoseconds)
-{
- if (!sTimer) {
- MOZ_ASSERT(false, "We should have enabled the alarm");
- return false;
- }
-
- // Do the math to convert aSeconds and aNanoseconds into milliseconds since
- // the epoch.
- int64_t milliseconds = static_cast<int64_t>(aSeconds) * 1000 +
- static_cast<int64_t>(aNanoseconds) / 1000000;
-
- // nsITimer expects relative milliseconds.
- int64_t relMilliseconds = milliseconds - PR_Now() / 1000;
-
- // If the alarm time is in the past relative to PR_Now(),
- // we choose to immediately fire the alarm. Passing 0 means nsITimer will
- // queue a timeout event immediately.
- sTimer->InitWithFuncCallback(TimerCallbackFunc, nullptr,
- clamped<int64_t>(relMilliseconds, 0, INT32_MAX),
- nsITimer::TYPE_ONE_SHOT);
- return true;
-}
-
-} // namespace hal_impl
-} // namespace mozilla
--- a/hal/gonk/GonkHal.cpp
+++ b/hal/gonk/GonkHal.cpp
@@ -1110,96 +1110,16 @@ WaitForAlarm(void* aData)
NS_DispatchToMainThread(event);
}
}
pthread_cleanup_pop(1);
return nullptr;
}
-bool
-EnableAlarm()
-{
- MOZ_ASSERT(!sAlarmData);
-
- int alarmFd = open("/dev/alarm", O_RDWR);
- if (alarmFd < 0) {
- HAL_LOG("Failed to open alarm device: %s.", strerror(errno));
- return false;
- }
-
- UniquePtr<AlarmData> alarmData = MakeUnique<AlarmData>(alarmFd);
-
- struct sigaction actions;
- memset(&actions, 0, sizeof(actions));
- sigemptyset(&actions.sa_mask);
- actions.sa_flags = 0;
- actions.sa_handler = ShutDownAlarm;
- if (sigaction(SIGUSR1, &actions, nullptr)) {
- HAL_LOG("Failed to set SIGUSR1 signal for alarm-watcher thread.");
- return false;
- }
-
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
- int status = pthread_create(&sAlarmFireWatcherThread, &attr, WaitForAlarm,
- alarmData.get());
- if (status) {
- alarmData.reset();
- HAL_LOG("Failed to create alarm-watcher thread. Status: %d.", status);
- return false;
- }
-
- pthread_attr_destroy(&attr);
-
- // The thread owns this now. We only hold a pointer.
- sAlarmData = alarmData.release();
- return true;
-}
-
-void
-DisableAlarm()
-{
- MOZ_ASSERT(sAlarmData);
-
- // NB: this must happen-before the thread cancellation.
- sAlarmData = nullptr;
-
- // The cancel will interrupt the thread and destroy it, freeing the
- // data pointed at by sAlarmData.
- DebugOnly<int> err = pthread_kill(sAlarmFireWatcherThread, SIGUSR1);
- MOZ_ASSERT(!err);
-}
-
-bool
-SetAlarm(int32_t aSeconds, int32_t aNanoseconds)
-{
- if (!sAlarmData) {
- HAL_LOG("We should have enabled the alarm.");
- return false;
- }
-
- struct timespec ts;
- ts.tv_sec = aSeconds;
- ts.tv_nsec = aNanoseconds;
-
- // Currently we only support RTC wakeup alarm type.
- const int result = ioctl(sAlarmData->mFd,
- ANDROID_ALARM_SET(ANDROID_ALARM_RTC_WAKEUP), &ts);
-
- if (result < 0) {
- HAL_LOG("Unable to set alarm: %s.", strerror(errno));
- return false;
- }
-
- return true;
-}
-
static int
OomAdjOfOomScoreAdj(int aOomScoreAdj)
{
// Convert OOM adjustment from the domain of /proc/<pid>/oom_score_adj
// to the domain of /proc/<pid>/oom_adj.
int adj;
--- a/hal/moz.build
+++ b/hal/moz.build
@@ -39,17 +39,16 @@ SOURCES += [
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
LOCAL_INCLUDES += [
'/widget/android',
]
UNIFIED_SOURCES += [
'android/AndroidSensor.cpp',
- 'fallback/FallbackAlarm.cpp',
'fallback/FallbackPower.cpp',
'linux/LinuxMemory.cpp',
]
# AndroidHal.cpp cannot be built in unified mode because it relies on HalImpl.h.
SOURCES += [
'android/AndroidHal.cpp',
]
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
@@ -67,73 +66,68 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'go
'linux/LinuxPower.cpp',
]
# GonkHal.cpp cannot be built in unified mode because it relies on HalImpl.h.
SOURCES += [
'gonk/GonkHal.cpp',
]
elif CONFIG['OS_TARGET'] == 'Linux':
UNIFIED_SOURCES += [
- 'fallback/FallbackAlarm.cpp',
'fallback/FallbackScreenConfiguration.cpp',
'fallback/FallbackSensor.cpp',
'fallback/FallbackVibration.cpp',
'linux/LinuxMemory.cpp',
'linux/LinuxPower.cpp',
]
if CONFIG['MOZ_ENABLE_DBUS']:
UNIFIED_SOURCES += [
'linux/UPowerClient.cpp',
]
else:
UNIFIED_SOURCES += [
'fallback/FallbackBattery.cpp',
]
elif CONFIG['OS_TARGET'] == 'WINNT':
UNIFIED_SOURCES += [
- 'fallback/FallbackAlarm.cpp',
'fallback/FallbackMemory.cpp',
'fallback/FallbackPower.cpp',
'fallback/FallbackScreenConfiguration.cpp',
'fallback/FallbackVibration.cpp',
'windows/WindowsSensor.cpp',
]
# WindowsBattery.cpp cannot be built in unified mode because it relies on HalImpl.h.
SOURCES += [
'windows/WindowsBattery.cpp',
]
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
UNIFIED_SOURCES += [
'cocoa/CocoaBattery.cpp',
- 'fallback/FallbackAlarm.cpp',
'fallback/FallbackMemory.cpp',
'fallback/FallbackPower.cpp',
'fallback/FallbackScreenConfiguration.cpp',
'fallback/FallbackVibration.cpp',
]
elif CONFIG['OS_TARGET'] in ('OpenBSD', 'NetBSD', 'FreeBSD', 'DragonFly'):
UNIFIED_SOURCES += [
- 'fallback/FallbackAlarm.cpp',
'fallback/FallbackMemory.cpp',
'fallback/FallbackPower.cpp',
'fallback/FallbackScreenConfiguration.cpp',
'fallback/FallbackSensor.cpp',
'fallback/FallbackVibration.cpp',
]
if CONFIG['MOZ_ENABLE_DBUS']:
UNIFIED_SOURCES += [
'linux/UPowerClient.cpp',
]
else:
UNIFIED_SOURCES += [
'fallback/FallbackBattery.cpp',
]
else:
UNIFIED_SOURCES += [
- 'fallback/FallbackAlarm.cpp',
'fallback/FallbackBattery.cpp',
'fallback/FallbackMemory.cpp',
'fallback/FallbackPower.cpp',
'fallback/FallbackScreenConfiguration.cpp',
'fallback/FallbackSensor.cpp',
'fallback/FallbackVibration.cpp',
]