<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [GStreamer] Use MainThreadNotifier to send notifications to main thread in WebKitWebSourceGStreamer"
   href="https://bugs.webkit.org/show_bug.cgi?id=150890#c5">Comment # 5</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [GStreamer] Use MainThreadNotifier to send notifications to main thread in WebKitWebSourceGStreamer"
   href="https://bugs.webkit.org/show_bug.cgi?id=150890">bug 150890</a>
              from <span class="vcard"><a class="email" href="mailto:cgarcia&#64;igalia.com" title="Carlos Garcia Campos &lt;cgarcia&#64;igalia.com&gt;"> <span class="fn">Carlos Garcia Campos</span></a>
</span></b>
        <pre>(In reply to <a href="show_bug.cgi?id=150890#c3">comment #3</a>)
<span class="quote">&gt; Comment on <span class="bz_obsolete"><a href="attachment.cgi?id=264788&amp;action=diff" name="attach_264788" title="Patch">attachment 264788</a> <a href="attachment.cgi?id=264788&amp;action=edit" title="Patch">[details]</a></span>
&gt; Patch
&gt; 
&gt; View in context:
&gt; <a href="https://bugs.webkit.org/attachment.cgi?id=264788&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=264788&amp;action=review</a>
&gt; 
&gt; All the uses of MainThreadNotifier&lt;&gt;::notify() need updating, otherwise
&gt; looks fine.
&gt; 
&gt; &gt; Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:177
&gt; &gt; +    // NeedData
&gt; 
&gt; I usually write these in the same C-style they're declared in: need_data,
&gt; enough_data, seek_data.
&gt; 
&gt; &gt; Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:194
&gt; &gt; +        {
&gt; &gt; +            WTF::GMutexLocker&lt;GMutex&gt; locker(*GST_OBJECT_GET_LOCK(src));
&gt; &gt; +            if (!priv-&gt;paused)
&gt; &gt; +                return;
&gt; &gt; +
&gt; &gt; +            if (!isMainThread()) {
&gt; &gt; +                GRefPtr&lt;WebKitWebSrc&gt; protector(src);
&gt; &gt; +                priv-&gt;notifier.notify(MainThreadSourceNotification::NeedData, [protector] { webKitWebSrcNeedData(protector.get()); });
&gt; &gt; +                return;
&gt; &gt; +            }
&gt; &gt; +        }
&gt; &gt; +
&gt; &gt; +        webKitWebSrcNeedData(src);
&gt; 
&gt; Can webKitWebSrcNeedData(), webKitWebSrcEnoughData() and webKitWebSrcSeek()
&gt; all be rewritten and used with the expectation that the
&gt; GST_OBJECT_GET_LOCK() is already locked? That way the lock can be held
&gt; throughout the lambda scope, and there's no need for the isMainThread()
&gt; check at this level.</span >

I thought it was possible but it's not that easy. We don't want to keep the lock until the notification happens in the main thread, so we need to take lock again before calling the callback in the lambda. 
The notifier is thread say, so we can just release the lock before calling notify()

<span class="quote">&gt; &gt; Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:656
&gt; &gt; +        if (isMainThread())
&gt; &gt; +            webKitWebSrcStart(src);
&gt; &gt; +        else {
&gt; &gt; +            GRefPtr&lt;WebKitWebSrc&gt; protector(src);
&gt; &gt; +            priv-&gt;notifier.notify(MainThreadSourceNotification::Start, [protector] { webKitWebSrcStart(protector.get()); });
&gt; &gt; +        }
&gt; 
&gt; Similarly, webKitWebSrcStart() and webKitWebSrcStop() could just work with
&gt; the assumption (or an actual run-time assertion) that the GstObject lock is
&gt; locked.
&gt; 
&gt; &gt; Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:833
&gt; &gt; +static void webKitWebSrcSeek(WebKitWebSrc* src)
&gt; 
&gt; If all the above is possible, don't forget to set up the lock here.</span ></pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>