Jeff Thompson | fa30664 | 2013-06-17 15:06:57 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
| 16 | OneTimeTask::OneTimeTask(const Callback &callback, const Tag &tag, const SchedulerPtr &scheduler, double delay) |
| 17 | : Task(callback, tag, scheduler) |
| 18 | { |
| 19 | setTv(delay); |
| 20 | } |
| 21 | |
| 22 | void |
| 23 | OneTimeTask::run() |
| 24 | { |
| 25 | if (!m_invoked) |
| 26 | { |
| 27 | m_callback(); |
| 28 | m_invoked = true; |
| 29 | deregisterSelf(); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | void |
| 34 | OneTimeTask::deregisterSelf() |
| 35 | { |
| 36 | m_scheduler->deleteTask(m_tag); |
| 37 | } |
| 38 | |
| 39 | void |
| 40 | OneTimeTask::reset() |
| 41 | { |
| 42 | m_invoked = false; |
| 43 | } |