Commit 530f751a authored by zandobersek@gmail.com's avatar zandobersek@gmail.com

[GTK][WK2] Move the rest of GTK's WorkQueue implementation to std::function

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

Reviewed by Anders Carlsson.

Move to using std::function and move semantics in WorkQueue::registerSocketEventHandler
and WorkQueue::SocketEventSource.

* Platform/IPC/unix/ConnectionUnix.cpp:
(IPC::Connection::open):
* Platform/WorkQueue.h:
* Platform/gtk/WorkQueueGtk.cpp:
(WorkQueue::SocketEventSource::SocketEventSource):
(WorkQueue::registerSocketEventHandler):
(WorkQueue::dispatchOnSource): Use std::move instead of std::forward<T>.
(WorkQueue::dispatch): Ditto.
(WorkQueue::dispatchAfter): Ditto.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@162370 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 585b903f
2014-01-20 Zan Dobersek <zdobersek@igalia.com>
[GTK][WK2] Move the rest of GTK's WorkQueue implementation to std::function
https://bugs.webkit.org/show_bug.cgi?id=127273
Reviewed by Anders Carlsson.
Move to using std::function and move semantics in WorkQueue::registerSocketEventHandler
and WorkQueue::SocketEventSource.
* Platform/IPC/unix/ConnectionUnix.cpp:
(IPC::Connection::open):
* Platform/WorkQueue.h:
* Platform/gtk/WorkQueueGtk.cpp:
(WorkQueue::SocketEventSource::SocketEventSource):
(WorkQueue::registerSocketEventHandler):
(WorkQueue::dispatchOnSource): Use std::move instead of std::forward<T>.
(WorkQueue::dispatch): Ditto.
(WorkQueue::dispatchAfter): Ditto.
2014-01-20 Zan Dobersek <zdobersek@igalia.com>
Unreviewed. Additional build fixes after r162276 and r163304.
......
......@@ -388,7 +388,14 @@ bool Connection::open()
m_isConnected = true;
#if PLATFORM(GTK)
m_connectionQueue->registerSocketEventHandler(m_socketDescriptor, WTF::bind(&Connection::readyReadHandler, this), WTF::bind(&Connection::connectionDidClose, this));
RefPtr<Connection> protector(this);
m_connectionQueue->registerSocketEventHandler(m_socketDescriptor,
[=] {
protector->readyReadHandler();
},
[=] {
protector->connectionDidClose();
});
#elif PLATFORM(EFL)
m_connectionQueue->registerSocketEventHandler(m_socketDescriptor, WTF::bind(&Connection::readyReadHandler, this));
#endif
......
......@@ -63,7 +63,7 @@ public:
#if OS(DARWIN)
dispatch_queue_t dispatchQueue() const { return m_dispatchQueue; }
#elif PLATFORM(GTK)
void registerSocketEventHandler(int, const Function<void()>&, const Function<void()>&);
void registerSocketEventHandler(int, std::function<void ()>, std::function<void ()>);
void unregisterSocketEventHandler(int);
#elif PLATFORM(EFL)
void registerSocketEventHandler(int, const Function<void()>&);
......
......@@ -69,10 +69,10 @@ private:
class WorkQueue::SocketEventSource : public WorkQueue::EventSource {
public:
SocketEventSource(const Function<void()>& function, WorkQueue* workQueue, GCancellable* cancellable, const Function<void()>& closeFunction)
: EventSource(function, workQueue)
SocketEventSource(std::function<void ()> function, WorkQueue* workQueue, GCancellable* cancellable, std::function<void ()> closeFunction)
: EventSource(std::move(function), workQueue)
, m_cancellable(cancellable)
, m_closeFunction(closeFunction)
, m_closeFunction(std::move(closeFunction))
{
ASSERT(cancellable);
}
......@@ -107,7 +107,7 @@ public:
private:
GCancellable* m_cancellable;
Function<void()> m_closeFunction;
std::function<void ()> m_closeFunction;
};
// WorkQueue
......@@ -159,14 +159,15 @@ void WorkQueue::workQueueThreadBody()
g_main_loop_run(m_eventLoop.get());
}
void WorkQueue::registerSocketEventHandler(int fileDescriptor, const Function<void()>& function, const Function<void()>& closeFunction)
void WorkQueue::registerSocketEventHandler(int fileDescriptor, std::function<void ()> function, std::function<void ()> closeFunction)
{
GRefPtr<GSocket> socket = adoptGRef(g_socket_new_from_fd(fileDescriptor, 0));
ASSERT(socket);
GRefPtr<GCancellable> cancellable = adoptGRef(g_cancellable_new());
GRefPtr<GSource> dispatchSource = adoptGRef(g_socket_create_source(socket.get(), G_IO_IN, cancellable.get()));
ASSERT(dispatchSource);
SocketEventSource* eventSource = new SocketEventSource(function, this, cancellable.get(), closeFunction);
SocketEventSource* eventSource = new SocketEventSource(std::move(function), this,
cancellable.get(), std::move(closeFunction));
g_source_set_callback(dispatchSource.get(), reinterpret_cast<GSourceFunc>(&WorkQueue::SocketEventSource::eventCallback),
eventSource, reinterpret_cast<GDestroyNotify>(&WorkQueue::EventSource::deleteEventSource));
......@@ -206,7 +207,7 @@ void WorkQueue::unregisterSocketEventHandler(int fileDescriptor)
void WorkQueue::dispatchOnSource(GSource* dispatchSource, std::function<void ()> function, GSourceFunc sourceCallback)
{
g_source_set_callback(dispatchSource, sourceCallback, new EventSource(std::forward<std::function<void ()>>(function), this),
g_source_set_callback(dispatchSource, sourceCallback, new EventSource(std::move(function), this),
reinterpret_cast<GDestroyNotify>(&WorkQueue::EventSource::deleteEventSource));
g_source_attach(dispatchSource, m_eventContext.get());
......@@ -216,7 +217,7 @@ void WorkQueue::dispatch(std::function<void ()> function)
{
GRefPtr<GSource> dispatchSource = adoptGRef(g_idle_source_new());
g_source_set_priority(dispatchSource.get(), G_PRIORITY_DEFAULT);
dispatchOnSource(dispatchSource.get(), std::forward<std::function<void ()>>(function),
dispatchOnSource(dispatchSource.get(), std::move(function),
reinterpret_cast<GSourceFunc>(&WorkQueue::EventSource::performWorkOnce));
}
......@@ -224,6 +225,6 @@ void WorkQueue::dispatchAfter(std::chrono::nanoseconds duration, std::function<v
{
GRefPtr<GSource> dispatchSource = adoptGRef(g_timeout_source_new(
static_cast<guint>(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count())));
dispatchOnSource(dispatchSource.get(), std::forward<std::function<void ()>>(function),
dispatchOnSource(dispatchSource.get(), std::move(function),
reinterpret_cast<GSourceFunc>(&WorkQueue::EventSource::performWorkOnce));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment