Changeset 276691 in webkit
- Timestamp:
- Apr 27, 2021, 11:26:12 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 12 edited
- 1 copied
-
Source/WTF/ChangeLog (modified) (1 diff)
-
Source/WTF/WTF.xcodeproj/project.pbxproj (modified) (2 diffs)
-
Source/WTF/wtf/CMakeLists.txt (modified) (1 diff)
-
Source/WTF/wtf/CheckedCondition.h (added)
-
Source/WTF/wtf/CheckedLock.h (modified) (1 diff)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/Platform/IPC/Connection.cpp (modified) (5 diffs)
-
Source/WebKit/Platform/IPC/Connection.h (modified) (3 diffs)
-
Source/WebKit/Shared/mac/MediaFormatReader/MediaTrackReader.cpp (modified) (6 diffs)
-
Source/WebKit/Shared/mac/MediaFormatReader/MediaTrackReader.h (modified) (2 diffs)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (modified) (4 diffs)
-
Tools/TestWebKitAPI/Tests/WTF/CheckedConditionTest.cpp (copied) (copied from trunk/Tools/TestWebKitAPI/Tests/WTF/CheckedLockTest.cpp ) (1 diff)
-
Tools/TestWebKitAPI/Tests/WTF/CheckedLockTest.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r276682 r276691 1 2021-04-27 Kimmo Kinnunen <kkinnunen@apple.com> 2 3 Add a Condition type that supports thread safety analysis 4 https://bugs.webkit.org/show_bug.cgi?id=224970 5 6 Reviewed by Darin Adler. 7 8 Add CheckedCondition, a condition variable to be used with CheckedLock. 9 Use thread safety analysis annotations for CheckedCondition. 10 11 * WTF.xcodeproj/project.pbxproj: 12 * wtf/CMakeLists.txt: 13 * wtf/CheckedCondition.h: Added. 14 * wtf/CheckedLock.h: 15 1 16 2021-04-27 Ben Nham <nham@apple.com> 2 17 -
trunk/Source/WTF/WTF.xcodeproj/project.pbxproj
r276303 r276691 457 457 7B2739DC2624DAAA0040F182 /* ThreadSafetyAnalysis.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ThreadSafetyAnalysis.h; sourceTree = "<group>"; }; 458 458 7B2739DD2624DAC30040F182 /* CheckedLock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CheckedLock.h; sourceTree = "<group>"; }; 459 7B2739F0263179C30040F182 /* CheckedCondition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CheckedCondition.h; sourceTree = "<group>"; }; 459 460 7C137941222326C700D7A824 /* AUTHORS */ = {isa = PBXFileReference; lastKnownFileType = text; path = AUTHORS; sourceTree = "<group>"; }; 460 461 7C137942222326D500D7A824 /* ieee.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ieee.h; sourceTree = "<group>"; }; … … 982 983 A8A4726A151A825A004123FF /* CheckedArithmetic.h */, 983 984 A8A4726B151A825A004123FF /* CheckedBoolean.h */, 985 7B2739F0263179C30040F182 /* CheckedCondition.h */, 984 986 7B2739DD2624DAC30040F182 /* CheckedLock.h */, 985 987 0F66B2801DC97BAB004A1D3F /* ClockType.cpp */, -
trunk/Source/WTF/wtf/CMakeLists.txt
r276303 r276691 29 29 CheckedArithmetic.h 30 30 CheckedBoolean.h 31 CheckedCondition.h 31 32 CheckedLock.h 32 33 ClockType.h -
trunk/Source/WTF/wtf/CheckedLock.h
r276247 r276691 68 68 bool isHeld() const { return Lock::isHeld(); } 69 69 bool isLocked() const { return Lock::isLocked(); } 70 friend class CheckedCondition; 70 71 }; 71 72 -
trunk/Source/WebKit/ChangeLog
r276689 r276691 1 2021-04-27 Kimmo Kinnunen <kkinnunen@apple.com> 2 3 Add a Condition type that supports thread safety analysis 4 https://bugs.webkit.org/show_bug.cgi?id=224970 5 6 Reviewed by Darin Adler. 7 8 Use CheckedCondition and CheckedLock as an example of the 9 added implementations. 10 11 * Platform/IPC/Connection.cpp: 12 (IPC::Connection::waitForMessage): 13 (IPC::Connection::processIncomingMessage): 14 (IPC::Connection::connectionDidClose): 15 * Platform/IPC/Connection.h: 16 (IPC::Connection::WTF_GUARDED_BY_LOCK): 17 Use CheckedCondition (as an example). 18 19 Mark up variables protected by 20 IPC::Connection::m_waitForMessageMutex 21 to use thread safety analysis. 22 23 * Shared/mac/MediaFormatReader/MediaTrackReader.cpp: 24 (WebKit::MediaTrackReader::greatestPresentationTime const): 25 Fix unlocked access. 26 27 (WebKit::MediaTrackReader::addSample): 28 (WebKit::MediaTrackReader::waitForSample const): 29 (WebKit::MediaTrackReader::finishParsing): 30 (WebKit::MediaTrackReader::copyProperty): 31 (WebKit::MediaTrackReader::finalize): 32 * Shared/mac/MediaFormatReader/MediaTrackReader.h: 33 Use CheckedCondition (as an example). 34 35 Mark up variables protected by 36 MediaTrackReader::m_sampleStorageLock 37 to use thread safety analysis. 38 1 39 2021-04-27 Chris Dumez <cdumez@apple.com> 2 40 -
trunk/Source/WebKit/Platform/IPC/Connection.cpp
r276678 r276691 521 521 522 522 { 523 auto locker = holdLock(m_waitForMessageMutex);523 Locker locker { m_waitForMessageMutex }; 524 524 525 525 // We don't support having multiple clients waiting for messages. … … 570 570 SyncMessageState::singleton().dispatchMessages(); 571 571 572 std::unique_lock<Lock> lock(m_waitForMessageMutex);572 Locker lock { m_waitForMessageMutex }; 573 573 574 574 if (m_waitingForMessage->decoder) { … … 579 579 580 580 // Now we wait. 581 bool didTimeout = !m_waitForMessageCondition.waitUntil( lock, timeout.deadline());581 bool didTimeout = !m_waitForMessageCondition.waitUntil(m_waitForMessageMutex, timeout.deadline()); 582 582 // We timed out, lost our connection, or a sync message came in with InterruptWaitingIfSyncMessageArrives, so stop waiting. 583 583 if (didTimeout || m_waitingForMessage->messageWaitingInterrupted) { … … 749 749 750 750 // FIXME: These are practically the same mutex, so maybe they could be merged. 751 auto waitForMessagesLocker = holdLock(m_waitForMessageMutex);751 Locker waitForMessagesLocker { m_waitForMessageMutex }; 752 752 753 753 auto incomingMessagesLocker = holdLock(m_incomingMessagesMutex); … … 867 867 868 868 { 869 auto locker = holdLock(m_waitForMessageMutex);869 Locker locker { m_waitForMessageMutex }; 870 870 871 871 ASSERT(m_shouldWaitForMessages); -
trunk/Source/WebKit/Platform/IPC/Connection.h
r276678 r276691 34 34 #include "MessageReceiver.h" 35 35 #include "Timeout.h" 36 #include <wtf/CheckedCondition.h> 37 #include <wtf/CheckedLock.h> 36 38 #include <wtf/CompletionHandler.h> 37 #include <wtf/Condition.h>38 39 #include <wtf/Deque.h> 39 40 #include <wtf/Forward.h> … … 412 413 Lock m_outgoingMessagesMutex; 413 414 Deque<UniqueRef<Encoder>> m_outgoingMessages; 414 415 C ondition m_waitForMessageCondition;416 Lock m_waitForMessageMutex;415 416 CheckedCondition m_waitForMessageCondition; 417 CheckedLock m_waitForMessageMutex; 417 418 418 419 struct WaitForMessageState; 419 WaitForMessageState* m_waitingForMessage { nullptr };420 WaitForMessageState* m_waitingForMessage WTF_GUARDED_BY_LOCK(m_waitForMessageMutex) { nullptr }; // NOLINT 420 421 421 422 class SyncMessageState; … … 423 424 Lock m_syncReplyStateMutex; 424 425 bool m_shouldWaitForSyncReplies; 425 bool m_shouldWaitForMessages ;426 bool m_shouldWaitForMessages WTF_GUARDED_BY_LOCK(m_waitForMessageMutex); 426 427 struct PendingSyncReply; 427 428 Vector<PendingSyncReply> m_pendingSyncReplies; -
trunk/Source/WebKit/Shared/mac/MediaFormatReader/MediaTrackReader.cpp
r274378 r276691 88 88 MediaTime MediaTrackReader::greatestPresentationTime() const 89 89 { 90 Locker locker { m_sampleStorageLock }; 90 91 auto& sampleMap = m_sampleStorage->sampleMap; 91 92 if (sampleMap.empty()) … … 99 100 { 100 101 ASSERT(!isMainRunLoop()); 101 auto locker = holdLock(m_sampleStorageLock);102 Locker locker { m_sampleStorageLock }; 102 103 if (!m_sampleStorage) 103 104 m_sampleStorage = makeUnique<SampleStorage>(); … … 117 118 void MediaTrackReader::waitForSample(Function<bool(SampleMap&, bool)>&& predicate) const 118 119 { 119 auto locker = holdLock(m_sampleStorageLock);120 Locker locker { m_sampleStorageLock }; 120 121 if (!m_sampleStorage) 121 122 m_sampleStorage = makeUnique<SampleStorage>(); 122 123 m_sampleStorageCondition.wait(m_sampleStorageLock, [predicate = WTFMove(predicate), this] { 124 assertIsHeld(m_sampleStorageLock); 123 125 return predicate(m_sampleStorage->sampleMap, m_sampleStorage->hasAllSamples); 124 126 }); … … 130 132 131 133 ALWAYS_LOG(LOGIDENTIFIER); 132 auto locker = holdLock(m_sampleStorageLock);134 Locker locker { m_sampleStorageLock }; 133 135 if (!m_sampleStorage) 134 136 m_sampleStorage = makeUnique<SampleStorage>(); … … 166 168 } 167 169 168 auto locker = holdLock(m_sampleStorageLock);170 Locker locker { m_sampleStorageLock }; 169 171 m_sampleStorageCondition.wait(m_sampleStorageLock, [&] { 172 assertIsHeld(m_sampleStorageLock); 170 173 return !!m_sampleStorage; 171 174 }); … … 199 202 void MediaTrackReader::finalize() 200 203 { 201 auto locker = holdLock(m_sampleStorageLock);204 Locker locker { m_sampleStorageLock }; 202 205 storageQueue().dispatch([sampleStorage = std::exchange(m_sampleStorage, nullptr)]() mutable { 203 206 sampleStorage = nullptr; -
trunk/Source/WebKit/Shared/mac/MediaFormatReader/MediaTrackReader.h
r274174 r276691 30 30 #include "CoreMediaWrapped.h" 31 31 #include <WebCore/SampleMap.h> 32 #include <wtf/Condition.h> 32 #include <wtf/CheckedCondition.h> 33 #include <wtf/CheckedLock.h> 33 34 34 35 DECLARE_CORE_MEDIA_TRAITS(TrackReader); … … 106 107 const MediaTime m_duration; 107 108 std::atomic<Enabled> m_isEnabled { Enabled::Unknown }; 108 mutable C ondition m_sampleStorageCondition;109 mutable Lock m_sampleStorageLock;110 mutable std::unique_ptr<SampleStorage> m_sampleStorage ;109 mutable CheckedCondition m_sampleStorageCondition; 110 mutable CheckedLock m_sampleStorageLock; 111 mutable std::unique_ptr<SampleStorage> m_sampleStorage WTF_GUARDED_BY_LOCK(m_sampleStorageLock); 111 112 Ref<const Logger> m_logger; 112 113 const void* m_logIdentifier; -
trunk/Tools/ChangeLog
r276670 r276691 1 2021-04-27 Kimmo Kinnunen <kkinnunen@apple.com> 2 3 Add a Condition type that supports thread safety analysis 4 https://bugs.webkit.org/show_bug.cgi?id=224970 5 6 Reviewed by Darin Adler. 7 8 A simple test for CheckedCondition to make sure 9 it compiles. 10 11 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 12 * TestWebKitAPI/Tests/WTF/CheckedConditionTest.cpp: Copied from Tools/TestWebKitAPI/Tests/WTF/CheckedLockTest.cpp. 13 (TestWebKitAPI::TEST): 14 * TestWebKitAPI/Tests/WTF/CheckedLockTest.cpp: 15 1 16 2021-04-27 Sam Sneddon <gsnedders@apple.com> 2 17 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r276620 r276691 584 584 7AEAD4811E20122700416EFE /* CrossPartitionFileSchemeAccess.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7AEAD47D1E20114E00416EFE /* CrossPartitionFileSchemeAccess.html */; }; 585 585 7B2739E0262571CC0040F182 /* CheckedLockTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B2739DF262571CC0040F182 /* CheckedLockTest.cpp */; }; 586 7B2739EF26315E7E0040F182 /* CheckedConditionTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B2739EE26315E7D0040F182 /* CheckedConditionTest.cpp */; }; 586 587 7B7D096A2519F8F90017A078 /* WebGLNoCrashOnOtherThreadAccess.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7B7D09692519F8F90017A078 /* WebGLNoCrashOnOtherThreadAccess.mm */; }; 587 588 7C1AF7951E8DCBAB002645B9 /* PrepareForMoveToWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7C1AF7931E8DCBAB002645B9 /* PrepareForMoveToWindow.mm */; }; … … 2433 2434 7AEAD47D1E20114E00416EFE /* CrossPartitionFileSchemeAccess.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = CrossPartitionFileSchemeAccess.html; path = Tests/mac/CrossPartitionFileSchemeAccess.html; sourceTree = SOURCE_ROOT; }; 2434 2435 7B2739DF262571CC0040F182 /* CheckedLockTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CheckedLockTest.cpp; sourceTree = "<group>"; }; 2436 7B2739EE26315E7D0040F182 /* CheckedConditionTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CheckedConditionTest.cpp; sourceTree = "<group>"; }; 2435 2437 7B7D09692519F8F90017A078 /* WebGLNoCrashOnOtherThreadAccess.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebGLNoCrashOnOtherThreadAccess.mm; sourceTree = "<group>"; }; 2436 2438 7C1AF7931E8DCBAB002645B9 /* PrepareForMoveToWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PrepareForMoveToWindow.mm; sourceTree = "<group>"; }; … … 4377 4379 0451A5A6235E438E009DF945 /* BumpPointerAllocator.cpp */, 4378 4380 A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */, 4381 7B2739EE26315E7D0040F182 /* CheckedConditionTest.cpp */, 4379 4382 7B2739DF262571CC0040F182 /* CheckedLockTest.cpp */, 4380 4383 E302BDA92404B92300865277 /* CompactRefPtrTuple.cpp */, … … 5133 5136 04DB2396235E43EC00328F17 /* BumpPointerAllocator.cpp in Sources */, 5134 5137 7C83DEA01D0A590C00FEBCF3 /* CheckedArithmeticOperations.cpp in Sources */, 5138 7B2739EF26315E7E0040F182 /* CheckedConditionTest.cpp in Sources */, 5135 5139 7B2739E0262571CC0040F182 /* CheckedLockTest.cpp in Sources */, 5136 5140 E302BDAA2404B92400865277 /* CompactRefPtrTuple.cpp in Sources */, -
trunk/Tools/TestWebKitAPI/Tests/WTF/CheckedConditionTest.cpp
r276690 r276691 25 25 26 26 #include "config.h" 27 #include <wtf/CheckedLock.h> 28 29 #include <wtf/StdLibExtras.h> 27 #include <wtf/CheckedCondition.h> 30 28 31 29 namespace TestWebKitAPI { 32 30 33 namespace { 34 class MyValue { 35 public: 36 void setValue(int value) 37 { 38 Locker holdLock { m_lock }; 39 m_value = value; 40 } 41 void maybeSetOtherValue(int value) 42 { 43 if (!m_otherLock.tryLock()) 44 return; 45 Locker holdLock { AdoptLockTag { }, m_otherLock }; 46 m_otherValue = value; 47 } 48 // This function can be used to manually check that compile fails. 49 template<typename T> void shouldFailCompile(T t) 50 { 51 m_value = t; 52 } 53 private: 54 CheckedLock m_lock; 55 int m_value WTF_GUARDED_BY_LOCK(m_lock) { 77 }; 56 CheckedLock m_otherLock; 57 int m_otherValue WTF_GUARDED_BY_LOCK(m_otherLock) { 88 }; 58 }; 59 60 } 61 62 TEST(WTF_CheckedLock, CheckedLockCompiles) 31 TEST(WTF_CheckedLock, CheckedConditionCompiles) 63 32 { 64 MyValue v; 65 v.setValue(7); 66 v.maybeSetOtherValue(34); 33 CheckedLock lock; 34 CheckedCondition condition; 35 Locker locker { lock }; // Comment this to ensure that thread safety analysis creates a compile error. 36 bool result = condition.waitFor(lock, 0_s); 37 EXPECT_FALSE(result); 67 38 } 68 39 -
trunk/Tools/TestWebKitAPI/Tests/WTF/CheckedLockTest.cpp
r276247 r276691 26 26 #include "config.h" 27 27 #include <wtf/CheckedLock.h> 28 29 #include <wtf/StdLibExtras.h>30 28 31 29 namespace TestWebKitAPI {
Note:
See TracChangeset
for help on using the changeset viewer.