Title: [149338] trunk/Source/WebCore
Revision
149338
Author
[email protected]
Date
2013-04-29 17:24:04 -0700 (Mon, 29 Apr 2013)

Log Message

Make RunLoop ref-counted
https://bugs.webkit.org/show_bug.cgi?id=115384

Reviewed by Sam Weinig.

This is a step towards creating a shared base class that both RunLoop and WorkQueue will derive from.

* platform/RunLoop.cpp:
(WebCore::RunLoop::current):
(WebCore::RunLoop::~RunLoop):
(WebCore):
* platform/RunLoop.h:
(RunLoop):
* platform/cf/RunLoopCF.cpp:
(WebCore::RunLoop::initializeMainRunLoop):
(WebCore::RunLoop::current):
(WebCore::RunLoop::~RunLoop):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (149337 => 149338)


--- trunk/Source/WebCore/ChangeLog	2013-04-30 00:14:14 UTC (rev 149337)
+++ trunk/Source/WebCore/ChangeLog	2013-04-30 00:24:04 UTC (rev 149338)
@@ -1,3 +1,23 @@
+2013-04-29  Anders Carlsson  <[email protected]>
+
+        Make RunLoop ref-counted
+        https://bugs.webkit.org/show_bug.cgi?id=115384
+
+        Reviewed by Sam Weinig.
+
+        This is a step towards creating a shared base class that both RunLoop and WorkQueue will derive from.
+
+        * platform/RunLoop.cpp:
+        (WebCore::RunLoop::current):
+        (WebCore::RunLoop::~RunLoop):
+        (WebCore):
+        * platform/RunLoop.h:
+        (RunLoop):
+        * platform/cf/RunLoopCF.cpp:
+        (WebCore::RunLoop::initializeMainRunLoop):
+        (WebCore::RunLoop::current):
+        (WebCore::RunLoop::~RunLoop):
+
 2013-04-29  Brent Fulgham  <[email protected]>
 
         [Windows, WinCairo] Remove link and include directives for pthread.

Modified: trunk/Source/WebCore/platform/RunLoop.cpp (149337 => 149338)


--- trunk/Source/WebCore/platform/RunLoop.cpp	2013-04-30 00:14:14 UTC (rev 149337)
+++ trunk/Source/WebCore/platform/RunLoop.cpp	2013-04-30 00:24:04 UTC (rev 149338)
@@ -43,8 +43,8 @@
 
 RunLoop* RunLoop::current()
 {
-    DEFINE_STATIC_LOCAL(WTF::ThreadSpecific<RunLoop>, runLoopData, ());
-    return &*runLoopData;
+    DEFINE_STATIC_LOCAL(WTF::ThreadSpecific<RefPtr<RunLoop> >, runLoopData, ());
+    return runLoopData->get();
 }
 
 RunLoop* RunLoop::main()

Modified: trunk/Source/WebCore/platform/RunLoop.h (149337 => 149338)


--- trunk/Source/WebCore/platform/RunLoop.h	2013-04-30 00:14:14 UTC (rev 149337)
+++ trunk/Source/WebCore/platform/RunLoop.h	2013-04-30 00:24:04 UTC (rev 149338)
@@ -45,7 +45,7 @@
 
 namespace WebCore {
 
-class RunLoop {
+class RunLoop : public ThreadSafeRefCounted<RunLoop> {
 public:
     // Must be called from the main thread (except for the Mac platform, where it
     // can be called from any thread).
@@ -56,6 +56,7 @@
 
     static RunLoop* current();
     static RunLoop* main();
+    ~RunLoop();
 
     void dispatch(const Function<void()>&);
 
@@ -133,7 +134,6 @@
     friend class WTF::ThreadSpecific<RunLoop>;
 
     RunLoop();
-    ~RunLoop();
 
     void performWork();
 

Modified: trunk/Source/WebCore/platform/cf/RunLoopCF.cpp (149337 => 149338)


--- trunk/Source/WebCore/platform/cf/RunLoopCF.cpp	2013-04-30 00:14:14 UTC (rev 149337)
+++ trunk/Source/WebCore/platform/cf/RunLoopCF.cpp	2013-04-30 00:24:04 UTC (rev 149338)
@@ -38,7 +38,7 @@
 {
     static dispatch_once_t onceToken;
     dispatch_once(&onceToken, ^{
-        s_mainRunLoop = new RunLoop(CFRunLoopGetMain());
+        s_mainRunLoop = adoptRef(new RunLoop(CFRunLoopGetMain())).leakRef();
     });
 }
 
@@ -47,8 +47,8 @@
     if (pthread_main_np())
         return RunLoop::main();
     
-    DEFINE_STATIC_LOCAL(WTF::ThreadSpecific<RunLoop>, runLoopData, ());
-    return &*runLoopData;
+    DEFINE_STATIC_LOCAL(WTF::ThreadSpecific<RefPtr<RunLoop> >, runLoopData, ());
+    return runLoopData->get();
 }
 
 RunLoop* RunLoop::main()
@@ -88,7 +88,8 @@
 
 RunLoop::~RunLoop()
 {
-    // FIXME: Tear down the work item queue here.
+    ASSERT(this != main());
+
     CFRunLoopSourceInvalidate(m_runLoopSource);
     CFRelease(m_runLoopSource);
 }

Modified: trunk/Source/WebCore/platform/efl/RunLoopEfl.cpp (149337 => 149338)


--- trunk/Source/WebCore/platform/efl/RunLoopEfl.cpp	2013-04-30 00:14:14 UTC (rev 149337)
+++ trunk/Source/WebCore/platform/efl/RunLoopEfl.cpp	2013-04-30 00:24:04 UTC (rev 149338)
@@ -46,6 +46,7 @@
 
 RunLoop::~RunLoop()
 {
+    ASSERT(this != main());
 }
 
 void RunLoop::run()

Modified: trunk/Source/WebCore/platform/gtk/RunLoopGtk.cpp (149337 => 149338)


--- trunk/Source/WebCore/platform/gtk/RunLoopGtk.cpp	2013-04-30 00:14:14 UTC (rev 149337)
+++ trunk/Source/WebCore/platform/gtk/RunLoopGtk.cpp	2013-04-30 00:24:04 UTC (rev 149338)
@@ -46,6 +46,8 @@
 
 RunLoop::~RunLoop()
 {
+    ASSERT(this != main());
+
     for (int i = m_runLoopMainLoops.size() - 1; i >= 0; --i) {
         if (!g_main_loop_is_running(m_runLoopMainLoops[i].get()))
             continue;

Modified: trunk/Source/WebCore/platform/win/RunLoopWin.cpp (149337 => 149338)


--- trunk/Source/WebCore/platform/win/RunLoopWin.cpp	2013-04-30 00:14:14 UTC (rev 149337)
+++ trunk/Source/WebCore/platform/win/RunLoopWin.cpp	2013-04-30 00:24:04 UTC (rev 149338)
@@ -107,6 +107,7 @@
 RunLoop::~RunLoop()
 {
     // FIXME: Tear down the work item queue here.
+    ASSERT(this != main());
 }
 
 void RunLoop::wakeUp()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to