<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@falconsigh.net" title="Zan Dobersek <zan@falconsigh.net>"> <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">> (In reply to <a href="show_bug.cgi?id=150888#c3">comment #3</a>)
> > > Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:615
> > > + if (isMainThread())
> > > + player->notifyPlayerOfVideo();
> > > + else
> > > + player->m_notifier.notify(MainThreadNotification::VideoChanged, [player] { player->notifyPlayerOfVideo(); });
> >
> > This isMainThread() check and the conditional immediate execution could be
> > rolled up into the notifier class. Would save some lines.
> >
> > MainThreadNotifier::notify() would accept a templated functor as the second
> > parameter, invoke it immediately if on the main thread, or wrap it in
> > std::function<> and dispatch it onto the main thread via RunLoop otherwise.
>
> I thought about that, but decided to do it in callers to avoid the function
> creation just to invoke a member method. But I'm not sure if creating the
> function would have any real impact in the end, what do you think?</span >
You wouldn't create a std::function<> object until you know you're not on the main thread and have to use the RunLoop dispatch instead.
template<typename F>
void notify(T notificationType, const F& callbackFunctor)
{
if (!addPendingNotitifation(notificationType))
return;
if (!isMainThread()) {
auto weakThis = m_weakPtrFactory.createWeakPtr();
std::function<void ()> callback(callbackFunctor);
RunLoop::main().dispatch([weakThis, notificationType, callback] {
if (weakThis && weakThis->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>