[webkit-changes] [WebKit/WebKit] 8ed46d: WTF::ThreadAssertion is not useful as most of the ...

Kimmo Kinnunen noreply at github.com
Fri Oct 7 09:26:26 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 8ed46d3dd638db662ea8093cec940b1b00992ecf
      https://github.com/WebKit/WebKit/commit/8ed46d3dd638db662ea8093cec940b1b00992ecf
  Author: Kimmo Kinnunen <kkinnunen at apple.com>
  Date:   2022-10-07 (Fri, 07 Oct 2022)

  Changed paths:
    M Source/WTF/wtf/MainThread.h
    M Source/WTF/wtf/ThreadAssertions.h
    M Source/WTF/wtf/Threading.cpp
    M Source/WTF/wtf/Threading.h
    M Source/WTF/wtf/WorkQueue.h
    M Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp
    M Source/WTF/wtf/generic/MainThreadGeneric.cpp
    M Source/WTF/wtf/generic/WorkQueueGeneric.cpp
    M Source/WTF/wtf/win/MainThreadWin.cpp
    M Source/WebCore/platform/graphics/mac/DisplayConfigurationMonitor.cpp
    M Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp
    M Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayer.h
    M Tools/TestWebKitAPI/Tests/WTF/ThreadAssertionsTest.cpp
    M Tools/TestWebKitAPI/Tests/WTF/WorkQueue.cpp

  Log Message:
  -----------
  WTF::ThreadAssertion is not useful as most of the code is run with a WorkQueue
https://bugs.webkit.org/show_bug.cgi?id=237026
rdar://problem/89608226

Reviewed by Chris Dumez.

Rename ThreadAssertion to ThreadlikeAssertion, and assert that if the assertion is created in a WorkQueue,
the assertion checks for the work queue. If it is created on a Thread, it checks for that.

Implement for non-Cocoa by just using thread id for the sequence id. All WorkQueues have unique threads
and all Threads have unique ids. This means WorkQueues can be distinquished from Threads without WorkQueues.

Implement for Cocoa by using the same uid id namespace for WorkQueues as Threads have. Store the uid
in a Dispatch dispatch queue specific field. If the code is not running in Dispatch, return the current
thread uid. Since the uid namespace is the same, WorkQueues can be distinuished from Threads without WorkQueues.

In both cases, non-WebKit platform threads get also a Thread, so they're distinquished from WorkQueues.

Currently it is common in WebKit code to use a pattern of:
ASSERT(RunLoop::isMain()) -- This is not run in a work queue or a specific thread
ASSERT(!RunLoop::isMain()) -- This is run in a specific thread, but because we use WorkQueues,
we cannot actually assert the specific thread.

This pattern could be for example used to assert that object is created and destroyed in
correct thread.

After this commit, that can be expressed more exactly as:
 NO_UNIQUE_ADDRESS ThreadlikeAssertion m_owner;

* Source/WTF/wtf/MainThread.h:
(WTF::WTF_ASSERTS_ACQUIRED_CAPABILITY):
* Source/WTF/wtf/ThreadAssertions.h:
(WTF::WTF_ASSERTS_ACQUIRED_CAPABILITY):
(WTF::Threadlike::createThreadlikeAssertion):
* Source/WTF/wtf/Threading.cpp:
(WTF::Threadlike::currentSequence):
* Source/WTF/wtf/Threading.h:
(WTF::WTF_ASSERTS_ACQUIRED_CAPABILITY):
(WTF::Thread::Thread): Deleted.
* Source/WTF/wtf/WorkQueue.h:
(WTF::WTF_ASSERTS_ACQUIRED_CAPABILITY):
* Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp:
(WTF::WorkQueueBase::platformInitialize):
(WTF::WorkQueue::WorkQueue):
(WTF::WorkQueue::threadlikeAssertion const):
(WTF::WorkQueue::assertIsCurrent const): Deleted.
* Source/WTF/wtf/generic/WorkQueueGeneric.cpp:
(WTF::WorkQueueBase::threadlikeAssertion const):
(WTF::WorkQueue::assertIsCurrent const): Deleted.
* Source/WebCore/platform/graphics/mac/DisplayConfigurationMonitor.cpp:
* Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp:
* Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayer.h:
* Tools/TestWebKitAPI/Tests/WTF/ThreadAssertionsTest.cpp:
* Tools/TestWebKitAPI/Tests/WTF/WorkQueue.cpp:
(TestWebKitAPI::TEST):

Canonical link: https://commits.webkit.org/255274@main




More information about the webkit-changes mailing list