Modified: trunk/Source/WebCore/platform/RunLoop.h (149409 => 149410)
--- trunk/Source/WebCore/platform/RunLoop.h 2013-04-30 22:53:56 UTC (rev 149409)
+++ trunk/Source/WebCore/platform/RunLoop.h 2013-04-30 23:34:37 UTC (rev 149410)
@@ -32,6 +32,7 @@
#include <wtf/Forward.h>
#include <wtf/Functional.h>
#include <wtf/HashMap.h>
+#include <wtf/RetainPtr.h>
#include <wtf/ThreadSpecific.h>
#include <wtf/Threading.h>
@@ -92,7 +93,7 @@
bool m_isRepeating;
#elif PLATFORM(MAC)
static void timerFired(CFRunLoopTimerRef, void*);
- CFRunLoopTimerRef m_timer;
+ RetainPtr<CFRunLoopTimerRef> m_timer;
#elif PLATFORM(QT)
static void timerFired(RunLoop*, int ID);
int m_ID;
@@ -149,10 +150,9 @@
typedef HashMap<uint64_t, TimerBase*> TimerMap;
TimerMap m_activeTimers;
#elif PLATFORM(MAC)
- RunLoop(CFRunLoopRef);
static void performWork(void*);
- CFRunLoopRef m_runLoop;
- CFRunLoopSourceRef m_runLoopSource;
+ RetainPtr<CFRunLoopRef> m_runLoop;
+ RetainPtr<CFRunLoopSourceRef> m_runLoopSource;
int m_nestingLevel;
#elif PLATFORM(QT)
typedef HashMap<int, TimerBase*> TimerMap;
Modified: trunk/Source/WebCore/platform/cf/RunLoopCF.cpp (149409 => 149410)
--- trunk/Source/WebCore/platform/cf/RunLoopCF.cpp 2013-04-30 22:53:56 UTC (rev 149409)
+++ trunk/Source/WebCore/platform/cf/RunLoopCF.cpp 2013-04-30 23:34:37 UTC (rev 149410)
@@ -31,41 +31,11 @@
#include <wtf/AutodrainedPool.h>
namespace WebCore {
-
-static RunLoop* s_mainRunLoop;
-void RunLoop::initializeMainRunLoop()
-{
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- s_mainRunLoop = new RunLoop(CFRunLoopGetMain());
- });
-}
-
-RunLoop* RunLoop::current()
-{
- if (pthread_main_np())
- return RunLoop::main();
-
- DEFINE_STATIC_LOCAL(WTF::ThreadSpecific<RunLoop>, runLoopData, ());
- return &*runLoopData;
-}
-
-RunLoop* RunLoop::main()
-{
- ASSERT(s_mainRunLoop);
- return s_mainRunLoop;
-}
-
void RunLoop::performWork(void* context)
{
- // Wrap main thread in an Autorelease pool. Sending messages can call
- // into objc code and accumulate memory.
- if (current() == main()) {
- AutodrainedPool pool;
- static_cast<RunLoop*>(context)->performWork();
- } else
- static_cast<RunLoop*>(context)->performWork();
+ AutodrainedPool pool;
+ static_cast<RunLoop*>(context)->performWork();
}
RunLoop::RunLoop()
@@ -73,24 +43,13 @@
, m_nestingLevel(0)
{
CFRunLoopSourceContext context = { 0, this, 0, 0, 0, 0, 0, 0, 0, performWork };
- m_runLoopSource = CFRunLoopSourceCreate(kCFAllocatorDefault, 0, &context);
- CFRunLoopAddSource(m_runLoop, m_runLoopSource, kCFRunLoopCommonModes);
+ m_runLoopSource = adoptCF(CFRunLoopSourceCreate(kCFAllocatorDefault, 0, &context));
+ CFRunLoopAddSource(m_runLoop.get(), m_runLoopSource.get(), kCFRunLoopCommonModes);
}
-RunLoop::RunLoop(CFRunLoopRef runLoop)
- : m_runLoop(runLoop)
- , m_nestingLevel(0)
-{
- CFRunLoopSourceContext context = { 0, this, 0, 0, 0, 0, 0, 0, 0, performWork };
- m_runLoopSource = CFRunLoopSourceCreate(kCFAllocatorDefault, 0, &context);
- CFRunLoopAddSource(m_runLoop, m_runLoopSource, kCFRunLoopCommonModes);
-}
-
RunLoop::~RunLoop()
{
- // FIXME: Tear down the work item queue here.
- CFRunLoopSourceInvalidate(m_runLoopSource);
- CFRelease(m_runLoopSource);
+ CFRunLoopSourceInvalidate(m_runLoopSource.get());
}
void RunLoop::runForDuration(double duration)
@@ -100,8 +59,8 @@
void RunLoop::wakeUp()
{
- CFRunLoopSourceSignal(m_runLoopSource);
- CFRunLoopWakeUp(m_runLoop);
+ CFRunLoopSourceSignal(m_runLoopSource.get());
+ CFRunLoopWakeUp(m_runLoop.get());
}
#if !PLATFORM(MAC) || PLATFORM(IOS)
@@ -129,19 +88,13 @@
void RunLoop::TimerBase::timerFired(CFRunLoopTimerRef, void* context)
{
TimerBase* timer = static_cast<TimerBase*>(context);
-
- // Wrap main thread in an Autorelease pool. The timer can call
- // into objc code and accumulate memory outside of the main event loop.
- if (current() == main()) {
- AutodrainedPool pool;
- timer->fired();
- } else
- timer->fired();
+
+ AutodrainedPool pool;
+ timer->fired();
}
RunLoop::TimerBase::TimerBase(RunLoop* runLoop)
: m_runLoop(runLoop)
- , m_timer(0)
{
}
@@ -157,8 +110,8 @@
CFRunLoopTimerContext context = { 0, this, 0, 0, 0 };
CFTimeInterval repeatInterval = repeat ? nextFireInterval : 0;
- m_timer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + nextFireInterval, repeatInterval, 0, 0, timerFired, &context);
- CFRunLoopAddTimer(m_runLoop->m_runLoop, m_timer, kCFRunLoopCommonModes);
+ m_timer = adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + nextFireInterval, repeatInterval, 0, 0, timerFired, &context));
+ CFRunLoopAddTimer(m_runLoop->m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
}
void RunLoop::TimerBase::stop()
@@ -166,14 +119,13 @@
if (!m_timer)
return;
- CFRunLoopTimerInvalidate(m_timer);
- CFRelease(m_timer);
- m_timer = 0;
+ CFRunLoopTimerInvalidate(m_timer.get());
+ m_timer = nullptr;
}
bool RunLoop::TimerBase::isActive() const
{
- return m_timer && CFRunLoopTimerIsValid(m_timer);
+ return m_timer && CFRunLoopTimerIsValid(m_timer.get());
}
} // namespace WebCore