Changeset 199694 in webkit


Ignore:
Timestamp:
Apr 18, 2016 3:59:31 PM (8 years ago)
Author:
Yusuke Suzuki
Message:

[JSCOnly] Implement RunLoop and remove glib dependency
https://bugs.webkit.org/show_bug.cgi?id=155706

Reviewed by Michael Catanzaro.

.:

  • Source/cmake/OptionsJSCOnly.cmake:

Source/WTF:

Add missing RunLoop and WorkQueue platform code for JSCOnly port.
The implementation does not use platform specific things. Instead, we
implement them on WTF framework; using condition variables to construct
the run loop and timers.

Since the fallback is implemented, it is not necessary for JSCOnly port
to depend on GLib's RunLoop abstraction. So this patch removes its
dependency. As a result, now, JSCOnly port removes dependencies except for the system ICU.

We clean up event loop ifdefs by introducing USE_XXX_EVENT_LOOP flags.
USE(XXX_EVENT_LOOP) is exclusive to each other. So from now, we do not need to take care
of the order of if-defs for the event loops. (For example, USE(GLIB) should have lead before
OS(DARWIN) in WorkQueue.h for WebKitGTK on Darwin.)

EVENT_LOOP determination is done in Platform.h. This follows the style of WTF PLATFORM.

  • wtf/Platform.h:
  • wtf/PlatformJSCOnly.cmake:
  • wtf/RunLoop.h:
  • wtf/WorkQueue.h:
  • wtf/generic/MainThreadGeneric.cpp: Renamed from Source/WTF/wtf/none/MainThreadNone.cpp.

(WTF::initializeMainThreadPlatform):
(WTF::scheduleDispatchFunctionsOnMainThread):

  • wtf/generic/RunLoopGeneric.cpp: Added.

(WTF::RunLoop::TimerBase::ScheduledTask::create):
(WTF::RunLoop::TimerBase::ScheduledTask::ScheduledTask):
(WTF::RunLoop::TimerBase::ScheduledTask::fired):
(WTF::RunLoop::TimerBase::ScheduledTask::scheduledTimePoint):
(WTF::RunLoop::TimerBase::ScheduledTask::updateReadyTime):
(WTF::RunLoop::TimerBase::ScheduledTask::EarliestSchedule::operator()):
(WTF::RunLoop::TimerBase::ScheduledTask::isActive):
(WTF::RunLoop::TimerBase::ScheduledTask::deactivate):
(WTF::RunLoop::RunLoop):
(WTF::RunLoop::~RunLoop):
(WTF::RunLoop::populateTasks):
(WTF::RunLoop::runImpl):
(WTF::RunLoop::run):
(WTF::RunLoop::iterate):
(WTF::RunLoop::stop):
(WTF::RunLoop::wakeUp):
(WTF::RunLoop::schedule):
(WTF::RunLoop::scheduleAndWakeUp):
(WTF::RunLoop::dispatchAfter):
(WTF::RunLoop::TimerBase::TimerBase):
(WTF::RunLoop::TimerBase::~TimerBase):
(WTF::RunLoop::TimerBase::start):
(WTF::RunLoop::TimerBase::stop):
(WTF::RunLoop::TimerBase::isActive):

  • wtf/generic/WorkQueueGeneric.cpp: Added.

(WorkQueue::platformInitialize):
(WorkQueue::platformInvalidate):
(WorkQueue::dispatch):
(WorkQueue::dispatchAfter):

  • wtf/none/MainThreadNone.cpp:

(WTF::initializeMainThreadPlatform): Deleted.
(WTF::scheduleDispatchFunctionsOnMainThread): Deleted.

  • wtf/none/RunLoopNone.cpp:

(WTF::RunLoop::RunLoop): Deleted.
(WTF::RunLoop::~RunLoop): Deleted.
(WTF::RunLoop::run): Deleted.
(WTF::RunLoop::stop): Deleted.
(WTF::RunLoop::wakeUp): Deleted.
(WTF::RunLoop::TimerBase::TimerBase): Deleted.
(WTF::RunLoop::TimerBase::~TimerBase): Deleted.
(WTF::RunLoop::TimerBase::start): Deleted.
(WTF::RunLoop::TimerBase::stop): Deleted.
(WTF::RunLoop::TimerBase::isActive): Deleted.

  • wtf/none/WorkQueueNone.cpp:

(WorkQueue::platformInitialize): Deleted.
(WorkQueue::platformInvalidate): Deleted.
(WorkQueue::dispatch): Deleted.
(WorkQueue::dispatchAfter): Deleted.

Tools:

Add TestWTF to JSCOnly port to test WorkQueue and RunLoop.
Platform specific ones locate under jsconly directory since
it is not generic (Since it includes the GLIB event loop case).

  • CMakeLists.txt:
  • TestWebKitAPI/PlatformJSCOnly.cmake: Added.
  • TestWebKitAPI/PlatformUtilities.h:
  • TestWebKitAPI/Tests/WTF/RunLoop.cpp:

(TestWebKitAPI::TEST):

  • TestWebKitAPI/config.h:
  • TestWebKitAPI/jsconly/PlatformUtilitiesJSCOnly.cpp: Renamed from Source/WTF/wtf/none/RunLoopNone.cpp.

(TestWebKitAPI::Util::run):
(TestWebKitAPI::Util::sleep):

  • TestWebKitAPI/jsconly/main.cpp: Renamed from Source/WTF/wtf/none/WorkQueueNone.cpp.

(main):

Location:
trunk
Files:
5 added
1 deleted
12 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r199659 r199694  
     12016-04-18  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSCOnly] Implement RunLoop and remove glib dependency
     4        https://bugs.webkit.org/show_bug.cgi?id=155706
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        * Source/cmake/OptionsJSCOnly.cmake:
     9
    1102016-04-18  Carlos Garcia Campos  <cgarcia@igalia.com>
    211
  • trunk/Source/WTF/ChangeLog

    r199679 r199694  
     12016-04-18  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSCOnly] Implement RunLoop and remove glib dependency
     4        https://bugs.webkit.org/show_bug.cgi?id=155706
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Add missing RunLoop and WorkQueue platform code for JSCOnly port.
     9        The implementation does not use platform specific things. Instead, we
     10        implement them on WTF framework; using condition variables to construct
     11        the run loop and timers.
     12
     13        Since the fallback is implemented, it is not necessary for JSCOnly port
     14        to depend on GLib's RunLoop abstraction. So this patch removes its
     15        dependency. As a result, now, JSCOnly port removes dependencies except for the system ICU.
     16
     17        We clean up event loop ifdefs by introducing USE_XXX_EVENT_LOOP flags.
     18        USE(XXX_EVENT_LOOP) is exclusive to each other. So from now, we do not need to take care
     19        of the order of if-defs for the event loops. (For example, USE(GLIB) should have lead before
     20        OS(DARWIN) in WorkQueue.h for WebKitGTK on Darwin.)
     21
     22        EVENT_LOOP determination is done in Platform.h. This follows the style of WTF PLATFORM.
     23
     24        * wtf/Platform.h:
     25        * wtf/PlatformJSCOnly.cmake:
     26        * wtf/RunLoop.h:
     27        * wtf/WorkQueue.h:
     28        * wtf/generic/MainThreadGeneric.cpp: Renamed from Source/WTF/wtf/none/MainThreadNone.cpp.
     29        (WTF::initializeMainThreadPlatform):
     30        (WTF::scheduleDispatchFunctionsOnMainThread):
     31        * wtf/generic/RunLoopGeneric.cpp: Added.
     32        (WTF::RunLoop::TimerBase::ScheduledTask::create):
     33        (WTF::RunLoop::TimerBase::ScheduledTask::ScheduledTask):
     34        (WTF::RunLoop::TimerBase::ScheduledTask::fired):
     35        (WTF::RunLoop::TimerBase::ScheduledTask::scheduledTimePoint):
     36        (WTF::RunLoop::TimerBase::ScheduledTask::updateReadyTime):
     37        (WTF::RunLoop::TimerBase::ScheduledTask::EarliestSchedule::operator()):
     38        (WTF::RunLoop::TimerBase::ScheduledTask::isActive):
     39        (WTF::RunLoop::TimerBase::ScheduledTask::deactivate):
     40        (WTF::RunLoop::RunLoop):
     41        (WTF::RunLoop::~RunLoop):
     42        (WTF::RunLoop::populateTasks):
     43        (WTF::RunLoop::runImpl):
     44        (WTF::RunLoop::run):
     45        (WTF::RunLoop::iterate):
     46        (WTF::RunLoop::stop):
     47        (WTF::RunLoop::wakeUp):
     48        (WTF::RunLoop::schedule):
     49        (WTF::RunLoop::scheduleAndWakeUp):
     50        (WTF::RunLoop::dispatchAfter):
     51        (WTF::RunLoop::TimerBase::TimerBase):
     52        (WTF::RunLoop::TimerBase::~TimerBase):
     53        (WTF::RunLoop::TimerBase::start):
     54        (WTF::RunLoop::TimerBase::stop):
     55        (WTF::RunLoop::TimerBase::isActive):
     56        * wtf/generic/WorkQueueGeneric.cpp: Added.
     57        (WorkQueue::platformInitialize):
     58        (WorkQueue::platformInvalidate):
     59        (WorkQueue::dispatch):
     60        (WorkQueue::dispatchAfter):
     61        * wtf/none/MainThreadNone.cpp:
     62        (WTF::initializeMainThreadPlatform): Deleted.
     63        (WTF::scheduleDispatchFunctionsOnMainThread): Deleted.
     64        * wtf/none/RunLoopNone.cpp:
     65        (WTF::RunLoop::RunLoop): Deleted.
     66        (WTF::RunLoop::~RunLoop): Deleted.
     67        (WTF::RunLoop::run): Deleted.
     68        (WTF::RunLoop::stop): Deleted.
     69        (WTF::RunLoop::wakeUp): Deleted.
     70        (WTF::RunLoop::TimerBase::TimerBase): Deleted.
     71        (WTF::RunLoop::TimerBase::~TimerBase): Deleted.
     72        (WTF::RunLoop::TimerBase::start): Deleted.
     73        (WTF::RunLoop::TimerBase::stop): Deleted.
     74        (WTF::RunLoop::TimerBase::isActive): Deleted.
     75        * wtf/none/WorkQueueNone.cpp:
     76        (WorkQueue::platformInitialize): Deleted.
     77        (WorkQueue::platformInvalidate): Deleted.
     78        (WorkQueue::dispatch): Deleted.
     79        (WorkQueue::dispatchAfter): Deleted.
     80
    1812016-04-18  Commit Queue  <commit-queue@webkit.org>
    282
  • trunk/Source/WTF/wtf/Platform.h

    r199366 r199694  
    11451145#endif
    11461146
     1147
     1148#if !defined(WTF_DEFAULT_EVENT_LOOP)
     1149#define WTF_DEFAULT_EVENT_LOOP 1
     1150#endif
     1151
     1152#if WTF_DEFAULT_EVENT_LOOP
     1153#if PLATFORM(WIN)
     1154/* Use Windows message pump abstraction.
     1155 * Even if the port is AppleWin, we use the Windows message pump system for the event loop,
     1156 * so that USE(WINDOWS_EVENT_LOOP) && USE(CF) can be true.
     1157 * And PLATFORM(WIN), PLATFORM(EFL) and PLATFORM(GTK) are exclusive. If the port is GTK,
     1158 * PLATFORM(WIN) should be false. And in that case, GLib's event loop is used.
     1159 */
     1160#define USE_WINDOWS_EVENT_LOOP 1
     1161#elif PLATFORM(COCOA)
     1162/* OS X and IOS. Use CoreFoundation & GCD abstraction. */
     1163#define USE_COCOA_EVENT_LOOP 1
     1164#elif PLATFORM(EFL)
     1165/* EFL port uses GLib. But it uses its own event loop abstraction.
     1166 * Thus, USE(EFL_EVENT_LOOP) && USE(GLIB) can be true.
     1167 */
     1168#define USE_EFL_EVENT_LOOP 1
     1169#elif USE(GLIB)
     1170/* Use GLib's event loop abstraction. Primarily GTK port uses it. */
     1171#define USE_GLIB_EVENT_LOOP 1
     1172#else
     1173#define USE_GENERIC_EVENT_LOOP 1
     1174#endif
     1175#endif
     1176
    11471177#endif /* WTF_Platform_h */
  • trunk/Source/WTF/wtf/PlatformJSCOnly.cmake

    r198086 r199694  
    1 if (LOWERCASE_EVENTLOOP_TYPE STREQUAL "glib")
     1if (LOWERCASE_EVENT_LOOP_TYPE STREQUAL "glib")
    22    list(APPEND WTF_SOURCES
    33        glib/GRefPtr.cpp
     
    1616else ()
    1717    list(APPEND WTF_SOURCES
    18         none/MainThreadNone.cpp
    19         none/RunLoopNone.cpp
    20         none/WorkQueueNone.cpp
     18        generic/MainThreadGeneric.cpp
     19        generic/RunLoopGeneric.cpp
     20        generic/WorkQueueGeneric.cpp
    2121    )
    2222endif ()
  • trunk/Source/WTF/wtf/RunLoop.h

    r197563 r199694  
    2929#define RunLoop_h
    3030
     31#include <wtf/Condition.h>
    3132#include <wtf/Deque.h>
    3233#include <wtf/Forward.h>
     
    3637#include <wtf/Threading.h>
    3738
    38 #if USE(GLIB)
     39#if USE(GLIB_EVENT_LOOP)
    3940#include <wtf/glib/GRefPtr.h>
    4041#endif
    4142
    42 #if PLATFORM(EFL)
     43#if USE(EFL_EVENT_LOOP)
    4344#include <Ecore.h>
    4445#include <wtf/efl/UniquePtrEfl.h>
     
    6566    WTF_EXPORT_PRIVATE void wakeUp();
    6667
    67 #if PLATFORM(COCOA)
     68#if USE(COCOA_EVENT_LOOP)
    6869    WTF_EXPORT_PRIVATE void runForDuration(double duration);
    6970#endif
    7071
    71 #if USE(GLIB) && !PLATFORM(EFL)
     72#if USE(GLIB_EVENT_LOOP)
    7273    WTF_EXPORT_PRIVATE GMainContext* mainContext() const { return m_mainContext.get(); }
     74#endif
     75
     76#if USE(GENERIC_EVENT_LOOP)
     77    // Run the single iteration of the RunLoop. It consumes the pending tasks and expired timers, but it won't be blocked.
     78    WTF_EXPORT_PRIVATE static void iterate();
     79    WTF_EXPORT_PRIVATE void dispatchAfter(std::chrono::nanoseconds, std::function<void()>);
    7380#endif
    7481
     
    8895        virtual void fired() = 0;
    8996
    90 #if USE(GLIB) && !PLATFORM(EFL)
     97#if USE(GLIB_EVENT_LOOP)
    9198        void setPriority(int);
    9299#endif
     
    97104        RunLoop& m_runLoop;
    98105
    99 #if PLATFORM(WIN)
     106#if USE(WINDOWS_EVENT_LOOP)
    100107        static void timerFired(RunLoop*, uint64_t ID);
    101108        uint64_t m_ID;
    102109        bool m_isRepeating;
    103 #elif PLATFORM(COCOA)
     110#elif USE(COCOA_EVENT_LOOP)
    104111        static void timerFired(CFRunLoopTimerRef, void*);
    105112        RetainPtr<CFRunLoopTimerRef> m_timer;
    106 #elif PLATFORM(EFL)
     113#elif USE(EFL_EVENT_LOOP)
    107114        static bool timerFired(void* data);
    108115        Ecore_Timer* m_timer;
    109116        bool m_isRepeating;
    110 #elif USE(GLIB)
     117#elif USE(GLIB_EVENT_LOOP)
    111118        void updateReadyTime();
    112119        GRefPtr<GSource> m_source;
    113120        bool m_isRepeating { false };
    114121        std::chrono::microseconds m_fireInterval { 0 };
     122#elif USE(GENERIC_EVENT_LOOP)
     123        class ScheduledTask;
     124        RefPtr<ScheduledTask> m_scheduledTask;
    115125#endif
    116126    };
     
    145155    Deque<std::function<void ()>> m_functionQueue;
    146156
    147 #if PLATFORM(WIN)
     157#if USE(WINDOWS_EVENT_LOOP)
    148158    static bool registerRunLoopMessageWindowClass();
    149159    static LRESULT CALLBACK RunLoopWndProc(HWND, UINT, WPARAM, LPARAM);
     
    153163    typedef HashMap<uint64_t, TimerBase*> TimerMap;
    154164    TimerMap m_activeTimers;
    155 #elif PLATFORM(COCOA)
     165#elif USE(COCOA_EVENT_LOOP)
    156166    static void performWork(void*);
    157167    RetainPtr<CFRunLoopRef> m_runLoop;
    158168    RetainPtr<CFRunLoopSourceRef> m_runLoopSource;
    159169    int m_nestingLevel;
    160 #elif PLATFORM(EFL)
     170#elif USE(EFL_EVENT_LOOP)
    161171    Mutex m_pipeLock;
    162172    EflUniquePtr<Ecore_Pipe> m_pipe;
     
    166176
    167177    static void wakeUpEvent(void* data, void*, unsigned);
    168 #elif USE(GLIB)
     178#elif USE(GLIB_EVENT_LOOP)
    169179    GRefPtr<GMainContext> m_mainContext;
    170180    Vector<GRefPtr<GMainLoop>> m_mainLoops;
    171181    GRefPtr<GSource> m_source;
     182#elif USE(GENERIC_EVENT_LOOP)
     183    void schedule(RefPtr<TimerBase::ScheduledTask>&&);
     184    void schedule(const LockHolder&, RefPtr<TimerBase::ScheduledTask>&&);
     185    void wakeUp(const LockHolder&);
     186    void scheduleAndWakeUp(RefPtr<TimerBase::ScheduledTask>);
     187
     188    enum class RunMode {
     189        Iterate,
     190        Drain
     191    };
     192
     193    enum class Status {
     194        Clear,
     195        Stopping,
     196    };
     197    void runImpl(RunMode);
     198    bool populateTasks(RunMode, Status&, Deque<RefPtr<TimerBase::ScheduledTask>>&);
     199
     200    Lock m_loopLock;
     201    Condition m_readyToRun;
     202    Condition m_stopCondition;
     203    Vector<RefPtr<TimerBase::ScheduledTask>> m_schedules;
     204    Vector<Status*> m_mainLoops;
     205    bool m_shutdown { false };
     206    bool m_pendingTasks { false };
    172207#endif
    173208};
  • trunk/Source/WTF/wtf/WorkQueue.h

    r198086 r199694  
    3535#include <wtf/Threading.h>
    3636
    37 #if OS(DARWIN) && !PLATFORM(GTK)
     37#if USE(COCOA_EVENT_LOOP)
    3838#include <dispatch/dispatch.h>
    3939#endif
    4040
    41 #if PLATFORM(EFL)
     41#if USE(EFL_EVENT_LOOP)
    4242#include <DispatchQueueEfl.h>
    43 #elif USE(GLIB)
    44 #include <wtf/Condition.h>
    45 #include <wtf/RunLoop.h>
    46 #include <wtf/glib/GRefPtr.h>
    47 #elif OS(WINDOWS)
     43#endif
     44
     45#if USE(WINDOWS_EVENT_LOOP)
    4846#include <wtf/HashMap.h>
    4947#include <wtf/Vector.h>
    5048#include <wtf/win/WorkItemWin.h>
     49#endif
     50
     51#if USE(GLIB_EVENT_LOOP)
     52#include <wtf/glib/GRefPtr.h>
     53#endif
     54
     55#if USE(GLIB_EVENT_LOOP) || USE(GENERIC_EVENT_LOOP)
     56#include <wtf/Condition.h>
     57#include <wtf/RunLoop.h>
    5158#endif
    5259
     
    7582    WTF_EXPORT_PRIVATE static void concurrentApply(size_t iterations, const std::function<void (size_t index)>&);
    7683
    77 #if PLATFORM(EFL)
     84#if USE(EFL_EVENT_LOOP)
    7885    void registerSocketEventHandler(int, std::function<void ()>);
    7986    void unregisterSocketEventHandler(int);
    80 #elif USE(GLIB)
     87#elif USE(COCOA_EVENT_LOOP)
     88    dispatch_queue_t dispatchQueue() const { return m_dispatchQueue; }
     89#elif USE(GLIB_EVENT_LOOP) || USE(GENERIC_EVENT_LOOP)
    8190    RunLoop& runLoop() const { return *m_runLoop; }
    82 #elif OS(DARWIN)
    83     dispatch_queue_t dispatchQueue() const { return m_dispatchQueue; }
    8491#endif
    8592
     
    9097    void platformInvalidate();
    9198
    92 #if OS(WINDOWS)
     99#if USE(WINDOWS_EVENT_LOOP)
    93100    static void CALLBACK handleCallback(void* context, BOOLEAN timerOrWaitFired);
    94101    static void CALLBACK timerCallback(void* context, BOOLEAN timerOrWaitFired);
     
    103110#endif
    104111
    105 #if PLATFORM(EFL)
     112#if USE(EFL_EVENT_LOOP)
    106113    RefPtr<DispatchQueue> m_dispatchQueue;
    107 #elif USE(GLIB)
    108     ThreadIdentifier m_workQueueThread;
    109     Lock m_initializeRunLoopConditionMutex;
    110     Condition m_initializeRunLoopCondition;
    111     RunLoop* m_runLoop;
    112     Lock m_terminateRunLoopConditionMutex;
    113     Condition m_terminateRunLoopCondition;
    114 #elif OS(DARWIN)
     114#elif USE(COCOA_EVENT_LOOP)
    115115    static void executeFunction(void*);
    116116    dispatch_queue_t m_dispatchQueue;
    117 #elif OS(WINDOWS)
     117#elif USE(WINDOWS_EVENT_LOOP)
    118118    volatile LONG m_isWorkThreadRegistered;
    119119
     
    125125
    126126    HANDLE m_timerQueue;
     127#elif USE(GLIB_EVENT_LOOP) || USE(GENERIC_EVENT_LOOP)
     128    ThreadIdentifier m_workQueueThread;
     129    Lock m_initializeRunLoopConditionMutex;
     130    Condition m_initializeRunLoopCondition;
     131    RunLoop* m_runLoop;
     132    Lock m_terminateRunLoopConditionMutex;
     133    Condition m_terminateRunLoopCondition;
    127134#endif
    128135};
  • trunk/Source/WTF/wtf/generic/MainThreadGeneric.cpp

    r199693 r199694  
    11/*
    22 * Copyright (C) 2016 Konstantin Tokavev <annulen@yandex.ru>
     3 * Copyright (C) 2016 Yusuke Suzuki <utatane.tea@gmail.com>
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2728#include "MainThread.h"
    2829
     30#include <wtf/RunLoop.h>
     31
    2932namespace WTF {
    3033
     
    3538void scheduleDispatchFunctionsOnMainThread()
    3639{
     40    RunLoop::main().dispatch(std::function<void()>(dispatchFunctionsFromMainThread));
    3741}
    3842
  • trunk/Source/cmake/OptionsJSCOnly.cmake

    r198388 r199694  
    1212WEBKIT_OPTION_END()
    1313
    14 set(ALL_EVENTLOOP_TYPES
     14set(ALL_EVENT_LOOP_TYPES
    1515    GLib
    16     None
     16    Generic
    1717)
    1818
    19 if (UNIX AND NOT APPLE)
    20     set(DEFAULT_EVENTLOOP_TYPE "GLib")
    21 else ()
    22     # TODO: Use native Mac and Win implementations
    23     set(DEFAULT_EVENTLOOP_TYPE "None")
    24 endif ()
     19set(DEFAULT_EVENT_LOOP_TYPE "Generic")
    2520
    26 set(EVENTLOOP_TYPE ${DEFAULT_EVENTLOOP_TYPE} CACHE STRING "Implementation of event loop to be used in JavaScriptCore (one of ${ALL_EVENTLOOP_TYPES})")
     21set(EVENT_LOOP_TYPE ${DEFAULT_EVENT_LOOP_TYPE} CACHE STRING "Implementation of event loop to be used in JavaScriptCore (one of ${ALL_EVENT_LOOP_TYPES})")
    2722
    2823set(ENABLE_WEBCORE OFF)
    2924set(ENABLE_WEBKIT OFF)
    3025set(ENABLE_WEBKIT2 OFF)
    31 set(ENABLE_API_TESTS OFF)
     26set(ENABLE_API_TESTS ON)
    3227
    3328if (WTF_CPU_X86 OR WTF_CPU_X86_64)
     
    3934endif ()
    4035
    41 string(TOLOWER ${EVENTLOOP_TYPE} LOWERCASE_EVENTLOOP_TYPE)
    42 if (LOWERCASE_EVENTLOOP_TYPE STREQUAL "glib")
     36string(TOLOWER ${EVENT_LOOP_TYPE} LOWERCASE_EVENT_LOOP_TYPE)
     37if (LOWERCASE_EVENT_LOOP_TYPE STREQUAL "glib")
    4338    find_package(GLIB 2.36 REQUIRED COMPONENTS gio gobject)
    4439    SET_AND_EXPOSE_TO_BUILD(USE_GLIB 1)
     40    SET_AND_EXPOSE_TO_BUILD(USE_GLIB_EVENT_LOOP 1)
     41    SET_AND_EXPOSE_TO_BUILD(WTF_DEFAULT_EVENT_LOOP 0)
     42else ()
     43    SET_AND_EXPOSE_TO_BUILD(USE_GENERIC_EVENT_LOOP 1)
     44    SET_AND_EXPOSE_TO_BUILD(WTF_DEFAULT_EVENT_LOOP 0)
    4545endif ()
    4646
  • trunk/Tools/CMakeLists.txt

    r199656 r199694  
    3232    add_subdirectory(WebKitTestRunner)
    3333    add_subdirectory(MiniBrowser/mac)
     34elseif ("${PORT}" STREQUAL "JSCOnly")
     35    if (ENABLE_API_TESTS)
     36        add_subdirectory(TestWebKitAPI)
     37    endif ()
    3438endif ()
    3539
  • trunk/Tools/ChangeLog

    r199681 r199694  
     12016-04-18  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSCOnly] Implement RunLoop and remove glib dependency
     4        https://bugs.webkit.org/show_bug.cgi?id=155706
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Add TestWTF to JSCOnly port to test WorkQueue and RunLoop.
     9        Platform specific ones locate under jsconly directory since
     10        it is not `generic` (Since it includes the GLIB event loop case).
     11
     12        * CMakeLists.txt:
     13        * TestWebKitAPI/PlatformJSCOnly.cmake: Added.
     14        * TestWebKitAPI/PlatformUtilities.h:
     15        * TestWebKitAPI/Tests/WTF/RunLoop.cpp:
     16        (TestWebKitAPI::TEST):
     17        * TestWebKitAPI/config.h:
     18        * TestWebKitAPI/jsconly/PlatformUtilitiesJSCOnly.cpp: Renamed from Source/WTF/wtf/none/RunLoopNone.cpp.
     19        (TestWebKitAPI::Util::run):
     20        (TestWebKitAPI::Util::sleep):
     21        * TestWebKitAPI/jsconly/main.cpp: Renamed from Source/WTF/wtf/none/WorkQueueNone.cpp.
     22        (main):
     23
    1242016-04-18  Jon Lee  <jonlee@apple.com>
    225
  • trunk/Tools/TestWebKitAPI/PlatformUtilities.h

    r188844 r199694  
    2727#define PlatformUtilities_h
    2828
     29#ifndef BUILDING_JSCONLY__
    2930#include <WebKit/WKNativeEvent.h>
    3031#include <WebKit/WKRetainPtr.h>
     32#endif
    3133#include <string>
    3234
  • trunk/Tools/TestWebKitAPI/Tests/WTF/RunLoop.cpp

    r186006 r199694  
    5555}
    5656
     57TEST(WTF_RunLoop, NestedRunLoop)
     58{
     59    RunLoop::initializeMainRunLoop();
     60
     61    bool testFinished = false;
     62    RunLoop::current().dispatch([&] {
     63        RunLoop::current().dispatch([&] {
     64            testFinished = true;
     65        });
     66        Util::run(&testFinished);
     67    });
     68
     69    Util::run(&testFinished);
     70}
     71
     72TEST(WTF_RunLoop, OneShotTimer)
     73{
     74    RunLoop::initializeMainRunLoop();
     75
     76    bool testFinished = false;
     77
     78    class DerivedTimer : public RunLoop::Timer<DerivedTimer> {
     79    public:
     80        DerivedTimer(bool& testFinished)
     81            : RunLoop::Timer<DerivedTimer>(RunLoop::current(), this, &DerivedTimer::fired)
     82            , m_testFinished(testFinished)
     83        {
     84        }
     85
     86        void fired()
     87        {
     88            m_testFinished = true;
     89            stop();
     90        }
     91
     92    private:
     93        bool& m_testFinished;
     94    };
     95
     96    {
     97        DerivedTimer timer(testFinished);
     98        timer.startOneShot(0.1);
     99        Util::run(&testFinished);
     100    }
     101}
     102
     103TEST(WTF_RunLoop, RepeatingTimer)
     104{
     105    RunLoop::initializeMainRunLoop();
     106
     107    bool testFinished = false;
     108
     109    class DerivedTimer : public RunLoop::Timer<DerivedTimer> {
     110    public:
     111        DerivedTimer(bool& testFinished)
     112            : RunLoop::Timer<DerivedTimer>(RunLoop::current(), this, &DerivedTimer::fired)
     113            , m_testFinished(testFinished)
     114        {
     115        }
     116
     117        void fired()
     118        {
     119            if (++m_count == 10) {
     120                m_testFinished = true;
     121                stop();
     122            }
     123        }
     124
     125    private:
     126        unsigned m_count { 0 };
     127        bool& m_testFinished;
     128    };
     129
     130    {
     131        DerivedTimer timer(testFinished);
     132        timer.startRepeating(0.01);
     133        Util::run(&testFinished);
     134    }
     135}
     136
     137TEST(WTF_RunLoop, ManyTimes)
     138{
     139    RunLoop::initializeMainRunLoop();
     140
     141    class Counter {
     142    public:
     143        void run()
     144        {
     145            if (++m_count == 100000) {
     146                RunLoop::current().stop();
     147                return;
     148            }
     149            RunLoop::current().dispatch([this] {
     150                run();
     151            });
     152        }
     153
     154    private:
     155        unsigned m_count { 0 };
     156    };
     157
     158    Counter counter;
     159
     160    RunLoop::current().dispatch([&counter] {
     161        counter.run();
     162    });
     163    RunLoop::run();
     164}
     165
    57166} // namespace TestWebKitAPI
  • trunk/Tools/TestWebKitAPI/config.h

    r188643 r199694  
    2828#endif
    2929
     30#include <runtime/JSExportMacros.h>
     31#ifndef BUILDING_JSCONLY__
    3032#include <WebCore/PlatformExportMacros.h>
    31 #include <runtime/JSExportMacros.h>
     33#endif
    3234
    3335#if defined(__APPLE__) && __APPLE__
     
    6466#include <stdint.h>
    6567
    66 #if !PLATFORM(IOS) && !PLATFORM(WIN) && !(PLATFORM(GTK) && !defined(BUILDING_WEBKIT2__))
     68#if !PLATFORM(IOS) && !PLATFORM(WIN) && !(PLATFORM(GTK) && !defined(BUILDING_WEBKIT2__)) && !defined(BUILDING_JSCONLY__)
    6769#include <WebKit/WebKit2_C.h>
    6870#endif
     
    9092#endif
    9193
    92 #if !PLATFORM(IOS)
     94#if !PLATFORM(IOS) && !defined(BUILDING_JSCONLY__)
    9395#define WK_HAVE_C_SPI 1
    9496#endif
  • trunk/Tools/TestWebKitAPI/jsconly/PlatformUtilitiesJSCOnly.cpp

    r199693 r199694  
    11/*
    2  * Copyright (C) 2016 Konstantin Tokavev <annulen@yandex.ru>
     2 * Copyright (C) 2016 Yusuke Suzuki <utatane.tea@gmail.com>
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2525
    2626#include "config.h"
    27 #include "RunLoop.h"
     27#include "PlatformUtilities.h"
    2828
    29 namespace WTF {
     29#include <wtf/CurrentTime.h>
     30#include <wtf/RunLoop.h>
    3031
    31 RunLoop::RunLoop()
     32#if USE(GLIB_EVENT_LOOP)
     33#include <glib.h>
     34#include <wtf/glib/GRefPtr.h>
     35#endif
     36
     37namespace TestWebKitAPI {
     38namespace Util {
     39
     40void run(bool* done)
    3241{
     42    while (!*done) {
     43#if USE(GLIB_EVENT_LOOP)
     44        g_main_context_iteration(RunLoop::current().mainContext(), false);
     45#else
     46        WTF::RunLoop::iterate();
     47#endif
     48    }
    3349}
    3450
    35 RunLoop::~RunLoop()
     51void sleep(double seconds)
    3652{
     53    WTF::sleep(seconds);
    3754}
    3855
    39 void RunLoop::run()
    40 {
    41 }
    42 
    43 void RunLoop::stop()
    44 {
    45 }
    46 
    47 void RunLoop::wakeUp()
    48 {
    49     ASSERT_NOT_REACHED();
    50 }
    51 
    52 RunLoop::TimerBase::TimerBase(RunLoop& runLoop)
    53     : m_runLoop(runLoop)
    54 {
    55 }
    56 
    57 RunLoop::TimerBase::~TimerBase()
    58 {
    59     stop();
    60 }
    61 
    62 void RunLoop::TimerBase::start(double, bool)
    63 {
    64 }
    65 
    66 void RunLoop::TimerBase::stop()
    67 {
    68 }
    69 
    70 bool RunLoop::TimerBase::isActive() const
    71 {
    72     return false;
    73 }
    74 
    75 } // namespace WTF
     56} // namespace Util
     57} // namespace TestWebKitAPI
  • trunk/Tools/TestWebKitAPI/jsconly/main.cpp

    r199693 r199694  
    11/*
    2  * Copyright (C) 2016 Konstantin Tokavev <annulen@yandex.ru>
     2 * Copyright (C) 2016 Yusuke Suzuki <utatane.tea@gmail.com>
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2525
    2626#include "config.h"
    27 #include "WorkQueue.h"
     27#include "TestsController.h"
    2828
    29 void WorkQueue::platformInitialize(const char*, Type, QOS)
     29int main(int argc, char** argv)
    3030{
     31    return TestWebKitAPI::TestsController::singleton().run(argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE;
    3132}
    32 
    33 void WorkQueue::platformInvalidate()
    34 {
    35 }
    36 
    37 void WorkQueue::dispatch(std::function<void()>)
    38 {
    39     ASSERT_NOT_REACHED();
    40 }
    41 
    42 void WorkQueue::dispatchAfter(std::chrono::nanoseconds, std::function<void()>)
    43 {
    44     ASSERT_NOT_REACHED();
    45 }
Note: See TracChangeset for help on using the changeset viewer.