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  if (g_scheduler.get() == nullptr) {
40  g_scheduler.reset(new Scheduler(*static_cast<boost::asio::io_service*>(nullptr)));
41  }
42 
43  return *g_scheduler;
44 }
45 
46 EventId
47 schedule(time::nanoseconds after, const EventCallback& event)
48 {
49  return getGlobalScheduler().scheduleEvent(after, event);
50 }
51 
52 void
53 cancel(const EventId& eventId)
54 {
55  getGlobalScheduler().cancelEvent(eventId);
56 }
57 
58 void
60 {
61  g_scheduler.reset();
62 }
63 
65 {
66 }
67 
69  : m_event(event)
70 {
71 }
72 
74  : m_event(other.m_event)
75 {
76  other.release();
77 }
78 
81 {
82  if (m_event != event) {
83  scheduler::cancel(m_event);
84  m_event = event;
85  }
86  return *this;
87 }
88 
90 {
91  scheduler::cancel(m_event);
92 }
93 
94 void
96 {
97  scheduler::cancel(m_event);
98 }
99 
100 void
102 {
103  m_event.reset();
104 }
105 
106 } // namespace scheduler
107 } // namespace nfd
function< void()> EventCallback
Definition: scheduler.hpp:46
void cancel()
cancels the event manually
Definition: scheduler.cpp:95
ScopedEventId & operator=(const EventId &event)
assigns an event
Definition: scheduler.cpp:80
void cancel(const EventId &eventId)
cancel a scheduled event
Definition: scheduler.cpp:53
~ScopedEventId()
cancels the event
Definition: scheduler.cpp:89
std::shared_ptr< ns3::EventId > EventId
Definition: scheduler.hpp:51
void release()
releases the event so that it won&#39;t be disconnected when this ScopedEventId is destructed ...
Definition: scheduler.cpp:101
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
void resetGlobalScheduler()
Definition: scheduler.cpp:59
cancels an event automatically upon destruction
Definition: scheduler.hpp:59
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:47
Scheduler & getGlobalScheduler()
Definition: scheduler.cpp:37