Title: [276247] trunk
Revision
276247
Author
[email protected]
Date
2021-04-19 06:12:23 -0700 (Mon, 19 Apr 2021)

Log Message

Enable -Wthread-safety, add attributes to custom lock classes, and provide macros to declare guards
https://bugs.webkit.org/show_bug.cgi?id=221614
<rdar://problem/74396781>

Patch by Kimmo Kinnunen <[email protected]> on 2021-04-19
Reviewed by David Kilzer.

PerformanceTests:

Add -Wthread-safety to compile flags.

* DecoderTest/Configurations/Base.xcconfig:

Source/bmalloc:

Add -Wthread-safety to compile flags.

* Configurations/Base.xcconfig:

Source/_javascript_Core:

Add -Wthread-safety to compile flags.

* Configurations/Base.xcconfig:

Source/WebCore:

Add -Wthread-safety to compile flags.

* Configurations/Base.xcconfig:

Source/WebCore/PAL:

Add -Wthread-safety to compile flags.

* Configurations/Base.xcconfig:

Source/WebInspectorUI:

Add -Wthread-safety to compile flags.

* Configurations/Base.xcconfig:

Source/WebKit:

Add -Wthread-safety to compile flags.

* Configurations/Base.xcconfig:

Source/WebKitLegacy/mac:

Add -Wthread-safety to compile flags.

* Configurations/Base.xcconfig:

Source/WTF:

Implement rudimentary support for clang thread safety analysis.
The added macros can be used to declare which member variables or
global variables are locked by which mutexes. The compiler will
check statically that the mutexes are held correctly. The checking
is intra procedural, not global.

* Configurations/Base.xcconfig:
    Add -Wthread-safety to compile flags.

* wtf/CheckedLock.h: Added.
Add CheckedLock, a Lock variant that is amenable to static
analysis.
Add a Locker specialization for CheckedLock that is amenable to
static analysis.

Locker<CheckedLock> is a std::scoped_lock. The scoped_lock cannot be aliased,
since it appears that (Apple's) libcxx is not compiled with thread safety
analysis support enabled by default.

New types are needed due Locker move constructor and conditional locking.
The Locker has default usage pattern of:
  auto locker = holdLock(m_lock);
This forces dynamism that removes the possibility of simple statical
analysis that thread safety analysis capabilities "mutex" and "scoped_lock"
currently implement. Most likely large fraction of call sites is due to historical
lack of CTAD and as such can be converted to less general form.
Once the pattern is not used by default, CheckedLock can be deleted
and the move dynamism bits of Locker can be moved to some more specific type
("UncheckedLocker").

* wtf/ThreadSafetyAnalysis.h: Added.
Add macro wrappers around clang "mutex" and "scoped_lock" capability attributes.

Tools:

* TestWebKitAPI/Configurations/Base.xcconfig:
Add -Wthread-safety to compile flags.

* TestWebKitAPI/CMakeLists.txt:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WTF/CheckedLock.cpp: Added.
(TestWebKitAPI::TEST):
Implement a test for testing that CheckedLock compiles.

Modified Paths

Added Paths

Diff

Modified: trunk/PerformanceTests/ChangeLog (276246 => 276247)


--- trunk/PerformanceTests/ChangeLog	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/PerformanceTests/ChangeLog	2021-04-19 13:12:23 UTC (rev 276247)
@@ -1,3 +1,15 @@
+2021-04-19  Kimmo Kinnunen  <[email protected]>
+
+        Enable -Wthread-safety, add attributes to custom lock classes, and provide macros to declare guards
+        https://bugs.webkit.org/show_bug.cgi?id=221614
+        <rdar://problem/74396781>
+
+        Reviewed by David Kilzer.
+
+        Add -Wthread-safety to compile flags.
+
+        * DecoderTest/Configurations/Base.xcconfig:
+
 2021-04-12  Sergio Villar Senin  <[email protected]>
 
         [css-flexbox] CDC COVID Vaccine Tracker: Safari garbles data table

Modified: trunk/PerformanceTests/DecoderTest/Configurations/Base.xcconfig (276246 => 276247)


--- trunk/PerformanceTests/DecoderTest/Configurations/Base.xcconfig	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/PerformanceTests/DecoderTest/Configurations/Base.xcconfig	2021-04-19 13:12:23 UTC (rev 276247)
@@ -83,7 +83,7 @@
 GCC_WARN_UNINITIALIZED_AUTOS = YES;
 GCC_WARN_UNUSED_FUNCTION = YES;
 GCC_WARN_UNUSED_VARIABLE = YES;
-WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wextra-tokens -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wno-unknown-warning-option -Wliteral-conversion;
+WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wextra-tokens -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wno-unknown-warning-option -Wliteral-conversion -Wthread-safety;
 
 TARGET_MAC_OS_X_VERSION_MAJOR = $(TARGET_MAC_OS_X_VERSION_MAJOR_$(MACOSX_DEPLOYMENT_TARGET:base)$(MACOSX_DEPLOYMENT_TARGET:suffix:identifier));
 TARGET_MAC_OS_X_VERSION_MAJOR_10_13 = 101300;

Modified: trunk/Source/_javascript_Core/ChangeLog (276246 => 276247)


--- trunk/Source/_javascript_Core/ChangeLog	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-04-19 13:12:23 UTC (rev 276247)
@@ -1,3 +1,15 @@
+2021-04-19  Kimmo Kinnunen  <[email protected]>
+
+        Enable -Wthread-safety, add attributes to custom lock classes, and provide macros to declare guards
+        https://bugs.webkit.org/show_bug.cgi?id=221614
+        <rdar://problem/74396781>
+
+        Reviewed by David Kilzer.
+
+        Add -Wthread-safety to compile flags.
+
+        * Configurations/Base.xcconfig:
+
 2021-04-18  Yusuke Suzuki  <[email protected]>
 
         Unreviewed, build fix

Modified: trunk/Source/_javascript_Core/Configurations/Base.xcconfig (276246 => 276247)


--- trunk/Source/_javascript_Core/Configurations/Base.xcconfig	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/_javascript_Core/Configurations/Base.xcconfig	2021-04-19 13:12:23 UTC (rev 276247)
@@ -98,7 +98,7 @@
 GCC_WARN_UNUSED_VARIABLE = YES;
 CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
 PREBINDING = NO;
-WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wextra-tokens -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wliteral-conversion;
+WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wextra-tokens -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wliteral-conversion -Wthread-safety;
 
 HEADER_SEARCH_PATHS = . "${BUILT_PRODUCTS_DIR}/usr/local/include" $(HEADER_SEARCH_PATHS);
 

Modified: trunk/Source/WTF/ChangeLog (276246 => 276247)


--- trunk/Source/WTF/ChangeLog	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/WTF/ChangeLog	2021-04-19 13:12:23 UTC (rev 276247)
@@ -1,3 +1,44 @@
+2021-04-19  Kimmo Kinnunen  <[email protected]>
+
+        Enable -Wthread-safety, add attributes to custom lock classes, and provide macros to declare guards
+        https://bugs.webkit.org/show_bug.cgi?id=221614
+        <rdar://problem/74396781>
+
+        Reviewed by David Kilzer.
+
+        Implement rudimentary support for clang thread safety analysis.
+        The added macros can be used to declare which member variables or
+        global variables are locked by which mutexes. The compiler will
+        check statically that the mutexes are held correctly. The checking
+        is intra procedural, not global.
+
+        * Configurations/Base.xcconfig:
+            Add -Wthread-safety to compile flags.
+
+        * wtf/CheckedLock.h: Added.
+        Add CheckedLock, a Lock variant that is amenable to static
+        analysis.
+        Add a Locker specialization for CheckedLock that is amenable to
+        static analysis.
+
+        Locker<CheckedLock> is a std::scoped_lock. The scoped_lock cannot be aliased,
+        since it appears that (Apple's) libcxx is not compiled with thread safety
+        analysis support enabled by default.
+
+        New types are needed due Locker move constructor and conditional locking.
+        The Locker has default usage pattern of:
+          auto locker = holdLock(m_lock);
+        This forces dynamism that removes the possibility of simple statical
+        analysis that thread safety analysis capabilities "mutex" and "scoped_lock"
+        currently implement. Most likely large fraction of call sites is due to historical
+        lack of CTAD and as such can be converted to less general form.
+        Once the pattern is not used by default, CheckedLock can be deleted
+        and the move dynamism bits of Locker can be moved to some more specific type
+        ("UncheckedLocker").
+
+        * wtf/ThreadSafetyAnalysis.h: Added.
+        Add macro wrappers around clang "mutex" and "scoped_lock" capability attributes.
+
 2021-04-17  Sam Weinig  <[email protected]>
 
         Move RuntimeEnabledFeatures to Settings (Part 1)

Modified: trunk/Source/WTF/Configurations/Base.xcconfig (276246 => 276247)


--- trunk/Source/WTF/Configurations/Base.xcconfig	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/WTF/Configurations/Base.xcconfig	2021-04-19 13:12:23 UTC (rev 276247)
@@ -97,7 +97,7 @@
 GCC_WARN_UNUSED_FUNCTION = YES;
 GCC_WARN_UNUSED_VARIABLE = YES;
 PREBINDING = NO;
-WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wextra-tokens -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wliteral-conversion;
+WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wextra-tokens -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wliteral-conversion -Wthread-safety;
 HEADER_SEARCH_PATHS = $(BUILT_PRODUCTS_DIR)$(WTF_INSTALL_PATH_PREFIX)/usr/local/include $(DSTROOT)$(WTF_INSTALL_PATH_PREFIX)/usr/local/include $(inherited);
 SYSTEM_HEADER_SEARCH_PATHS = $(SDK_DIR)$(WTF_INSTALL_PATH_PREFIX)/usr/local/include $(inherited);
 LIBRARY_SEARCH_PATHS = $(SDK_DIR)$(WTF_INSTALL_PATH_PREFIX)/usr/local/lib $(inherited);

Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (276246 => 276247)


--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2021-04-19 13:12:23 UTC (rev 276247)
@@ -454,6 +454,8 @@
 		7AF023B42061E16F00A8EFD6 /* ProcessPrivilege.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProcessPrivilege.cpp; sourceTree = "<group>"; };
 		7AFEC6AE1EB22AC600DADE36 /* UUID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UUID.h; sourceTree = "<group>"; };
 		7AFEC6B01EB22B5900DADE36 /* UUID.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UUID.cpp; sourceTree = "<group>"; };
+		7B2739DC2624DAAA0040F182 /* ThreadSafetyAnalysis.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ThreadSafetyAnalysis.h; sourceTree = "<group>"; };
+		7B2739DD2624DAC30040F182 /* CheckedLock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CheckedLock.h; sourceTree = "<group>"; };
 		7C137941222326C700D7A824 /* AUTHORS */ = {isa = PBXFileReference; lastKnownFileType = text; path = AUTHORS; sourceTree = "<group>"; };
 		7C137942222326D500D7A824 /* ieee.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ieee.h; sourceTree = "<group>"; };
 		7C137943222326D500D7A824 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
@@ -978,6 +980,7 @@
 				413FE8F51F8D2EAB00F6D7D7 /* CallbackAggregator.h */,
 				A8A4726A151A825A004123FF /* CheckedArithmetic.h */,
 				A8A4726B151A825A004123FF /* CheckedBoolean.h */,
+				7B2739DD2624DAC30040F182 /* CheckedLock.h */,
 				0F66B2801DC97BAB004A1D3F /* ClockType.cpp */,
 				0F66B2811DC97BAB004A1D3F /* ClockType.h */,
 				0FC4EDE51696149600F65041 /* CommaPrinter.h */,
@@ -1284,6 +1287,7 @@
 				5311BD5B1EA822F900525281 /* ThreadMessage.cpp */,
 				5311BD591EA81A9600525281 /* ThreadMessage.h */,
 				A8A4733E151A825B004123FF /* ThreadSafeRefCounted.h */,
+				7B2739DC2624DAAA0040F182 /* ThreadSafetyAnalysis.h */,
 				4468567225094FE8008CCA05 /* ThreadSanitizerSupport.h */,
 				A8A4733F151A825B004123FF /* ThreadSpecific.h */,
 				0F66B2861DC97BAB004A1D3F /* TimeWithDynamicClockType.cpp */,

Modified: trunk/Source/WTF/wtf/CMakeLists.txt (276246 => 276247)


--- trunk/Source/WTF/wtf/CMakeLists.txt	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/WTF/wtf/CMakeLists.txt	2021-04-19 13:12:23 UTC (rev 276247)
@@ -28,6 +28,7 @@
     CallbackAggregator.h
     CheckedArithmetic.h
     CheckedBoolean.h
+    CheckedLock.h
     ClockType.h
     CommaPrinter.h
     CompactPointerTuple.h
@@ -264,6 +265,7 @@
     TaggedArrayStoragePtr.h
     ThreadGroup.h
     ThreadMessage.h
+    ThreadSafetyAnalysis.h
     ThreadSafeRefCounted.h
     ThreadSanitizerSupport.h
     ThreadSpecific.h

Added: trunk/Source/WTF/wtf/CheckedLock.h (0 => 276247)


--- trunk/Source/WTF/wtf/CheckedLock.h	                        (rev 0)
+++ trunk/Source/WTF/wtf/CheckedLock.h	2021-04-19 13:12:23 UTC (rev 276247)
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <mutex>
+#include <wtf/Lock.h>
+#include <wtf/Locker.h>
+#include <wtf/ThreadSafetyAnalysis.h>
+
+namespace WTF {
+
+// A lock type with support for thread safety analysis.
+// To annotate a member variable or a global variable with thread ownership information,
+// use lock capability annotations defined in ThreadSafetyAnalysis.h.
+//
+// Example:
+//   class MyValue : public ThreadSafeRefCounted<MyValue>
+//   {
+//   public:
+//       void setValue(int value) { Lochker holdLock { m_lock }; m_value = value;  }
+//       void maybeSetOtherValue(int value)
+//       {
+//           if (!m_lock.tryLock())
+//              return;
+//           Locker locker { AdoptLockTag { }, m_otherLock };
+//           m_otherValue = value;
+//       }
+//   private:
+//       CheckedLock m_lock;
+//       int m_value WTF_GUARDED_BY_LOCK(m_lock) { 77 };
+//       int m_otherValue WTF_GUARDED_BY_LOCK(m_lock) { 88 };
+//   };
+// FIXME: Maybe should be folded back to Lock once holdLock is not used globally.
+class WTF_CAPABILITY_LOCK CheckedLock : Lock {
+    WTF_MAKE_NONCOPYABLE(CheckedLock);
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    constexpr CheckedLock() = default;
+    void lock() WTF_ACQUIRES_LOCK() { Lock::lock(); }
+    bool tryLock() WTF_ACQUIRES_LOCK_IF(true) { return Lock::tryLock(); }
+    bool try_lock() WTF_ACQUIRES_LOCK_IF(true) { return Lock::try_lock(); } // NOLINT: Intentional deviation to support std::scoped_lock.
+    void unlock() WTF_RELEASES_LOCK() { Lock::unlock(); }
+    void unlockFairly() WTF_RELEASES_LOCK() { Lock::unlockFairly(); }
+    void safepoint() { Lock::safepoint(); }
+    bool isHeld() const { return Lock::isHeld(); }
+    bool isLocked() const { return Lock::isLocked(); }
+};
+
+using AdoptLockTag = std::adopt_lock_t;
+
+// Locker specialization to use with CheckedLock.
+// Non-movable simple scoped lock holder.
+// Example: Locker locker { m_lock };
+template <>
+class WTF_CAPABILITY_SCOPED_LOCK Locker<CheckedLock> {
+public:
+    explicit Locker(CheckedLock& lock) WTF_ACQUIRES_LOCK(lock)
+        : m_lock(lock)
+    {
+        m_lock.lock();
+    }
+    Locker(AdoptLockTag, CheckedLock& lock) WTF_REQUIRES_LOCK(lock)
+        : m_lock(lock)
+    {
+    }
+    ~Locker() WTF_RELEASES_LOCK()
+    {
+        m_lock.unlock();
+    }
+    Locker(const Locker<CheckedLock>&) = delete;
+    Locker& operator=(const Locker<CheckedLock>&) = delete;
+private:
+    CheckedLock& m_lock;
+};
+
+Locker(CheckedLock&) -> Locker<CheckedLock>;
+Locker(AdoptLockTag, CheckedLock&) -> Locker<CheckedLock>;
+
+} // namespace WTF
+
+using WTF::CheckedLock;
+using WTF::AdoptLockTag;

Added: trunk/Source/WTF/wtf/ThreadSafetyAnalysis.h (0 => 276247)


--- trunk/Source/WTF/wtf/ThreadSafetyAnalysis.h	                        (rev 0)
+++ trunk/Source/WTF/wtf/ThreadSafetyAnalysis.h	2021-04-19 13:12:23 UTC (rev 276247)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/Compiler.h>
+
+// See <https://clang.llvm.org/docs/ThreadSafetyAnalysis.html> for details.
+
+#if COMPILER(CLANG)
+#define WTF_THREAD_ANNOTATION_ATTRIBUTE(x)  __attribute__((x))
+#else
+#define WTF_THREAD_ANNOTATION_ATTRIBUTE(x)
+#endif
+
+#define WTF_ACQUIRES_LOCK_IF(...) WTF_THREAD_ANNOTATION_ATTRIBUTE(try_acquire_capability(__VA_ARGS__))
+#define WTF_ACQUIRES_LOCK(...) WTF_THREAD_ANNOTATION_ATTRIBUTE(acquire_capability(__VA_ARGS__))
+#define WTF_ACQUIRES_SHARED_LOCK_IF(...) WTF_THREAD_ANNOTATION_ATTRIBUTE(try_acquire_shared_capability(__VA_ARGS__))
+#define WTF_ACQUIRES_SHARED_LOCK(...) WTF_THREAD_ANNOTATION_ATTRIBUTE(acquire_shared_capability(__VA_ARGS__))
+#define WTF_ASSERTS_ACQUIRED_LOCK(x) WTF_THREAD_ANNOTATION_ATTRIBUTE(assert_capability(x))
+#define WTF_ASSERTS_ACQUIRED_SHARED_LOCK(x) WTF_THREAD_ANNOTATION_ATTRIBUTE(assert_shared_capability(x))
+#define WTF_CAPABILITY_LOCK WTF_THREAD_ANNOTATION_ATTRIBUTE(capability("mutex"))
+#define WTF_CAPABILITY_SCOPED_LOCK WTF_THREAD_ANNOTATION_ATTRIBUTE(scoped_lockable)
+#define WTF_EXCLUDES_LOCK(...) WTF_THREAD_ANNOTATION_ATTRIBUTE(locks_excluded(__VA_ARGS__))
+#define WTF_GUARDED_BY_LOCK(x) WTF_THREAD_ANNOTATION_ATTRIBUTE(guarded_by(x))
+#define WTF_IGNORES_THREAD_SAFETY_ANALYSIS WTF_THREAD_ANNOTATION_ATTRIBUTE(no_thread_safety_analysis)
+#define WTF_POINTEE_GUARDED_BY_LOCK(x) WTF_THREAD_ANNOTATION_ATTRIBUTE(pt_guarded_by(x))
+#define WTF_RELEASES_LOCK_GENERIC(...) WTF_THREAD_ANNOTATION_ATTRIBUTE(release_generic_capability(__VA_ARGS__))
+#define WTF_RELEASES_LOCK(...) WTF_THREAD_ANNOTATION_ATTRIBUTE(release_capability(__VA_ARGS__))
+#define WTF_RELEASES_SHARED_LOCK(...) WTF_THREAD_ANNOTATION_ATTRIBUTE(release_shared_capability(__VA_ARGS__))
+#define WTF_REQUIRES_LOCK(...) WTF_THREAD_ANNOTATION_ATTRIBUTE(requires_capability(__VA_ARGS__))
+#define WTF_REQUIRES_SHARED_LOCK(...) WTF_THREAD_ANNOTATION_ATTRIBUTE(requires_shared_capability(__VA_ARGS__))
+#define WTF_RETURNS_LOCK(x) WTF_THREAD_ANNOTATION_ATTRIBUTE(lock_returned(x))

Modified: trunk/Source/WebCore/ChangeLog (276246 => 276247)


--- trunk/Source/WebCore/ChangeLog	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/WebCore/ChangeLog	2021-04-19 13:12:23 UTC (rev 276247)
@@ -1,3 +1,15 @@
+2021-04-19  Kimmo Kinnunen  <[email protected]>
+
+        Enable -Wthread-safety, add attributes to custom lock classes, and provide macros to declare guards
+        https://bugs.webkit.org/show_bug.cgi?id=221614
+        <rdar://problem/74396781>
+
+        Reviewed by David Kilzer.
+
+        Add -Wthread-safety to compile flags.
+
+        * Configurations/Base.xcconfig:
+
 2021-04-19  Youenn Fablet  <[email protected]>
 
         Make RealtimeIncomingAudioSourceCocoa preallocate audio buffer

Modified: trunk/Source/WebCore/Configurations/Base.xcconfig (276246 => 276247)


--- trunk/Source/WebCore/Configurations/Base.xcconfig	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/WebCore/Configurations/Base.xcconfig	2021-04-19 13:12:23 UTC (rev 276247)
@@ -90,7 +90,7 @@
 GCC_WARN_UNINITIALIZED_AUTOS = YES;
 GCC_WARN_UNUSED_FUNCTION = YES;
 GCC_WARN_UNUSED_VARIABLE = YES;
-WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wextra-tokens -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wno-unknown-warning-option -Wliteral-conversion;
+WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wextra-tokens -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wno-unknown-warning-option -Wliteral-conversion -Wthread-safety;
 
 TARGET_MACOS_LEGACY_VERSION_IDENTIFIER = $(TARGET_MACOS_LEGACY_VERSION_IDENTIFIER_$(MACOSX_DEPLOYMENT_TARGET:base))
 TARGET_MACOS_LEGACY_VERSION_IDENTIFIER_10 = 10$(MACOSX_DEPLOYMENT_TARGET:suffix:identifier)

Modified: trunk/Source/WebCore/PAL/ChangeLog (276246 => 276247)


--- trunk/Source/WebCore/PAL/ChangeLog	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/WebCore/PAL/ChangeLog	2021-04-19 13:12:23 UTC (rev 276247)
@@ -1,3 +1,15 @@
+2021-04-19  Kimmo Kinnunen  <[email protected]>
+
+        Enable -Wthread-safety, add attributes to custom lock classes, and provide macros to declare guards
+        https://bugs.webkit.org/show_bug.cgi?id=221614
+        <rdar://problem/74396781>
+
+        Reviewed by David Kilzer.
+
+        Add -Wthread-safety to compile flags.
+
+        * Configurations/Base.xcconfig:
+
 2021-04-09  Jer Noble  <[email protected]>
 
         WTF SoftLinking macros can cause collisions with their target functions

Modified: trunk/Source/WebCore/PAL/Configurations/Base.xcconfig (276246 => 276247)


--- trunk/Source/WebCore/PAL/Configurations/Base.xcconfig	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/WebCore/PAL/Configurations/Base.xcconfig	2021-04-19 13:12:23 UTC (rev 276247)
@@ -88,7 +88,7 @@
 GCC_WARN_UNINITIALIZED_AUTOS = YES;
 GCC_WARN_UNUSED_FUNCTION = YES;
 GCC_WARN_UNUSED_VARIABLE = YES;
-WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wextra-tokens -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wno-unknown-warning-option -Wliteral-conversion;
+WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wextra-tokens -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wno-unknown-warning-option -Wliteral-conversion -Wthread-safety;
 
 TARGET_MACOS_LEGACY_VERSION_IDENTIFIER = $(TARGET_MACOS_LEGACY_VERSION_IDENTIFIER_$(MACOSX_DEPLOYMENT_TARGET:base))
 TARGET_MACOS_LEGACY_VERSION_IDENTIFIER_10 = 10$(MACOSX_DEPLOYMENT_TARGET:suffix:identifier)

Modified: trunk/Source/WebInspectorUI/ChangeLog (276246 => 276247)


--- trunk/Source/WebInspectorUI/ChangeLog	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/WebInspectorUI/ChangeLog	2021-04-19 13:12:23 UTC (rev 276247)
@@ -1,3 +1,15 @@
+2021-04-19  Kimmo Kinnunen  <[email protected]>
+
+        Enable -Wthread-safety, add attributes to custom lock classes, and provide macros to declare guards
+        https://bugs.webkit.org/show_bug.cgi?id=221614
+        <rdar://problem/74396781>
+
+        Reviewed by David Kilzer.
+
+        Add -Wthread-safety to compile flags.
+
+        * Configurations/Base.xcconfig:
+
 2021-04-16  Devin Rousso  <[email protected]>
 
         Web Inspector: REGRESSION(?): Graphics: dropping a recording leaves behind a drop zone view

Modified: trunk/Source/WebInspectorUI/Configurations/Base.xcconfig (276246 => 276247)


--- trunk/Source/WebInspectorUI/Configurations/Base.xcconfig	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/WebInspectorUI/Configurations/Base.xcconfig	2021-04-19 13:12:23 UTC (rev 276247)
@@ -61,7 +61,7 @@
 GCC_WARN_UNINITIALIZED_AUTOS = YES
 GCC_WARN_UNUSED_FUNCTION = YES;
 GCC_WARN_UNUSED_VARIABLE = YES
-WARNING_CFLAGS = -Wall -W -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wformat-security -Wmissing-format-attribute -Wpointer-arith -Wwrite-strings -Wno-unused-parameter -Wexit-time-destructors -Wvla -Wliteral-conversion;
+WARNING_CFLAGS = -Wall -W -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wformat-security -Wmissing-format-attribute -Wpointer-arith -Wwrite-strings -Wno-unused-parameter -Wexit-time-destructors -Wvla -Wliteral-conversion -Wthread-safety;
 
 SUPPORTED_PLATFORMS = iphoneos iphonesimulator macosx appletvos appletvsimulator watchos watchsimulator;
 SUPPORTS_MACCATALYST = YES;

Modified: trunk/Source/WebKit/ChangeLog (276246 => 276247)


--- trunk/Source/WebKit/ChangeLog	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/WebKit/ChangeLog	2021-04-19 13:12:23 UTC (rev 276247)
@@ -1,3 +1,15 @@
+2021-04-19  Kimmo Kinnunen  <[email protected]>
+
+        Enable -Wthread-safety, add attributes to custom lock classes, and provide macros to declare guards
+        https://bugs.webkit.org/show_bug.cgi?id=221614
+        <rdar://problem/74396781>
+
+        Reviewed by David Kilzer.
+
+        Add -Wthread-safety to compile flags.
+
+        * Configurations/Base.xcconfig:
+
 2021-04-18  Chris Dumez  <[email protected]>
 
         Update LibWebRTCCodecsProxy to use a Lock

Modified: trunk/Source/WebKit/Configurations/Base.xcconfig (276246 => 276247)


--- trunk/Source/WebKit/Configurations/Base.xcconfig	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/WebKit/Configurations/Base.xcconfig	2021-04-19 13:12:23 UTC (rev 276247)
@@ -86,7 +86,7 @@
 GCC_WARN_UNUSED_VARIABLE = YES;
 OTHER_MIGFLAGS = -F$(BUILT_PRODUCTS_DIR);
 PREBINDING = NO;
-WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wextra-tokens -Wformat-security -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wno-unused-parameter -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wliteral-conversion;
+WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wextra-tokens -Wformat-security -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wno-unused-parameter -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wliteral-conversion -Wthread-safety;
 
 SWIFT_VERSION = 5.0;
 

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (276246 => 276247)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2021-04-19 13:12:23 UTC (rev 276247)
@@ -1,3 +1,15 @@
+2021-04-19  Kimmo Kinnunen  <[email protected]>
+
+        Enable -Wthread-safety, add attributes to custom lock classes, and provide macros to declare guards
+        https://bugs.webkit.org/show_bug.cgi?id=221614
+        <rdar://problem/74396781>
+
+        Reviewed by David Kilzer.
+
+        Add -Wthread-safety to compile flags.
+
+        * Configurations/Base.xcconfig:
+
 2021-04-17  Wenson Hsieh  <[email protected]>
 
         [macOS] Add some support for webpage translation in WebKitLegacy

Modified: trunk/Source/WebKitLegacy/mac/Configurations/Base.xcconfig (276246 => 276247)


--- trunk/Source/WebKitLegacy/mac/Configurations/Base.xcconfig	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/WebKitLegacy/mac/Configurations/Base.xcconfig	2021-04-19 13:12:23 UTC (rev 276247)
@@ -88,7 +88,7 @@
 OTHER_MIGFLAGS = -F$(BUILT_PRODUCTS_DIR);
 CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
 PREBINDING = NO;
-WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wextra-tokens -Wformat-security -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wno-unused-parameter -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wliteral-conversion;
+WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wextra-tokens -Wformat-security -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wno-unused-parameter -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wliteral-conversion -Wthread-safety;
 
 TARGET_MACOS_LEGACY_VERSION_IDENTIFIER = $(TARGET_MACOS_LEGACY_VERSION_IDENTIFIER_$(MACOSX_DEPLOYMENT_TARGET:base))
 TARGET_MACOS_LEGACY_VERSION_IDENTIFIER_10 = 10$(MACOSX_DEPLOYMENT_TARGET:suffix:identifier)

Modified: trunk/Source/bmalloc/ChangeLog (276246 => 276247)


--- trunk/Source/bmalloc/ChangeLog	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/bmalloc/ChangeLog	2021-04-19 13:12:23 UTC (rev 276247)
@@ -1,3 +1,15 @@
+2021-04-19  Kimmo Kinnunen  <[email protected]>
+
+        Enable -Wthread-safety, add attributes to custom lock classes, and provide macros to declare guards
+        https://bugs.webkit.org/show_bug.cgi?id=221614
+        <rdar://problem/74396781>
+
+        Reviewed by David Kilzer.
+
+        Add -Wthread-safety to compile flags.
+
+        * Configurations/Base.xcconfig:
+
 2021-03-26  Jessie Berlin  <[email protected]>
 
         Update the BEFORE/SINCE, SYSTEM_VERSION_PREFIX, and MACOSX_DEPLOYMENT_TARGET flags

Modified: trunk/Source/bmalloc/Configurations/Base.xcconfig (276246 => 276247)


--- trunk/Source/bmalloc/Configurations/Base.xcconfig	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Source/bmalloc/Configurations/Base.xcconfig	2021-04-19 13:12:23 UTC (rev 276247)
@@ -94,7 +94,7 @@
 GCC_WARN_UNUSED_FUNCTION = YES;
 GCC_WARN_UNUSED_VARIABLE = YES;
 PREBINDING = NO;
-WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wextra-tokens -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wliteral-conversion;
+WARNING_CFLAGS = -Wall -Wextra -Wcast-qual -Wchar-subscripts -Wconditional-uninitialized -Wextra-tokens -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wundef -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wliteral-conversion -Wthread-safety;
 
 TARGET_MACOS_LEGACY_VERSION_IDENTIFIER = $(TARGET_MACOS_LEGACY_VERSION_IDENTIFIER_$(MACOSX_DEPLOYMENT_TARGET:base))
 TARGET_MACOS_LEGACY_VERSION_IDENTIFIER_10 = 10$(MACOSX_DEPLOYMENT_TARGET:suffix:identifier)

Modified: trunk/Tools/ChangeLog (276246 => 276247)


--- trunk/Tools/ChangeLog	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Tools/ChangeLog	2021-04-19 13:12:23 UTC (rev 276247)
@@ -1,3 +1,20 @@
+2021-04-19  Kimmo Kinnunen  <[email protected]>
+
+        Enable -Wthread-safety, add attributes to custom lock classes, and provide macros to declare guards
+        https://bugs.webkit.org/show_bug.cgi?id=221614
+        <rdar://problem/74396781>
+
+        Reviewed by David Kilzer.
+
+        * TestWebKitAPI/Configurations/Base.xcconfig:
+        Add -Wthread-safety to compile flags.
+
+        * TestWebKitAPI/CMakeLists.txt:
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WTF/CheckedLock.cpp: Added.
+        (TestWebKitAPI::TEST):
+        Implement a test for testing that CheckedLock compiles.
+
 2021-04-18  Zalan Bujtas  <[email protected]>
 
         Update name in contributors.json

Modified: trunk/Tools/TestWebKitAPI/CMakeLists.txt (276246 => 276247)


--- trunk/Tools/TestWebKitAPI/CMakeLists.txt	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Tools/TestWebKitAPI/CMakeLists.txt	2021-04-19 13:12:23 UTC (rev 276247)
@@ -29,6 +29,7 @@
     Tests/WTF/BumpPointerAllocator.cpp
     Tests/WTF/CString.cpp
     Tests/WTF/CheckedArithmeticOperations.cpp
+    Tests/WTF/CheckedLockTest.cpp
     Tests/WTF/CompactRefPtrTuple.cpp
     Tests/WTF/CompactUniquePtrTuple.cpp
     Tests/WTF/ConcurrentPtrHashSet.cpp

Modified: trunk/Tools/TestWebKitAPI/Configurations/Base.xcconfig (276246 => 276247)


--- trunk/Tools/TestWebKitAPI/Configurations/Base.xcconfig	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Tools/TestWebKitAPI/Configurations/Base.xcconfig	2021-04-19 13:12:23 UTC (rev 276247)
@@ -72,7 +72,7 @@
 CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
 GCC_WARN_64_TO_32_BIT_CONVERSION[arch=arm64*] = NO;
 GCC_WARN_64_TO_32_BIT_CONVERSION[arch=x86_64] = NO;
-WARNING_CFLAGS = -Wall -W -Wno-unused-parameter
+WARNING_CFLAGS = -Wall -W -Wno-unused-parameter -Wthread-safety
 
 DEBUG_DEFINES = NDEBUG;
 DEBUG_DEFINES[config=Debug] = ;

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (276246 => 276247)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2021-04-19 11:55:43 UTC (rev 276246)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2021-04-19 13:12:23 UTC (rev 276247)
@@ -580,6 +580,7 @@
 		7AE9E5091AE5AE8B00CF874B /* test.pdf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7AE9E5081AE5AE8B00CF874B /* test.pdf */; };
 		7AEAD47F1E20116C00416EFE /* CrossPartitionFileSchemeAccess.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7AEAD47C1E20113800416EFE /* CrossPartitionFileSchemeAccess.mm */; };
 		7AEAD4811E20122700416EFE /* CrossPartitionFileSchemeAccess.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7AEAD47D1E20114E00416EFE /* CrossPartitionFileSchemeAccess.html */; };
+		7B2739E0262571CC0040F182 /* CheckedLockTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B2739DF262571CC0040F182 /* CheckedLockTest.cpp */; };
 		7B7D096A2519F8F90017A078 /* WebGLNoCrashOnOtherThreadAccess.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7B7D09692519F8F90017A078 /* WebGLNoCrashOnOtherThreadAccess.mm */; };
 		7C1AF7951E8DCBAB002645B9 /* PrepareForMoveToWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7C1AF7931E8DCBAB002645B9 /* PrepareForMoveToWindow.mm */; };
 		7C3965061CDD74F90094DBB8 /* ColorTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C3965051CDD74F90094DBB8 /* ColorTests.cpp */; };
@@ -2423,6 +2424,7 @@
 		7AE9E5081AE5AE8B00CF874B /* test.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = test.pdf; sourceTree = "<group>"; };
 		7AEAD47C1E20113800416EFE /* CrossPartitionFileSchemeAccess.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CrossPartitionFileSchemeAccess.mm; sourceTree = "<group>"; };
 		7AEAD47D1E20114E00416EFE /* CrossPartitionFileSchemeAccess.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = CrossPartitionFileSchemeAccess.html; path = Tests/mac/CrossPartitionFileSchemeAccess.html; sourceTree = SOURCE_ROOT; };
+		7B2739DF262571CC0040F182 /* CheckedLockTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CheckedLockTest.cpp; sourceTree = "<group>"; };
 		7B7D09692519F8F90017A078 /* WebGLNoCrashOnOtherThreadAccess.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebGLNoCrashOnOtherThreadAccess.mm; sourceTree = "<group>"; };
 		7C1AF7931E8DCBAB002645B9 /* PrepareForMoveToWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PrepareForMoveToWindow.mm; sourceTree = "<group>"; };
 		7C3965051CDD74F90094DBB8 /* ColorTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ColorTests.cpp; sourceTree = "<group>"; };
@@ -4362,6 +4364,7 @@
 				93A427AE180DA60F00CD24D7 /* BoxPtr.cpp */,
 				0451A5A6235E438E009DF945 /* BumpPointerAllocator.cpp */,
 				A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */,
+				7B2739DF262571CC0040F182 /* CheckedLockTest.cpp */,
 				E302BDA92404B92300865277 /* CompactRefPtrTuple.cpp */,
 				9B0C051824FDFB7000F2FE31 /* CompactUniquePtrTuple.cpp */,
 				0F30CB5B1FCE1792004B5323 /* ConcurrentPtrHashSet.cpp */,
@@ -5117,6 +5120,7 @@
 				7C83DF181D0A590C00FEBCF3 /* BoxPtr.cpp in Sources */,
 				04DB2396235E43EC00328F17 /* BumpPointerAllocator.cpp in Sources */,
 				7C83DEA01D0A590C00FEBCF3 /* CheckedArithmeticOperations.cpp in Sources */,
+				7B2739E0262571CC0040F182 /* CheckedLockTest.cpp in Sources */,
 				E302BDAA2404B92400865277 /* CompactRefPtrTuple.cpp in Sources */,
 				9B0C051924FDFB7D00F2FE31 /* CompactUniquePtrTuple.cpp in Sources */,
 				0F30CB5C1FCE1796004B5323 /* ConcurrentPtrHashSet.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WTF/CheckedLockTest.cpp (0 => 276247)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/CheckedLockTest.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/CheckedLockTest.cpp	2021-04-19 13:12:23 UTC (rev 276247)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include <wtf/CheckedLock.h>
+
+#include <wtf/StdLibExtras.h>
+
+namespace TestWebKitAPI {
+
+namespace {
+class MyValue {
+public:
+    void setValue(int value)
+    {
+        Locker holdLock { m_lock };
+        m_value = value;
+    }
+    void maybeSetOtherValue(int value)
+    {
+        if (!m_otherLock.tryLock())
+            return;
+        Locker holdLock { AdoptLockTag { }, m_otherLock };
+        m_otherValue = value;
+    }
+    // This function can be used to manually check that compile fails.
+    template<typename T> void shouldFailCompile(T t)
+    {
+        m_value = t;
+    }
+    private:
+    CheckedLock m_lock;
+    int m_value WTF_GUARDED_BY_LOCK(m_lock) { 77 };
+    CheckedLock m_otherLock;
+    int m_otherValue WTF_GUARDED_BY_LOCK(m_otherLock) { 88 };
+};
+
+}
+
+TEST(WTF_CheckedLock, CheckedLockCompiles)
+{
+    MyValue v;
+    v.setValue(7);
+    v.maybeSetOtherValue(34);
+}
+
+} // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to