Title: [149410] trunk/Source/WebCore
Revision
149410
Author
[email protected]
Date
2013-04-30 16:34:37 -0700 (Tue, 30 Apr 2013)

Log Message

Clean up RunLoop code
https://bugs.webkit.org/show_bug.cgi?id=115454

Reviewed by Andreas Kling.

Delete a couple of functions from RunLoopCF.cpp and just use the generic ones in RunLoop.cpp,
use RetainPtr instead of manual retain/release. Always use an AutoreleasePool when calling performWork or timers.

* platform/RunLoop.cpp:
(WebCore::RunLoop::setUseApplicationRunLoopOnMainRunLoop):
(WebCore):
* platform/RunLoop.h:
(TimerBase):
(RunLoop):
* platform/cf/RunLoopCF.cpp:
(WebCore::RunLoop::performWork):
(WebCore::RunLoop::RunLoop):
(WebCore::RunLoop::~RunLoop):
(WebCore::RunLoop::wakeUp):
(WebCore::RunLoop::TimerBase::timerFired):
(WebCore::RunLoop::TimerBase::TimerBase):
(WebCore::RunLoop::TimerBase::start):
(WebCore::RunLoop::TimerBase::stop):
(WebCore::RunLoop::TimerBase::isActive):
* platform/mac/RunLoopMac.mm:
(WebCore::RunLoop::run):
(WebCore::RunLoop::stop):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (149409 => 149410)


--- trunk/Source/WebCore/ChangeLog	2013-04-30 22:53:56 UTC (rev 149409)
+++ trunk/Source/WebCore/ChangeLog	2013-04-30 23:34:37 UTC (rev 149410)
@@ -1,3 +1,33 @@
+2013-04-30  Anders Carlsson  <[email protected]>
+
+        Clean up RunLoop code
+        https://bugs.webkit.org/show_bug.cgi?id=115454
+
+        Reviewed by Andreas Kling.
+
+        Delete a couple of functions from RunLoopCF.cpp and just use the generic ones in RunLoop.cpp,
+        use RetainPtr instead of manual retain/release. Always use an AutoreleasePool when calling performWork or timers.
+
+        * platform/RunLoop.cpp:
+        (WebCore::RunLoop::setUseApplicationRunLoopOnMainRunLoop):
+        (WebCore):
+        * platform/RunLoop.h:
+        (TimerBase):
+        (RunLoop):
+        * platform/cf/RunLoopCF.cpp:
+        (WebCore::RunLoop::performWork):
+        (WebCore::RunLoop::RunLoop):
+        (WebCore::RunLoop::~RunLoop):
+        (WebCore::RunLoop::wakeUp):
+        (WebCore::RunLoop::TimerBase::timerFired):
+        (WebCore::RunLoop::TimerBase::TimerBase):
+        (WebCore::RunLoop::TimerBase::start):
+        (WebCore::RunLoop::TimerBase::stop):
+        (WebCore::RunLoop::TimerBase::isActive):
+        * platform/mac/RunLoopMac.mm:
+        (WebCore::RunLoop::run):
+        (WebCore::RunLoop::stop):
+
 2013-04-30  David Hyatt  <[email protected]>
 
         <button> ignores margin-bottom.

Modified: trunk/Source/WebCore/platform/RunLoop.cpp (149409 => 149410)


--- trunk/Source/WebCore/platform/RunLoop.cpp	2013-04-30 22:53:56 UTC (rev 149409)
+++ trunk/Source/WebCore/platform/RunLoop.cpp	2013-04-30 23:34:37 UTC (rev 149410)
@@ -31,6 +31,10 @@
 namespace WebCore {
 
 #if !PLATFORM(MAC)
+void RunLoop::setUseApplicationRunLoopOnMainRunLoop()
+{
+}
+#endif
 
 static RunLoop* s_mainRunLoop;
 
@@ -53,12 +57,6 @@
     return s_mainRunLoop;
 }
 
-void RunLoop::setUseApplicationRunLoopOnMainRunLoop()
-{
-}
-
-#endif
-
 void RunLoop::performWork()
 {
     // It is important to handle the functions in the queue one at a time because while inside one of these

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

Modified: trunk/Source/WebCore/platform/mac/RunLoopMac.mm (149409 => 149410)


--- trunk/Source/WebCore/platform/mac/RunLoopMac.mm	2013-04-30 22:53:56 UTC (rev 149409)
+++ trunk/Source/WebCore/platform/mac/RunLoopMac.mm	2013-04-30 23:34:37 UTC (rev 149410)
@@ -42,9 +42,9 @@
         // Use -[NSApplication run] for the main run loop.
         [NSApp run];
     } else {
-        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-        CFRunLoopRun();
-        [pool drain];
+        @autoreleasepool {
+            CFRunLoopRun();
+        }
     }
     current()->m_nestingLevel--;
 }
@@ -68,7 +68,7 @@
                                                data2:0];
         [NSApp postEvent:event atStart:true];
     } else
-        CFRunLoopStop(m_runLoop);
+        CFRunLoopStop(m_runLoop.get());
 }
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to