diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WTF/wtf/RunLoop.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WTF/wtf/RunLoop.cpp')
-rw-r--r-- | Source/WTF/wtf/RunLoop.cpp | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/Source/WTF/wtf/RunLoop.cpp b/Source/WTF/wtf/RunLoop.cpp index 11a860fd0..66593b04e 100644 --- a/Source/WTF/wtf/RunLoop.cpp +++ b/Source/WTF/wtf/RunLoop.cpp @@ -26,6 +26,7 @@ #include "config.h" #include "RunLoop.h" +#include <wtf/NeverDestroyed.h> #include <wtf/StdLibExtras.h> #include <wtf/ThreadSpecific.h> @@ -37,39 +38,40 @@ static RunLoop* s_mainRunLoop; class RunLoop::Holder { public: Holder() - : m_runLoop(adoptRef(new RunLoop)) + : m_runLoop(adoptRef(*new RunLoop)) { } - RunLoop* runLoop() const { return m_runLoop.get(); } + RunLoop& runLoop() { return m_runLoop; } private: - RefPtr<RunLoop> m_runLoop; + Ref<RunLoop> m_runLoop; }; void RunLoop::initializeMainRunLoop() { if (s_mainRunLoop) return; - s_mainRunLoop = RunLoop::current(); + initializeMainThread(); + s_mainRunLoop = &RunLoop::current(); } -RunLoop* RunLoop::current() +RunLoop& RunLoop::current() { - DEFINE_STATIC_LOCAL(WTF::ThreadSpecific<RunLoop::Holder>, runLoopHolder, ()); - return runLoopHolder->runLoop(); + static NeverDestroyed<ThreadSpecific<Holder>> runLoopHolder; + return runLoopHolder.get()->runLoop(); } -RunLoop* RunLoop::main() +RunLoop& RunLoop::main() { ASSERT(s_mainRunLoop); - return s_mainRunLoop; + return *s_mainRunLoop; } bool RunLoop::isMain() { ASSERT(s_mainRunLoop); - return s_mainRunLoop == RunLoop::current(); + return s_mainRunLoop == &RunLoop::current(); } void RunLoop::performWork() @@ -88,22 +90,24 @@ void RunLoop::performWork() // By only handling up to the number of functions that were in the queue when performWork() is called // we guarantee to occasionally return from the run loop so other event sources will be allowed to spin. - std::function<void()> function; size_t functionsToHandle = 0; - { - MutexLocker locker(m_functionQueueLock); - functionsToHandle = m_functionQueue.size(); + Function<void ()> function; + { + MutexLocker locker(m_functionQueueLock); + functionsToHandle = m_functionQueue.size(); - if (m_functionQueue.isEmpty()) - return; + if (m_functionQueue.isEmpty()) + return; - function = m_functionQueue.takeFirst(); - } + function = m_functionQueue.takeFirst(); + } - function(); + function(); + } for (size_t functionsHandled = 1; functionsHandled < functionsToHandle; ++functionsHandled) { + Function<void ()> function; { MutexLocker locker(m_functionQueueLock); @@ -120,10 +124,12 @@ void RunLoop::performWork() } } -void RunLoop::dispatch(std::function<void ()> function) +void RunLoop::dispatch(Function<void ()>&& function) { - MutexLocker locker(m_functionQueueLock); - m_functionQueue.append(std::move(function)); + { + MutexLocker locker(m_functionQueueLock); + m_functionQueue.append(WTFMove(function)); + } wakeUp(); } |