<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [GStreamer] Do not use GThreadSafeMainLoopSource to send notifications to the main thread in MediaPlayerPrivateGStreamer"
   href="https://bugs.webkit.org/show_bug.cgi?id=150888#c5">Comment # 5</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [GStreamer] Do not use GThreadSafeMainLoopSource to send notifications to the main thread in MediaPlayerPrivateGStreamer"
   href="https://bugs.webkit.org/show_bug.cgi?id=150888">bug 150888</a>
              from <span class="vcard"><a class="email" href="mailto:zan&#64;falconsigh.net" title="Zan Dobersek &lt;zan&#64;falconsigh.net&gt;"> <span class="fn">Zan Dobersek</span></a>
</span></b>
        <pre>(In reply to <a href="show_bug.cgi?id=150888#c4">comment #4</a>)
<span class="quote">&gt; (In reply to <a href="show_bug.cgi?id=150888#c3">comment #3</a>)
&gt; &gt; &gt; Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:615
&gt; &gt; &gt; +    if (isMainThread())
&gt; &gt; &gt; +        player-&gt;notifyPlayerOfVideo();
&gt; &gt; &gt; +    else
&gt; &gt; &gt; +        player-&gt;m_notifier.notify(MainThreadNotification::VideoChanged, [player] { player-&gt;notifyPlayerOfVideo(); });
&gt; &gt; 
&gt; &gt; This isMainThread() check and the conditional immediate execution could be
&gt; &gt; rolled up into the notifier class. Would save some lines.
&gt; &gt; 
&gt; &gt; MainThreadNotifier::notify() would accept a templated functor as the second
&gt; &gt; parameter, invoke it immediately if on the main thread, or wrap it in
&gt; &gt; std::function&lt;&gt; and dispatch it onto the main thread via RunLoop otherwise.
&gt; 
&gt; I thought about that, but decided to do it in callers to avoid the function
&gt; creation just to invoke a member method. But I'm not sure if creating the
&gt; function would have any real impact in the end, what do you think?</span >

You wouldn't create a std::function&lt;&gt; object until you know you're not on the main thread and have to use the RunLoop dispatch instead.

    template&lt;typename F&gt;
    void notify(T notificationType, const F&amp; callbackFunctor)
    {
        if (!addPendingNotitifation(notificationType))
            return;

        if (!isMainThread()) {
            auto weakThis = m_weakPtrFactory.createWeakPtr();
            std::function&lt;void ()&gt; callback(callbackFunctor);
            RunLoop::main().dispatch([weakThis, notificationType, callback] {
                if (weakThis &amp;&amp; weakThis-&gt;removePendingNotitifation(notificationType))
                    callback();
            });
        } else
            callbackFunctor();
    }</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>