mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-15 15:16:12 -04:00
Signed-off-by: Alexey Polyudov <apolyudov@google.com> Change-Id: I8936b527079074d5c3af5531b9245063767cc4a7
40 lines
1.0 KiB
C++
40 lines
1.0 KiB
C++
#include "platform/cancelable_alarm.h"
|
|
|
|
#include "platform/api/platform.h"
|
|
#include "platform/api/scheduled_executor.h"
|
|
#include "platform/synchronized.h"
|
|
|
|
namespace location {
|
|
namespace nearby {
|
|
|
|
namespace {
|
|
using Platform = platform::ImplementationPlatform;
|
|
}
|
|
|
|
CancelableAlarm::CancelableAlarm(const std::string &name,
|
|
Ptr<Runnable> runnable,
|
|
std::int64_t delay_millis,
|
|
Ptr<ScheduledExecutor> scheduled_executor)
|
|
: name_(name),
|
|
lock_(Platform::createLock()),
|
|
cancelable_(scheduled_executor->schedule(runnable, delay_millis)) {}
|
|
|
|
CancelableAlarm::~CancelableAlarm() { cancelable_.destroy(); }
|
|
|
|
bool CancelableAlarm::cancel() {
|
|
Synchronized s(lock_.get());
|
|
|
|
if (cancelable_.isNull()) {
|
|
// TODO(tracyzhou): Add logging
|
|
return false;
|
|
}
|
|
|
|
bool canceled = cancelable_->cancel();
|
|
// TODO(tracyzhou): Add logging
|
|
cancelable_.destroy();
|
|
return canceled;
|
|
}
|
|
|
|
} // namespace nearby
|
|
} // namespace location
|