Diff
Modified: trunk/Source/WTF/ChangeLog (225671 => 225672)
--- trunk/Source/WTF/ChangeLog 2017-12-08 07:47:18 UTC (rev 225671)
+++ trunk/Source/WTF/ChangeLog 2017-12-08 12:09:31 UTC (rev 225672)
@@ -1,3 +1,14 @@
+2017-12-08 Yusuke Suzuki <[email protected]>
+
+ Use StaticLock and Lock instead of Mutex in Windows WebKitLegacy
+ https://bugs.webkit.org/show_bug.cgi?id=180572
+
+ Reviewed by Mark Lam.
+
+ Remove DEPRECATED_DEFINE_STATIC_LOCAL since it's no longer used.
+
+ * wtf/StdLibExtras.h:
+
2017-12-07 Basuke Suzuki <[email protected]>
[Win] [64-bit] Resolve Microsoft warning C4319 on BitVector.cpp
Modified: trunk/Source/WTF/wtf/StdLibExtras.h (225671 => 225672)
--- trunk/Source/WTF/wtf/StdLibExtras.h 2017-12-08 07:47:18 UTC (rev 225671)
+++ trunk/Source/WTF/wtf/StdLibExtras.h 2017-12-08 12:09:31 UTC (rev 225672)
@@ -34,14 +34,6 @@
#include <wtf/CheckedArithmetic.h>
#include <wtf/Compiler.h>
-// This was used to declare and define a static local variable (static T;) so that
-// it was leaked so that its destructors were not called at exit.
-// Newly written code should use static NeverDestroyed<T> instead.
-#ifndef DEPRECATED_DEFINE_STATIC_LOCAL
-#define DEPRECATED_DEFINE_STATIC_LOCAL(type, name, arguments) \
- static type& name = *new type arguments
-#endif
-
// Use this macro to declare and define a debug-only global variable that may have a
// non-trivial constructor and destructor. When building with clang, this will suppress
// warnings about global constructors and exit-time destructors.
Modified: trunk/Source/WebKitLegacy/win/ChangeLog (225671 => 225672)
--- trunk/Source/WebKitLegacy/win/ChangeLog 2017-12-08 07:47:18 UTC (rev 225671)
+++ trunk/Source/WebKitLegacy/win/ChangeLog 2017-12-08 12:09:31 UTC (rev 225672)
@@ -1,3 +1,51 @@
+2017-12-08 Yusuke Suzuki <[email protected]>
+
+ Use StaticLock and Lock instead of Mutex in Windows WebKitLegacy
+ https://bugs.webkit.org/show_bug.cgi?id=180572
+
+ Reviewed by Mark Lam.
+
+ Use StaticLock and drop DEPRECATED_DEFINE_STATIC_LOCAL.
+ Also we use Lock instead of Mutex.
+
+ * WebKitQuartzCoreAdditions/CAD3DRenderer.cpp:
+ (WKQCA::CAD3DRenderer::swapChain):
+ (WKQCA::CAD3DRenderer::renderAndPresent):
+ (WKQCA::CAD3DRenderer::renderToImage):
+ (WKQCA::CAD3DRenderer::setDeviceIsLost):
+ (WKQCA::CAD3DRenderer::renderInternal):
+ * WebKitQuartzCoreAdditions/CAD3DRenderer.h:
+ * WebKitQuartzCoreAdditions/CAView.cpp:
+ (WKQCA::CAView::Handle::create):
+ Return Ref<Handle> instead of RefPtr<>.
+
+ (WKQCA::CAView::Handle::lock):
+ (WKQCA::CAView::Handle::view const):
+ (WKQCA::CAView::Handle::clear):
+ (WKQCA::views):
+ (WKQCA::viewsNeedingUpdate):
+ (WKQCA::CAView::releaseAllD3DResources):
+ (WKQCA::CAView::CAView):
+ (WKQCA::CAView::~CAView):
+ (WKQCA::CAView::setLayer):
+ (WKQCA::CAView::update):
+ (WKQCA::CAView::drawToWindow):
+ (WKQCA::CAView::drawToWindowInternal):
+ (WKQCA::CAView::drawToImage):
+ (WKQCA::CAView::willDraw):
+ (WKQCA::CAView::drawIntoDC):
+ (WKQCA::CAView::setShouldInvertColors):
+ (WKQCA::CAView::scheduleNextDraw):
+ (WKQCA::CAView::displayLinkReachedCAMediaTime):
+ (WKQCA::CAView::contextDidChange):
+ (WKQCA::CAView::updateSoon):
+ (WKQCA::CAView::updateViewsNow):
+ (WKQCA::CAView::d3dDevice9):
+ (WKQCA::CAView::Handle::mutex): Deleted.
+ (WKQCA::globalStateMutex): Deleted.
+ (): Deleted.
+ * WebKitQuartzCoreAdditions/CAView.h:
+
2017-12-07 Yusuke Suzuki <[email protected]>
Use StaticLock instead of NeverDestroyed<Lock>
Modified: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAD3DRenderer.cpp (225671 => 225672)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAD3DRenderer.cpp 2017-12-08 07:47:18 UTC (rev 225671)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAD3DRenderer.cpp 2017-12-08 12:09:31 UTC (rev 225672)
@@ -119,7 +119,7 @@
CComPtr<IDirect3DSwapChain9> CAD3DRenderer::swapChain(CWindow window, const CGSize& size)
{
- MutexLocker lock(m_mutex);
+ auto locker = holdLock(m_lock);
bool useDefaultSwapChain = false;
@@ -388,7 +388,7 @@
ASSERT_ARG(swapChain, swapChain);
ASSERT_ARG(context, context);
- MutexLocker lock(m_mutex);
+ auto locker = holdLock(m_lock);
CGRect unusedDirtyRect;
RenderResult result = renderInternal(bounds, swapChain, postProcessingContext, context, unusedDirtyRect, nextRenderTime);
@@ -428,7 +428,7 @@
ASSERT_ARG(swapChain, swapChain);
ASSERT_ARG(context, context);
- MutexLocker lock(m_mutex);
+ auto locker = holdLock(m_lock);
CGRect dirtyRect;
RenderResult result = renderInternal(bounds, swapChain, postProcessingContext, context, dirtyRect, nextRenderTime);
@@ -471,7 +471,7 @@
void CAD3DRenderer::setDeviceIsLost(bool lost)
{
- ASSERT_WITH_MESSAGE(!m_mutex.tryLock(), "m_mutex must be held when calling this function");
+ ASSERT_WITH_MESSAGE(!m_lock.tryLock(), "m_lock must be held when calling this function");
if (m_deviceIsLost == lost)
return;
@@ -494,7 +494,7 @@
ASSERT_ARG(swapChain, swapChain);
ASSERT_ARG(context, context);
- ASSERT_WITH_MESSAGE(!m_mutex.tryLock(), "m_mutex must be held when calling this function");
+ ASSERT_WITH_MESSAGE(!m_lock.tryLock(), "m_lock must be held when calling this function");
ASSERT(m_d3dDevice);
ASSERT(m_renderOGLContext);
Modified: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAD3DRenderer.h (225671 => 225672)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAD3DRenderer.h 2017-12-08 07:47:18 UTC (rev 225671)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAD3DRenderer.h 2017-12-08 12:09:31 UTC (rev 225672)
@@ -27,6 +27,7 @@
#include <d3d9.h>
#include <wtf/Forward.h>
+#include <wtf/Lock.h>
#include <wtf/Noncopyable.h>
struct IDirect3DDevice9;
@@ -99,7 +100,7 @@
void createShaderIfNeeded();
- Mutex m_mutex;
+ Lock m_lock;
CComPtr<IDirect3DDevice9> m_d3dDevice;
CARenderOGLContext* m_renderOGLContext { nullptr };
CComPtr<IDirect3DPixelShader9> m_pixelShader;
Modified: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAView.cpp (225671 => 225672)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAView.cpp 2017-12-08 07:47:18 UTC (rev 225671)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAView.cpp 2017-12-08 12:09:31 UTC (rev 225672)
@@ -33,6 +33,7 @@
#include <QuartzCore/CARenderOGL.h>
#include <d3d9.h>
#include <wtf/HashSet.h>
+#include <wtf/NeverDestroyed.h>
#include <wtf/StdLibExtras.h>
#include <wtf/Vector.h>
#include <wtf/win/GDIObject.h>
@@ -43,40 +44,44 @@
class CAView::Handle : public ThreadSafeRefCounted<Handle> {
public:
- static RefPtr<Handle> create(CAView* view) { return adoptRef(new Handle(view)); }
+ static Ref<Handle> create(CAView* view) { return adoptRef(*new Handle(view)); }
~Handle() { ASSERT(!m_view); }
- Mutex& mutex() { return m_mutex; }
- CAView* view() const { ASSERT_WITH_MESSAGE(!const_cast<Mutex&>(m_mutex).tryLock(), "CAView::Handle's mutex must be held when calling this function"); return m_view; }
- void clear() { ASSERT_WITH_MESSAGE(!m_mutex.tryLock(), "CAView::Handle's mutex must be held when calling this function"); m_view = 0; }
+ Lock& lock() { return m_lock; }
+ CAView* view() const
+ {
+ ASSERT_WITH_MESSAGE(!const_cast<Lock&>(m_lock).tryLock(), "CAView::Handle's lock must be held when calling this function");
+ return m_view;
+ }
+ void clear()
+ {
+ ASSERT_WITH_MESSAGE(!m_lock.tryLock(), "CAView::Handle's lock must be held when calling this function");
+ m_view = nullptr;
+ }
+
private:
Handle(CAView* view)
: m_view(view) { }
- Mutex m_mutex;
+ Lock m_lock;
CAView* m_view;
};
-static Mutex& globalStateMutex()
-{
- DEPRECATED_DEFINE_STATIC_LOCAL(Mutex, mutex, ());
- return mutex;
-}
-
+static StaticLock globalStateLock;
static HWND messageWindow;
static const wchar_t messageWindowClassName[] = L"CAViewMessageWindow";
-static HashSet<RefPtr<CAView::Handle> >& views()
+static HashSet<Ref<CAView::Handle>>& views()
{
- DEPRECATED_DEFINE_STATIC_LOCAL(HashSet<RefPtr<CAView::Handle> >, views, ());
- return views;
+ static NeverDestroyed<HashSet<Ref<CAView::Handle>>> views;
+ return views.get();
}
-static HashSet<RefPtr<CAView::Handle> >& viewsNeedingUpdate()
+static HashSet<Ref<CAView::Handle>>& viewsNeedingUpdate()
{
- DEPRECATED_DEFINE_STATIC_LOCAL(HashSet<RefPtr<CAView::Handle> >, views, ());
- return views;
+ static NeverDestroyed<HashSet<Ref<CAView::Handle>>> views;
+ return views.get();
}
static void registerMessageWindowClass()
@@ -101,33 +106,31 @@
void CAView::releaseAllD3DResources()
{
- DEPRECATED_DEFINE_STATIC_LOCAL(Mutex, mutex, ());
+ static StaticLock lock;
- if (!mutex.tryLock()) {
+ if (!lock.tryLock()) {
// Another thread is currently releasing 3D resources.
// Since it will also release resources for the view calling this method, we can just return early.
return;
}
- Vector<RefPtr<Handle>> viewsToRelease;
-
+ Vector<Ref<Handle>> viewsToRelease;
{
- MutexLocker lock(globalStateMutex());
- viewsToRelease = copyToVector(views());
+ auto locker = holdLock(globalStateLock);
+ viewsToRelease = WTF::map(views(), [] (auto& handle) { return handle.copyRef(); });
}
- for (size_t i = 0; i < viewsToRelease.size(); ++i) {
- const RefPtr<Handle>& handle = viewsToRelease[i];
- MutexLocker lock(handle->mutex());
+ for (auto& handle : viewsToRelease) {
+ auto locker = holdLock(handle->lock());
CAView* view = handle->view();
if (!view)
continue;
- MutexLocker viewLock(view->m_mutex);
+ auto viewLocker = holdLock(view->m_lock);
view->m_swapChain = nullptr;
view->m_d3dPostProcessingContext = nullptr;
}
- mutex.unlock();
+ lock.unlock();
}
inline CAView::CAView(DrawingDestination destination)
@@ -134,11 +137,10 @@
: m_destination(destination)
, m_handle(Handle::create(this))
, m_context(adoptCF(CACFContextCreate(0)))
- , m_bounds(CGRectZero)
{
{
- MutexLocker lock(globalStateMutex());
- views().add(m_handle);
+ auto locker = holdLock(globalStateLock);
+ views().add(m_handle.copyRef());
}
CARenderNotificationAddObserver(kCARenderContextDidChange, CACFContextGetRenderContext(m_context.get()), contextDidChangeCallback, this);
@@ -151,17 +153,17 @@
m_layer = nullptr;
{
- MutexLocker lock(m_mutex);
+ auto locker = holdLock(m_lock);
m_context = nullptr;
}
- // Avoid stopping the display link while we hold either m_mutex or m_displayLinkMutex, as doing
+ // Avoid stopping the display link while we hold either m_lock or m_displayLinkLock, as doing
// so will wait for displayLinkReachedCAMediaTime to return and that function can take those
// same mutexes.
RefPtr<CVDisplayLink> linkToStop;
{
- MutexLocker lock(m_displayLinkMutex);
+ auto locker = holdLock(m_displayLinkLock);
linkToStop = WTFMove(m_displayLink);
}
@@ -171,13 +173,13 @@
update(nullptr, CGRectZero);
{
- MutexLocker lock(m_handle->mutex());
+ auto locker = holdLock(m_handle->lock());
m_handle->clear();
}
- MutexLocker lock(globalStateMutex());
+ auto locker = holdLock(globalStateLock);
- views().remove(m_handle);
+ views().remove(m_handle.copyRef());
if (!views().isEmpty())
return;
@@ -205,7 +207,7 @@
CACFLayerSetFrame(m_layer.get(), m_bounds);
- MutexLocker lock(m_mutex);
+ auto locker = holdLock(m_lock);
CACFContextSetLayer(m_context.get(), m_layer.get());
}
@@ -212,7 +214,7 @@
void CAView::update(CWindow window, const CGRect& bounds)
{
{
- MutexLocker lock(globalStateMutex());
+ auto locker = holdLock(globalStateLock);
// Ensure our message window is created on the thread that called CAView::update.
if (!messageWindow)
@@ -223,13 +225,13 @@
ASSERT(::GetCurrentThreadId() == CWindow(messageWindow).GetWindowThreadID());
ASSERT(!window || ::GetCurrentThreadId() == window.GetWindowThreadID());
- viewsNeedingUpdate().remove(m_handle);
+ viewsNeedingUpdate().remove(m_handle.copyRef());
}
bool boundsChanged;
{
- MutexLocker lock(m_mutex);
+ auto locker = holdLock(m_lock);
boundsChanged = !CGRectEqualToRect(m_bounds, bounds);
@@ -292,13 +294,13 @@
void CAView::drawToWindow()
{
- MutexLocker lock(m_mutex);
+ auto locker = holdLock(m_lock);
drawToWindowInternal();
}
void CAView::drawToWindowInternal()
{
- ASSERT_WITH_MESSAGE(!m_mutex.tryLock(), "m_mutex must be held when calling this function");
+ ASSERT_WITH_MESSAGE(!m_lock.tryLock(), "m_lock must be held when calling this function");
CFTimeInterval nextDrawTime;
bool unusedWillUpdateSoon;
if (willDraw(unusedWillUpdateSoon))
@@ -315,7 +317,7 @@
imageOrigin = CGPointZero;
nextDrawTime = numeric_limits<CFTimeInterval>::infinity();
- MutexLocker lock(m_mutex);
+ auto locker = holdLock(m_lock);
RefPtr<Image> image;
bool willUpdateSoon;
@@ -334,7 +336,7 @@
bool CAView::willDraw(bool& willUpdateSoon)
{
- ASSERT_WITH_MESSAGE(!m_mutex.tryLock(), "m_mutex must be held when calling this function");
+ ASSERT_WITH_MESSAGE(!m_lock.tryLock(), "m_lock must be held when calling this function");
willUpdateSoon = false;
@@ -431,7 +433,7 @@
}
{
- MutexLocker lock(m_mutex);
+ auto locker = holdLock(m_lock);
CARenderContext* renderContext = static_cast<CARenderContext*>(CACFContextGetRenderContext(m_context.get()));
CARenderContextLock(renderContext);
@@ -456,13 +458,13 @@
void CAView::setShouldInvertColors(bool shouldInvertColors)
{
- MutexLocker lock(m_mutex);
+ auto locker = holdLock(m_lock);
m_shouldInvertColors = shouldInvertColors;
}
void CAView::scheduleNextDraw(CFTimeInterval mediaTime)
{
- MutexLocker lock(m_displayLinkMutex);
+ auto locker = holdLock(m_displayLinkLock);
if (!m_context)
return;
@@ -491,7 +493,7 @@
ASSERT(m_destination == DrawingDestinationWindow);
{
- MutexLocker lock(m_displayLinkMutex);
+ auto locker = holdLock(m_displayLinkLock);
if (!m_displayLink)
return;
ASSERT_UNUSED(displayLink, displayLink == m_displayLink);
@@ -500,7 +502,7 @@
return;
}
- MutexLocker lock(m_mutex);
+ auto locker = holdLock(m_lock);
drawToWindowInternal();
}
@@ -517,7 +519,7 @@
void CAView::contextDidChange()
{
{
- MutexLocker lock(m_mutex);
+ auto locker = holdLock(m_lock);
// Our layer's rendered appearance once again matches our bounds, so it's safe to draw.
m_drawingProhibited = false;
@@ -534,8 +536,8 @@
void CAView::updateSoon()
{
{
- MutexLocker lock(globalStateMutex());
- viewsNeedingUpdate().add(m_handle);
+ auto locker = holdLock(globalStateLock);
+ viewsNeedingUpdate().add(m_handle.copyRef());
}
// It doesn't matter what timer ID we pass here, as long as it's nonzero.
ASSERT(messageWindow);
@@ -547,21 +549,18 @@
ASSERT_ARG(window, window == messageWindow);
::KillTimer(window, timerID);
- Vector<RefPtr<Handle>> viewsToUpdate;
-
+ HashSet<Ref<CAView::Handle>> viewsToUpdate;
{
- MutexLocker lock(globalStateMutex());
- viewsToUpdate = copyToVector(viewsNeedingUpdate());
- viewsNeedingUpdate().clear();
+ auto locker = holdLock(globalStateLock);
+ viewsNeedingUpdate().swap(viewsToUpdate);
}
- for (size_t i = 0; i < viewsToUpdate.size(); ++i) {
- const RefPtr<Handle>& handle = viewsToUpdate[i];
- MutexLocker lock(handle->mutex());
+ for (auto& handle : viewsToUpdate) {
+ auto locker = holdLock(handle->lock());
CAView* view = handle->view();
if (!view)
continue;
- MutexLocker viewLock(view->m_mutex);
+ auto viewLocker = holdLock(view->m_lock);
view->update(view->m_window, view->m_bounds);
}
}
@@ -568,9 +567,9 @@
IDirect3DDevice9* CAView::d3dDevice9()
{
- // Hold the mutex while we return the shared d3d device. The caller is responsible for retaining
+ // Hold the lock while we return the shared d3d device. The caller is responsible for retaining
// the device before returning to ensure that it is not released.
- MutexLocker lock(m_mutex);
+ auto locker = holdLock(m_lock);
return CAD3DRenderer::shared().d3dDevice9();
}
Modified: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAView.h (225671 => 225672)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAView.h 2017-12-08 07:47:18 UTC (rev 225671)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAView.h 2017-12-08 12:09:31 UTC (rev 225672)
@@ -103,23 +103,23 @@
DrawingDestination m_destination;
// Only set in the constructor, then protected by its own Mutex.
- RefPtr<Handle> m_handle;
+ Ref<Handle> m_handle;
// Only accessed in API calls, the synchronization of which is the responsibility of the caller.
RetainPtr<CACFLayerRef> m_layer;
ContextDidChangeCallback m_contextDidChangeCallback;
- Mutex m_mutex;
- // Accessed by the display link thread, protected by m_mutex. (m_context isn't directly
+ Lock m_lock;
+ // Accessed by the display link thread, protected by m_lock. (m_context isn't directly
// accessed from the display link thread, but its CARenderContext is.)
RetainPtr<CACFContextRef> m_context;
CWindow m_window;
- CGRect m_bounds;
+ CGRect m_bounds { CGRectZero };
CComPtr<IDirect3DSwapChain9> m_swapChain;
std::unique_ptr<D3DPostProcessingContext> m_d3dPostProcessingContext;
- Mutex m_displayLinkMutex;
- // Accessed by the display link thread, protected by m_displayLinkMutex.
+ Lock m_displayLinkLock;
+ // Accessed by the display link thread, protected by m_displayLinkLock.
RefPtr<CVDisplayLink> m_displayLink;
CFTimeInterval m_nextDrawTime { 0 };