[Webkit-unassigned] [Bug 130027] [GLIB] Add GMainLoopSource class to wrap idle and timeout sources

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Mar 11 05:08:53 PDT 2014


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





--- Comment #18 from Zan Dobersek <zandobersek at gmail.com>  2014-03-11 05:05:44 PST ---
(From update of attachment 226403)
View in context: https://bugs.webkit.org/attachment.cgi?id=226403&action=review

> Source/WTF/wtf/gobject/GMainLoopSource.h:56
> +    void scheduleAfterDelay(const char* name, std::function<void ()>, std::chrono::milliseconds, int priority = G_PRIORITY_DEFAULT, std::function<void ()> destroyFunction = nullptr, GMainContext* = nullptr);
> +    void scheduleAfterDelay(const char* name, std::function<bool ()>, std::chrono::milliseconds, int priority = G_PRIORITY_DEFAULT, std::function<void ()> destroyFunction = nullptr, GMainContext* = nullptr);
> +    void scheduleAfterDelay(const char* name, std::function<void ()>, std::chrono::seconds, int priority = G_PRIORITY_DEFAULT, std::function<void ()> destroyFunction = nullptr, GMainContext* = nullptr);
> +    void scheduleAfterDelay(const char* name, std::function<bool ()>, std::chrono::seconds, int priority = G_PRIORITY_DEFAULT, std::function<void ()> destroyFunction = nullptr, GMainContext* = nullptr);

Can we simplify these into just two separate functions, differing in the type of the callback but both taking in std::chrono::milliseconds?

std::chrono::duration object should use the implicit constructor to convert between durations, so you could call sheduleAfterDelay() with std::chrono::seconds which would then get converted into milliseconds.

> Source/WTF/wtf/gtk/RunLoopGtk.cpp:102
> +    GMainLoopSource::create().schedule("[WebKit] RunLoop work", std::bind(&RunLoop::performWork, this));

Consider using a C++11 lambda, but remember to protect the RunLoop object through the reference counting mechanism:

    ref();
    GMainLoopSource::create().schedule(..., [this] {
        performWork();
        deref();
    });

> Source/WTF/wtf/gtk/RunLoopGtk.cpp:118
> +    m_timerSource.scheduleAfterDelay("[WebKit] RunLoop::Timer", static_cast<std::function<bool ()>>([this, repeat]() { fired(); return repeat; }),

Consider simply using the std::function<bool ()> constructor instead of the static_cast to that type.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list