Source/WebCore/ChangeLog

 12012-03-22 YoungTaeck Song <youngtaeck.song@samsung.com>
 2
 3 [EFL][WK2] Add RunLoopEfl and WorkQueueEfl
 4 https://bugs.webkit.org/show_bug.cgi?id=62777
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Add initial version RunLoopEfl for WebKit2 Efl.
 9
 10 * platform/RunLoop.h:
 11 (TimerBase):
 12 (RunLoop):
 13 * platform/efl/RunLoopEfl.cpp:
 14 (WebCore::RunLoop::RunLoop):
 15 (WebCore::RunLoop::~RunLoop):
 16 (WebCore):
 17 (WebCore::RunLoop::run):
 18 (WebCore::RunLoop::stop):
 19 (WebCore::RunLoop::wakeUpEvent):
 20 (WebCore::RunLoop::wakeUp):
 21 (WebCore::RunLoop::TimerBase::TimerBase):
 22 (WebCore::RunLoop::TimerBase::~TimerBase):
 23 (WebCore::RunLoop::TimerBase::timerFired):
 24 (WebCore::RunLoop::TimerBase::start):
 25 (WebCore::RunLoop::TimerBase::stop):
 26 (WebCore::RunLoop::TimerBase::isActive):
 27
1282012-03-22 Raphael Kubo da Costa <rakuco@FreeBSD.org>
229
330 [CMake] Unreviewed build fix after r111778.

Source/WebKit2/ChangeLog

 12012-03-22 YoungTaeck Song <youngtaeck.song@samsung.com>
 2
 3 [EFL][WK2] Add RunLoopEfl and WorkQueueEfl
 4 https://bugs.webkit.org/show_bug.cgi?id=62777
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Add initial version WorkQueueEfl for WebKit2 Efl.
 9
 10 * Platform/CoreIPC/Connection.h:
 11 (Connection):
 12 * Platform/CoreIPC/unix/ConnectionUnix.cpp:
 13 (CoreIPC::Connection::open):
 14 (CoreIPC):
 15 * Platform/PlatformProcessIdentifier.h:
 16 (WebKit):
 17 * Platform/WorkQueue.h:
 18 (WorkQueue):
 19 (WorkItemEfl):
 20 (WorkQueue::WorkItemEfl::WorkItemEfl):
 21 (WorkQueue::WorkItemEfl::~WorkItemEfl):
 22 (WorkQueue::WorkItemEfl::execute):
 23 (WorkQueue::WorkItemEfl::queue):
 24 (FdWorkItem):
 25 (WorkQueue::FdWorkItem::FdWorkItem):
 26 (WorkQueue::FdWorkItem::~FdWorkItem):
 27 (WorkQueue::FdWorkItem::fd):
 28 (TimerWorkItem):
 29 (WorkQueue::TimerWorkItem::TimerWorkItem):
 30 (WorkQueue::TimerWorkItem::~TimerWorkItem):
 31 (WorkQueue::TimerWorkItem::timerID):
 32 * Platform/efl/WorkQueueEfl.cpp: Added.
 33 (WorkQueue::platformInitialize):
 34 (WorkQueue::platformInvalidate):
 35 (WorkQueue::performWork):
 36 (WorkQueue::performFdWork):
 37 (WorkQueue::sendMessageToThread):
 38 (WorkQueue::workQueueThread):
 39 (WorkQueue::registerFdEventHandler):
 40 (WorkQueue::scheduleWorkAndWakeUp):
 41 (WorkQueue::dispatch):
 42 (WorkQueue::timerFired):
 43 (WorkQueue::dispatchAfterDelay):
 44 (WorkQueue::exitHandler):
 45 (WorkQueue::dispatchOnTermination):
 46 * PlatformEfl.cmake:
 47 * UIProcess/WebConnectionToWebProcess.cpp:
 48 (WebKit::WebConnectionToWebProcess::WebConnectionToWebProcess):
 49
1502012-03-22 Raphael Kubo da Costa <rakuco@FreeBSD.org>
251
352 [CMake] Unreviewed build fix after r111778.

Source/WebCore/platform/RunLoop.h

3939#include <wtf/gobject/GRefPtr.h>
4040#endif
4141
 42#if PLATFORM(EFL)
 43#include <Ecore.h>
 44#endif
 45
4246namespace WebCore {
4347
4448class RunLoop {

@@public:
9599 void clearTimerSource();
96100 GRefPtr<GSource> m_timerSource;
97101 gboolean m_isRepeating;
 102#elif PLATFORM(EFL)
 103 static bool timerFired(void* data);
 104 OwnPtr<Ecore_Timer> m_timer;
 105 bool m_isRepeating;
98106#endif
99107 };
100108

@@public:
157165private:
158166 GRefPtr<GMainContext> m_runLoopContext;
159167 Vector<GRefPtr<GMainLoop> > m_runLoopMainLoops;
 168#elif PLATFORM(EFL)
 169 bool m_initEfl;
 170 OwnPtr<Ecore_Pipe> m_pipe;
 171 static void wakeUpEvent(void* data, void* buf, unsigned int size);
160172#endif
161173};
162174

Source/WebCore/platform/efl/RunLoopEfl.cpp

11/*
2  * Copyright (C) 2012 ProFUSION embedded systems. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
17  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
 2 Copyright (C) 2012 Samsung Electronics
 3
 4 This library is free software; you can redistribute it and/or
 5 modify it under the terms of the GNU Library General Public
 6 License as published by the Free Software Foundation; either
 7 version 2 of the License, or (at your option) any later version.
 8
 9 This library is distributed in the hope that it will be useful,
 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 12 Library General Public License for more details.
 13
 14 You should have received a copy of the GNU Library General Public License
 15 along with this library; see the file COPYING.LIB. If not, write to
 16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 17 Boston, MA 02110-1301, USA.
 18*/
2519
2620#include "config.h"
2721#include "RunLoop.h"
2822
29 #include "NotImplemented.h"
 23#include <Ecore.h>
 24#include <Ecore_Evas.h>
 25#include <Ecore_File.h>
 26#include <Edje.h>
 27#include <wtf/OwnPtr.h>
 28#include <wtf/PassOwnPtr.h>
 29
 30static const int ecorePipeMessageSize = 1;
 31static const char* const wakupEcorePipeMessage = "W";
3032
3133namespace WebCore {
3234
3335RunLoop::RunLoop()
3436{
35  notImplemented();
 37 m_initEfl = false;
 38
 39 if (!ecore_init()) {
 40 LOG_ERROR("could not init ecore.");
 41 goto errorEcore;
 42 }
 43
 44 if (!ecore_evas_init()) {
 45 LOG_ERROR("could not init ecore_evas.");
 46 goto errorEcoreEvas;
 47 }
 48
 49 if (!ecore_file_init()) {
 50 LOG_ERROR("could not init ecore_file.");
 51 goto errorEcoreFile;
 52 }
 53
 54 if (!edje_init()) {
 55 LOG_ERROR("could not init edje.");
 56 goto errorEdje;
 57 }
 58
 59 m_pipe = adoptPtr(ecore_pipe_add(wakeUpEvent, this));
 60 m_initEfl = true;
 61
 62 return;
 63
 64errorEdje:
 65 ecore_file_shutdown();
 66errorEcoreFile:
 67 ecore_evas_shutdown();
 68errorEcoreEvas:
 69 ecore_shutdown();
 70errorEcore:
 71 return;
3672}
3773
3874RunLoop::~RunLoop()
3975{
40  notImplemented();
 76 if (m_initEfl) {
 77 edje_shutdown();
 78 ecore_file_shutdown();
 79 ecore_evas_shutdown();
 80 ecore_shutdown();
 81 }
 82}
 83
 84void RunLoop::run()
 85{
 86 ecore_main_loop_begin();
 87}
 88
 89void RunLoop::stop()
 90{
 91 ecore_main_loop_quit();
 92}
 93
 94void RunLoop::wakeUpEvent(void* data, void* buf, unsigned int size)
 95{
 96 static_cast<RunLoop*>(data)->performWork();
4197}
4298
4399void RunLoop::wakeUp()
44100{
45  notImplemented();
 101 ecore_pipe_write(m_pipe.get(), wakupEcorePipeMessage, ecorePipeMessageSize);
 102}
 103
 104RunLoop::TimerBase::TimerBase(RunLoop* runLoop)
 105 : m_isRepeating(false)
 106{
 107}
 108
 109RunLoop::TimerBase::~TimerBase()
 110{
 111 stop();
 112}
 113
 114bool RunLoop::TimerBase::timerFired(void* data)
 115{
 116 RunLoop::TimerBase* timer = static_cast<RunLoop::TimerBase*>(data);
 117
 118 timer->fired();
 119
 120 if (!timer->m_isRepeating) {
 121 timer->m_timer = nullptr;
 122 return ECORE_CALLBACK_CANCEL;
 123 }
 124
 125 return ECORE_CALLBACK_RENEW;
 126}
 127
 128void RunLoop::TimerBase::start(double fireInterval, bool repeat)
 129{
 130 m_isRepeating = repeat;
 131 m_timer = adoptPtr(ecore_timer_add(fireInterval, reinterpret_cast<Ecore_Task_Cb>(timerFired), this));
 132}
 133
 134void RunLoop::TimerBase::stop()
 135{
 136 m_timer = nullptr;
 137}
 138
 139bool RunLoop::TimerBase::isActive() const
 140{
 141 return (m_timer) ? true : false;
46142}
47143
48144} // namespace WebCore

Source/WebKit2/Platform/CoreIPC/Connection.h

4646class QSocketNotifier;
4747#endif
4848
49 #if PLATFORM(QT) || PLATFORM(GTK)
 49#if PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
5050#include "PlatformProcessIdentifier.h"
5151#endif
5252

Source/WebKit2/Platform/CoreIPC/unix/ConnectionUnix.cpp

@@void Connection::platformInvalidate()
153153 m_socketNotifier = 0;
154154#endif
155155
 156#if PLATFORM(EFL)
 157 m_connectionQueue.unregisterSocketEventHandler(m_socketDescriptor);
 158#endif
 159
156160 m_socketDescriptor = -1;
157161 m_isConnected = false;
158162}

@@bool Connection::open()
423427#elif PLATFORM(GTK)
424428 m_connectionQueue.registerEventSourceHandler(m_socketDescriptor, (G_IO_HUP | G_IO_ERR), bind(&Connection::connectionDidClose, this));
425429 m_connectionQueue.registerEventSourceHandler(m_socketDescriptor, G_IO_IN, bind(&Connection::readyReadHandler, this));
 430#elif PLATFORM(EFL)
 431 m_connectionQueue.registerSocketEventHandler(m_socketDescriptor, bind(&Connection::readyReadHandler, this));
426432#endif
427433
428434 // Schedule a call to readyReadHandler. Data may have arrived before installation of the signal

Source/WebKit2/Platform/PlatformProcessIdentifier.h

@@typedef void* GPid;
4646typedef int GPid;
4747#endif
4848typedef GPid PlatformProcessIdentifier;
 49#elif PLATFORM(EFL)
 50typedef pid_t PlatformProcessIdentifier;
4951#endif
5052
5153} // namespace WebKit

Source/WebKit2/Platform/WorkQueue.h

4141#include <wtf/Threading.h>
4242#include <wtf/Vector.h>
4343
 44#if (PLATFORM(QT) && !OS(DARWIN)) || PLATFORM(GTK) || PLATFORM(EFL)
 45#include "PlatformProcessIdentifier.h"
 46#endif
 47
4448#if PLATFORM(QT) && !OS(DARWIN)
4549#include <QSocketNotifier>
46 #include "PlatformProcessIdentifier.h"
4750class QObject;
4851class QThread;
4952#elif PLATFORM(GTK)
50 #include "PlatformProcessIdentifier.h"
5153#include <wtf/gobject/GRefPtr.h>
5254typedef gboolean (*GSourceFunc) (gpointer data);
 55#elif PLATFORM(EFL)
 56#include <Ecore.h>
5357#endif
5458
5559class WorkQueue {

@@public:
9094 void registerEventSourceHandler(int, int, const Function<void()>&);
9195 void unregisterEventSourceHandler(int);
9296 void dispatchOnTermination(WebKit::PlatformProcessIdentifier, const Function<void()>&);
 97#elif PLATFORM(EFL)
 98 void registerSocketEventHandler(int, const Function<void()>&);
 99 void unregisterSocketEventHandler(int);
 100 void dispatchOnTermination(WebKit::PlatformProcessIdentifier, const Function<void()>&);
93101#endif
94102
95103private:

@@private:
177185 class EventSource;
178186 HashMap<int, Vector<EventSource*> > m_eventSources;
179187 typedef HashMap<int, Vector<EventSource*> >::iterator EventSourceIterator;
 188#elif PLATFORM(EFL)
 189 class TimerWorkItem;
 190
 191 fd_set m_fdSet;
 192 int m_maxFd;
 193 int m_readFromPipeFd;
 194 int m_writeToPipeFd;
 195 bool m_threadLoop;
 196
 197 Vector<Function<void()> > m_workItemQueue;
 198 Mutex m_workItemQueueLock;
 199
 200 int m_socketDescriptor;
 201 Function<void()> m_socketEventHandler;
 202
 203 HashMap<int, OwnPtr<Ecore_Timer> > m_timers;
 204
 205 Ecore_Event_Handler* m_processExitHandler;
 206 HashMap<WebKit::PlatformProcessIdentifier, Function<void()> > m_termWorkItems;
 207
 208 void sendMessageToThread(const char*);
 209 static void* workQueueThread(WorkQueue*);
 210 void scheduleWorkAndWakeUp(const Function<void()>&);
 211 void performWork();
 212 void performFdWork();
 213 static bool timerFired(void*);
 214 static bool processExitCallBack(void*, int, void*);
180215#endif
181216};
182217

Source/WebKit2/Platform/efl/WorkQueueEfl.cpp

 1/*
 2 Copyright (C) 2012 Samsung Electronics
 3
 4 This library is free software; you can redistribute it and/or
 5 modify it under the terms of the GNU Library General Public
 6 License as published by the Free Software Foundation; either
 7 version 2 of the License, or (at your option) any later version.
 8
 9 This library is distributed in the hope that it will be useful,
 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 12 Library General Public License for more details.
 13
 14 You should have received a copy of the GNU Library General Public License
 15 along with this library; see the file COPYING.LIB. If not, write to
 16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 17 Boston, MA 02110-1301, USA.
 18 */
 19
 20#include "config.h"
 21#include "WorkQueue.h"
 22
 23#include <wtf/Assertions.h>
 24
 25class WorkQueue::TimerWorkItem {
 26public:
 27 TimerWorkItem(int timerID, const Function<void()>& function, WorkQueue* queue)
 28 : m_function(function)
 29 , m_queue(queue)
 30 , m_timerID(timerID)
 31 {
 32 }
 33 ~TimerWorkItem() { }
 34
 35 Function<void()> function() const { return m_function; }
 36 WorkQueue* queue() const { return m_queue; }
 37
 38 int timerID() const { return m_timerID; }
 39
 40private:
 41 Function<void()> m_function;
 42 WorkQueue* m_queue;
 43 int m_timerID;
 44};
 45
 46static const int invalidSocketDescriptor = -1;
 47static const int threadMessageSize = 1;
 48static const char* const finishThreadMessage = "F";
 49static const char* const wakupThreadMessage = "W";
 50
 51// WorkQueue
 52void WorkQueue::platformInitialize(const char* name)
 53{
 54 int fds[2];
 55 if (pipe(fds))
 56 ASSERT_NOT_REACHED();
 57 m_readFromPipeFd = fds[0];
 58 m_writeToPipeFd = fds[1];
 59 FD_ZERO(&m_fdSet);
 60 FD_SET(m_readFromPipeFd, &m_fdSet);
 61 m_maxFd = m_readFromPipeFd;
 62
 63 m_socketDescriptor = invalidSocketDescriptor;
 64
 65 m_processExitHandler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, reinterpret_cast<Ecore_Event_Handler_Cb>(processExitCallBack), this);
 66
 67 m_threadLoop = true;
 68 createThread(reinterpret_cast<WTF::ThreadFunction>(&WorkQueue::workQueueThread), this, name);
 69}
 70
 71void WorkQueue::platformInvalidate()
 72{
 73 if (m_processExitHandler)
 74 ecore_event_handler_del(m_processExitHandler);
 75 m_processExitHandler = 0;
 76
 77 sendMessageToThread(finishThreadMessage);
 78}
 79
 80void WorkQueue::performWork()
 81{
 82 m_workItemQueueLock.lock();
 83
 84 while (!m_workItemQueue.isEmpty()) {
 85 Vector<Function<void()> > workItemQueue;
 86 m_workItemQueue.swap(workItemQueue);
 87
 88 m_workItemQueueLock.unlock();
 89 for (size_t i = 0; i < workItemQueue.size(); ++i)
 90 workItemQueue[i]();
 91 m_workItemQueueLock.lock();
 92 }
 93 m_workItemQueueLock.unlock();
 94}
 95
 96void WorkQueue::performFdWork()
 97{
 98 fd_set readFdSet = m_fdSet;
 99
 100 if (select(m_maxFd + 1, &readFdSet, 0, 0, 0) >= 0) {
 101 if (FD_ISSET(m_readFromPipeFd, &readFdSet)) {
 102 char readBuf[threadMessageSize];
 103 if (read(m_readFromPipeFd, readBuf, threadMessageSize) == -1)
 104 LOG_ERROR("Failed to read from WorkQueueThread pipe");
 105 if (!strncmp(readBuf, finishThreadMessage, threadMessageSize))
 106 m_threadLoop = false;
 107 }
 108
 109 if (m_socketDescriptor != invalidSocketDescriptor && FD_ISSET(m_socketDescriptor, &readFdSet))
 110 m_socketEventHandler();
 111 }
 112}
 113
 114void WorkQueue::sendMessageToThread(const char* message)
 115{
 116 if (write(m_writeToPipeFd, message, threadMessageSize) == -1)
 117 LOG_ERROR("Failed to wake up WorkQueue Thread");
 118}
 119
 120void* WorkQueue::workQueueThread(WorkQueue* workQueue)
 121{
 122 while (workQueue->m_threadLoop) {
 123 workQueue->performWork();
 124 workQueue->performFdWork();
 125 }
 126
 127 close(workQueue->m_readFromPipeFd);
 128 close(workQueue->m_writeToPipeFd);
 129
 130 return 0;
 131}
 132
 133void WorkQueue::registerSocketEventHandler(int fd, const Function<void()>& function)
 134{
 135 if (m_socketDescriptor != invalidSocketDescriptor)
 136 LOG_ERROR("%d is already registerd.", fd);
 137
 138 m_socketDescriptor = fd;
 139 m_socketEventHandler = function;
 140
 141 if (fd > m_maxFd)
 142 m_maxFd = fd;
 143 FD_SET(fd, &m_fdSet);
 144}
 145
 146void WorkQueue::unregisterSocketEventHandler(int fd)
 147{
 148 m_socketDescriptor = invalidSocketDescriptor;
 149
 150 if (fd == m_maxFd)
 151 m_maxFd = m_readFromPipeFd;
 152 FD_CLR(fd, &m_fdSet);
 153}
 154
 155void WorkQueue::scheduleWorkAndWakeUp(const Function<void()>& function)
 156{
 157 if (function.isNull())
 158 return;
 159
 160 MutexLocker locker(m_workItemQueueLock);
 161 m_workItemQueue.append(function);
 162 sendMessageToThread(wakupThreadMessage);
 163}
 164
 165void WorkQueue::dispatch(const Function<void()>& function)
 166{
 167 scheduleWorkAndWakeUp(function);
 168}
 169
 170bool WorkQueue::timerFired(void* data)
 171{
 172 TimerWorkItem* item = static_cast<TimerWorkItem*>(data);
 173 if (item && item->queue()->m_isValid) {
 174 item->queue()->scheduleWorkAndWakeUp(item->function());
 175 item->queue()->m_timers.take(item->timerID());
 176 delete item;
 177 }
 178
 179 return ECORE_CALLBACK_CANCEL;
 180}
 181
 182void WorkQueue::dispatchAfterDelay(const Function<void()>& function, double delay)
 183{
 184 static int timerId = 0;
 185 m_timers.set(timerId, adoptPtr(ecore_timer_add(delay, reinterpret_cast<Ecore_Task_Cb>(timerFired), new TimerWorkItem(timerId, function, this))));
 186 timerId++;
 187}
 188
 189bool WorkQueue::processExitCallBack(void* data, int type, void* event)
 190{
 191 WorkQueue* queue = reinterpret_cast<WorkQueue*>(data);
 192 if (queue->m_isValid) {
 193 Ecore_Exe_Event_Del* ev = static_cast<Ecore_Exe_Event_Del*>(event);
 194 WebKit::PlatformProcessIdentifier deadChildPid = static_cast<WebKit::PlatformProcessIdentifier>(ev->pid);
 195
 196 if (queue->m_termWorkItems.contains(deadChildPid)) {
 197 Function<void()> function = queue->m_termWorkItems.take(deadChildPid);
 198 queue->scheduleWorkAndWakeUp(function);
 199 }
 200 }
 201 return ECORE_CALLBACK_RENEW;
 202}
 203
 204void WorkQueue::dispatchOnTermination(WebKit::PlatformProcessIdentifier childPid, const Function<void()>& function)
 205{
 206 ASSERT_ARG(childPid, !m_termWorkItems.contains(childPid));
 207 m_termWorkItems.set(childPid, function);
 208}

Source/WebKit2/PlatformEfl.cmake

@@LIST(APPEND WebKit2_LINK_FLAGS
77
88LIST(APPEND WebKit2_SOURCES
99 Platform/efl/ModuleEfl.cpp
10  Platform/efl/RunLoopEfl.cpp
1110 Platform/efl/WorkQueueEfl.cpp
1211 Platform/unix/SharedMemoryUnix.cpp
1312