NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
scheduler.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "scheduler.hpp"
27 #include "global-io.hpp"
28 
29 #include <boost/thread/tss.hpp>
30 
31 namespace nfd {
32 namespace scheduler {
33 
34 static boost::thread_specific_ptr<Scheduler> g_scheduler;
35 
36 Scheduler&
38 {
39  static ndn::DummyIoService io;
40  if (g_scheduler.get() == nullptr) {
41  g_scheduler.reset(new Scheduler(io));
42  }
43 
44  return *g_scheduler;
45 }
46 
47 EventId
48 schedule(time::nanoseconds after, const EventCallback& event)
49 {
50  return getGlobalScheduler().scheduleEvent(after, event);
51 }
52 
53 void
54 cancel(const EventId& eventId)
55 {
56  getGlobalScheduler().cancelEvent(eventId);
57 }
58 
59 void
61 {
62  g_scheduler.reset();
63 }
64 
66 {
67 }
68 
70  : m_event(event)
71 {
72 }
73 
75  : m_event(other.m_event)
76 {
77  other.release();
78 }
79 
82 {
83  if (m_event != event) {
84  scheduler::cancel(m_event);
85  m_event = event;
86  }
87  return *this;
88 }
89 
91 {
92  scheduler::cancel(m_event);
93 }
94 
95 void
97 {
98  scheduler::cancel(m_event);
99 }
100 
101 void
103 {
104  m_event.reset();
105 }
106 
107 } // namespace scheduler
108 } // namespace nfd
function< void()> EventCallback
Definition: scheduler.hpp:46
Opaque handle for a scheduled event.
void cancel()
Cancels the event manually.
Definition: scheduler.cpp:96
ScopedEventId & operator=(const EventId &event)
Assigns an event.
Definition: scheduler.cpp:81
void cancel(const EventId &eventId)
Cancel a scheduled event.
Definition: scheduler.cpp:54
~ScopedEventId()
Cancels the event.
Definition: scheduler.cpp:90
std::shared_ptr< ns3::EventId > EventId
Definition: scheduler.hpp:51
void release()
Releases the event so that it won&#39;t be cancelled when this ScopedEventId is destructed.
Definition: scheduler.cpp:102
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
void resetGlobalScheduler()
Definition: scheduler.cpp:60
Cancels an event automatically upon destruction.
Definition: scheduler.hpp:60
static boost::thread_specific_ptr< Scheduler > g_scheduler
Definition: scheduler.cpp:34
EventId schedule(time::nanoseconds after, const EventCallback &event)
Schedule an event.
Definition: scheduler.cpp:48
Scheduler & getGlobalScheduler()
Definition: scheduler.cpp:37