blob: a4531121f0cf9e3288ebb05b4627f164aec53a5e [file] [log] [blame]
Alexander Afanasyev920af2f2014-01-25 22:56:11 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "scheduler.hpp"
Junxiao Shi98e29f42014-03-31 10:27:26 -07008#include "global-io.hpp"
Alexander Afanasyev920af2f2014-01-25 22:56:11 -08009
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080010namespace nfd {
Junxiao Shic041ca32014-02-25 20:01:15 -070011namespace scheduler {
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080012
Junxiao Shic041ca32014-02-25 20:01:15 -070013static shared_ptr<Scheduler> g_scheduler;
14
Junxiao Shi98e29f42014-03-31 10:27:26 -070015inline Scheduler&
Junxiao Shic041ca32014-02-25 20:01:15 -070016getGlobalScheduler()
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080017{
Junxiao Shic041ca32014-02-25 20:01:15 -070018 if (!static_cast<bool>(g_scheduler)) {
19 g_scheduler = make_shared<Scheduler>(boost::ref(getGlobalIoService()));
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080020 }
Junxiao Shic041ca32014-02-25 20:01:15 -070021 return *g_scheduler;
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080022}
23
Junxiao Shi98e29f42014-03-31 10:27:26 -070024EventId
25schedule(const time::nanoseconds& after, const Scheduler::Event& event)
26{
27 return getGlobalScheduler().scheduleEvent(after, event);
28}
29
30void
31cancel(const EventId& eventId)
32{
33 getGlobalScheduler().cancelEvent(eventId);
34}
35
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080036void
Junxiao Shic041ca32014-02-25 20:01:15 -070037resetGlobalScheduler()
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080038{
Junxiao Shic041ca32014-02-25 20:01:15 -070039 g_scheduler.reset();
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080040}
41
Junxiao Shic041ca32014-02-25 20:01:15 -070042} // namespace scheduler
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080043} // namespace nfd