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(getGlobalIoService()));
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 
68 ScopedEventId::ScopedEventId(const EventId& event)
69  : m_event(event)
70 {
71 }
72 
74  : m_event(other.m_event)
75 {
76  other.release();
77 }
78 
80 ScopedEventId::operator=(const EventId& event)
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
~ScopedEventId()
cancels the event
Definition: scheduler.cpp:89
void cancel(const EventId &eventId)
cancel a scheduled event
Definition: scheduler.cpp:53
cancels an event automatically upon destruction
Definition: scheduler.hpp:56
Scheduler & getGlobalScheduler()
Definition: scheduler.cpp:37
void release()
releases the event so that it won&#39;t be disconnected when this ScopedEventId is destructed ...
Definition: scheduler.cpp:101
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
ScopedEventId & operator=(const EventId &event)
assigns an event
Definition: scheduler.cpp:80
void resetGlobalScheduler()
Definition: scheduler.cpp: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
void cancel()
cancels the event manually
Definition: scheduler.cpp:95
boost::asio::io_service & getGlobalIoService()
Definition: global-io.cpp:41