OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
task_tbbkeepawake.h
Go to the documentation of this file.
1 #include "base/task.h"
2 #include "base/timer.h"
3 #include <boost/bind.hpp>
4 #include "io/event_manager.h"
5 
7 public:
9  timeout_changed_(false), tbb_awake_timer_(NULL) { }
10 
12  const std::string task_name,
13  uint32_t tbbKeepawakeTimeout = 1000) {
14  uint32_t task_id = ts->GetTaskId(task_name);
16  "TBB Keep Awake",
17  task_id, 0);
18  tbb_awake_val_ = tbbKeepawakeTimeout;
19  bool ret = tbb_awake_timer_->Start(tbbKeepawakeTimeout,
20  boost::bind(&TaskTbbKeepAwake::TbbKeepAwake, this));
21  return ret;
22  }
23 
24  void ModifyTbbKeepAwakeTimeout(uint32_t timeout) {
25  tbb::mutex::scoped_lock lock(mutex_);
26  if (tbb_awake_val_ != timeout) {
27  timeout_changed_ = true;
28  tbb_awake_val_ = timeout;
29  }
30  }
31 
32  bool TbbKeepAwake() {
34  if (timeout_changed_) {
36  timeout_changed_ = false;
37  }
38  return true;
39  }
40 
42  if (tbb_awake_timer_) {
45  }
46  }
47 
48  uint32_t tbb_awake_val() const { return tbb_awake_val_; }
49 private:
50  uint64_t tbb_awake_count_;
51  uint32_t tbb_awake_val_;
54  tbb::mutex mutex_;
55 };
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:178
boost::asio::io_context * io_service()
Definition: event_manager.h:42
int GetTaskId(const std::string &name)
Definition: task.cc:856
void ModifyTbbKeepAwakeTimeout(uint32_t timeout)
uint32_t tbb_awake_val() const
bool StartTbbKeepAwakeTask(TaskScheduler *ts, EventManager *event_mgr, const std::string task_name, uint32_t tbbKeepawakeTimeout=1000)
static Timer * CreateTimer(boost::asio::io_context &service, const std::string &name, int task_id=Timer::GetTimerTaskId(), int task_instance=Timer::GetTimerInstanceId(), bool delete_on_completion=false)
Definition: timer.cc:201
bool Cancel()
Definition: timer.cc:150
bool Start(int time, Handler handler, ErrorHandler error_handler=NULL)
Definition: timer.cc:108
bool Reschedule(int time)
Definition: timer.cc:137
Definition: timer.h:54
static bool DeleteTimer(Timer *Timer)
Definition: timer.cc:222