blob: b3082af690852f02bcd89879c3c5c63e54390ce7 [file] [log] [blame]
Jeff Thompsonfa306642013-06-17 15:06:57 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Alexander Afanasyev
5 * Zhenkai Zhu
6 *
7 * BSD license, See the LICENSE file for more information
8 *
9 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
10 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
11 */
12
13#include "one-time-task.h"
14#include "scheduler.h"
15
16OneTimeTask::OneTimeTask(const Callback &callback, const Tag &tag, const SchedulerPtr &scheduler, double delay)
17 : Task(callback, tag, scheduler)
18{
19 setTv(delay);
20}
21
22void
23OneTimeTask::run()
24{
25 if (!m_invoked)
26 {
27 m_callback();
28 m_invoked = true;
29 deregisterSelf();
30 }
31}
32
33void
34OneTimeTask::deregisterSelf()
35{
36 m_scheduler->deleteTask(m_tag);
37}
38
39void
40OneTimeTask::reset()
41{
42 m_invoked = false;
43}