]>
git.saurik.com Git - apple/javascriptcore.git/blob - heap/HeapTimer.cpp
2 * Copyright (C) 2012 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "HeapTimer.h"
29 #include "IncrementalSweeper.h"
32 #include "JSCInlines.h"
33 #include <wtf/MainThread.h>
34 #include <wtf/Threading.h>
44 const CFTimeInterval
HeapTimer::s_decade
= 60 * 60 * 24 * 365 * 10;
46 static const void* retainAPILock(const void* info
)
48 static_cast<JSLock
*>(const_cast<void*>(info
))->ref();
52 static void releaseAPILock(const void* info
)
54 static_cast<JSLock
*>(const_cast<void*>(info
))->deref();
57 HeapTimer::HeapTimer(VM
* vm
, CFRunLoopRef runLoop
)
61 memset(&m_context
, 0, sizeof(CFRunLoopTimerContext
));
62 m_context
.info
= &vm
->apiLock();
63 m_context
.retain
= retainAPILock
;
64 m_context
.release
= releaseAPILock
;
65 m_timer
= adoptCF(CFRunLoopTimerCreate(0, s_decade
, s_decade
, 0, 0, HeapTimer::timerDidFire
, &m_context
));
66 CFRunLoopAddTimer(m_runLoop
.get(), m_timer
.get(), kCFRunLoopCommonModes
);
69 HeapTimer::~HeapTimer()
71 CFRunLoopRemoveTimer(m_runLoop
.get(), m_timer
.get(), kCFRunLoopCommonModes
);
72 CFRunLoopTimerInvalidate(m_timer
.get());
75 void HeapTimer::timerDidFire(CFRunLoopTimerRef timer
, void* context
)
77 JSLock
* apiLock
= static_cast<JSLock
*>(context
);
80 VM
* vm
= apiLock
->vm();
81 // The VM has been destroyed, so we should just give up.
87 HeapTimer
* heapTimer
= 0;
88 if (vm
->heap
.fullActivityCallback() && vm
->heap
.fullActivityCallback()->m_timer
.get() == timer
)
89 heapTimer
= vm
->heap
.fullActivityCallback();
90 else if (vm
->heap
.edenActivityCallback() && vm
->heap
.edenActivityCallback()->m_timer
.get() == timer
)
91 heapTimer
= vm
->heap
.edenActivityCallback();
92 else if (vm
->heap
.sweeper()->m_timer
.get() == timer
)
93 heapTimer
= vm
->heap
.sweeper();
95 RELEASE_ASSERT_NOT_REACHED();
98 JSLockHolder
locker(vm
);
107 HeapTimer::HeapTimer(VM
* vm
)
113 HeapTimer::~HeapTimer()
118 Ecore_Timer
* HeapTimer::add(double delay
, void* agent
)
120 return ecore_timer_add(delay
, reinterpret_cast<Ecore_Task_Cb
>(timerEvent
), agent
);
123 void HeapTimer::stop()
128 ecore_timer_del(m_timer
);
132 bool HeapTimer::timerEvent(void* info
)
134 HeapTimer
* agent
= static_cast<HeapTimer
*>(info
);
136 JSLockHolder
locker(agent
->m_vm
);
140 return ECORE_CALLBACK_CANCEL
;
143 HeapTimer::HeapTimer(VM
* vm
)
148 HeapTimer::~HeapTimer()
152 void HeapTimer::invalidate()