1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#include "config.h"
#include "HeapTimer.h"
#include <wtf/Threading.h>
namespace JSC {
#if USE(CF)
const CFTimeInterval HeapTimer::s_decade = 60 * 60 * 24 * 365 * 10;
HeapTimer::HeapTimer(JSGlobalData* globalData, CFRunLoopRef runLoop)
: m_globalData(globalData)
, m_runLoop(runLoop)
{
memset(&m_context, 0, sizeof(CFRunLoopTimerContext));
m_context.info = this;
m_timer.adoptCF(CFRunLoopTimerCreate(0, s_decade, s_decade, 0, 0, HeapTimer::timerDidFire, &m_context));
CFRunLoopAddTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
}
HeapTimer::~HeapTimer()
{
invalidate();
}
void HeapTimer::synchronize()
{
if (CFRunLoopGetCurrent() == m_runLoop.get())
return;
CFRunLoopRemoveTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
m_runLoop = CFRunLoopGetCurrent();
CFRunLoopAddTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
}
void HeapTimer::invalidate()
{
CFRunLoopRemoveTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
CFRunLoopTimerInvalidate(m_timer.get());
}
void HeapTimer::timerDidFire(CFRunLoopTimerRef, void* info)
{
HeapTimer* agent = static_cast<HeapTimer*>(info);
agent->doWork();
}
#else
HeapTimer::HeapTimer(JSGlobalData* globalData)
: m_globalData(globalData)
{
}
HeapTimer::~HeapTimer()
{
}
void HeapTimer::synchronize()
{
}
void HeapTimer::invalidate()
{
}
#endif
} // namespace JSC
|