blob: b3082af690852f02bcd89879c3c5c63e54390ce7 [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2013, Regents of the University of California
* Alexander Afanasyev
* Zhenkai Zhu
*
* BSD license, See the LICENSE file for more information
*
* Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
* Alexander Afanasyev <alexander.afanasyev@ucla.edu>
*/
#include "one-time-task.h"
#include "scheduler.h"
OneTimeTask::OneTimeTask(const Callback &callback, const Tag &tag, const SchedulerPtr &scheduler, double delay)
: Task(callback, tag, scheduler)
{
setTv(delay);
}
void
OneTimeTask::run()
{
if (!m_invoked)
{
m_callback();
m_invoked = true;
deregisterSelf();
}
}
void
OneTimeTask::deregisterSelf()
{
m_scheduler->deleteTask(m_tag);
}
void
OneTimeTask::reset()
{
m_invoked = false;
}