blob: b823255e28eb44dbd51a045e91540c6fa2235d7c [file] [log] [blame]
Zhenkai Zhu97019eb2013-01-08 00:21:43 -08001#include "event-scheduler.h"
2
3Task::Task(const Callback &callback, void *arg, const Tag &tag)
4 : m_callback(callback)
5 , m_arg(arg)
6 , m_tag(tag)
7{
8}
9
10Task::Task(const Task &other)
11 : m_callback(other.m_callback)
12 , m_arg(other.m_arg)
13 , m_tag(other.m_tag)
14{
15}
16
17Task &
18Task::operator=(const Task &other)
19{
20 m_callback = other.m_callback;
21 m_arg = other.m_arg;
22 m_tag = other.m_tag;
23 return (*this);
24}
25
26RandomIntervalGenerator::RandomIntervalGenerator(double interval, double percent, Direction direction = UP)
27 : m_interval(interval)
28 , m_rng(time(NULL))
29 , m_percent(percent)
30 , m_dist(0.0, fractional(percent))
31 , m_random(m_rng, m_dist)
32{
33}
34
35double
36RandomIntervalGenerator::nextInterval()
37{
38 double percent = m_random();
39 double interval = m_interval;
40 switch (m_direction)
41 {
42 case UP: interval = m_interval * (1.0 + percent); break;
43 case DOWN: interval = m_interval * (1.0 - percent); break;
44 case EVEN: interval = m_interval * (1.0 - m_percent/2.0 + percent); break;
45 default: break
46 }
47
48 return interval;
49}