[Webkit-unassigned] [Bug 199831] New: [WTF] Add DataMutex and MainThreadData wrappers

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Jul 16 09:27:32 PDT 2019


https://bugs.webkit.org/show_bug.cgi?id=199831

            Bug ID: 199831
           Summary: [WTF] Add DataMutex and MainThreadData wrappers
           Product: WebKit
           Version: WebKit Nightly Build
          Hardware: Unspecified
                OS: Unspecified
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: Web Template Framework
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: aboya at igalia.com

DataMutex<T> stores an instance of T in a private member along with a
mutex. In order to use its fields, users need to instantiate a
DataMutex<T>::LockedWrapper instance in the stack. This class uses
RAII to lock and unlock the mutex in construction and destruction
respectively, and by using the arrow operator lets the user access T's
members.

This way, DataMutex<T> prevents most instances of accidental access to
data fields that should only be read and modified in an atomic matter.

Still, both the Lock and the LockHolder are exposed once the user has
taken the lock so that special cases such as waiting for a condition
variable or performing an early unlock are doable.

MainThreadData<T> is another wrapper class, in this case for data
fields that should only be accessed from the main thread. In this
case, it works similar to a smart pointer, except that (1) there is no
actual memory indirection, T is stored directly inside
MainThreadData<T> and (2) attempts to use the -> or * operator have an
isMainThread() assertion.

Together, these two wrapper classes make it easier to write
multi-threaded code in a safer, more self-documented way by letting
the author group data into structures that have certain access safety
requirements.

These structures were originally part of the new GStreamer
WebKitMediaSrc rework patch: https://bugs.webkit.org/show_bug.cgi?id=199719

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20190716/b506881c/attachment.html>


More information about the webkit-unassigned mailing list