Changeset 76967 in webkit


Ignore:
Timestamp:
Jan 28, 2011 12:16:02 PM (13 years ago)
Author:
Adam Roben
Message:

Change BinarySemaphore to wrap an auto-reset Win32 event on Windows

Fixes <http://webkit.org/b/53208> <rdar://problem/8922490>.

Reviewed by Dave Hyatt.

Source/WebKit2:

  • Platform/CoreIPC/BinarySemaphore.cpp: Wrap this implementation in #if !PLATFORM(WIN).
  • Platform/CoreIPC/BinarySemaphore.h: Make the Windows implementation have a single HANDLE

member that holds the event.

  • Platform/CoreIPC/win/BinarySemaphoreWin.cpp: Copied from Source/WebKit2/Platform/CoreIPC/BinarySemaphore.cpp.

(CoreIPC::BinarySemaphore::BinarySemaphore): Create our event.
(CoreIPC::BinarySemaphore::~BinarySemaphore): Destory our event.
(CoreIPC::BinarySemaphore::signal): Signal the event.
(CoreIPC::BinarySemaphore::wait): Convert the absolute time to a wait interval, then wait
for the event to be signaled or for the interval to elapse.

  • win/WebKit2.vcproj: Added BinarySemaphoreWin.cpp. Also let VS have its way with the file.

Source/JavaScriptCore:

Extract code to convert a WTF absolute time to a Win32 wait interval into a separate
function

  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: Export the new function.
  • wtf/ThreadingPrimitives.h: Declare the new function.
  • wtf/ThreadingWin.cpp:

(WTF::ThreadCondition::timedWait): Moved code to convert the absolute time to a wait
interval from here...
(WTF::absoluteTimeToWaitTimeoutInterval): ...to here.

Location:
trunk/Source
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r76956 r76967  
     12011-01-27  Adam Roben  <aroben@apple.com>
     2
     3        Extract code to convert a WTF absolute time to a Win32 wait interval into a separate
     4        function
     5
     6        Fixes <http://webkit.org/b/53208> <rdar://problem/8922490> BinarySemaphore should wrap a
     7        Win32 event
     8
     9        Reviewed by Dave Hyatt.
     10
     11        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: Export the new function.
     12
     13        * wtf/ThreadingPrimitives.h: Declare the new function.
     14
     15        * wtf/ThreadingWin.cpp:
     16        (WTF::ThreadCondition::timedWait): Moved code to convert the absolute time to a wait
     17        interval from here...
     18        (WTF::absoluteTimeToWaitTimeoutInterval): ...to here.
     19
    1202011-01-28  Sam Weinig  <sam@webkit.org>
    221
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def

    r76615 r76967  
    4444    ??8WTF@@YA_NABVCString@0@0@Z
    4545    ?NaN@JSC@@3NB
     46    ?absoluteTimeToWaitTimeoutInterval@WTF@@YAKN@Z
    4647    ?add@Identifier@JSC@@SA?AV?$PassRefPtr@VStringImpl@WTF@@@WTF@@PAVExecState@2@PBD@Z
    4748    ?add@PropertyNameArray@JSC@@QAEXPAVStringImpl@WTF@@@Z
  • trunk/Source/JavaScriptCore/wtf/ThreadingPrimitives.h

    r76248 r76967  
    151151};
    152152
     153#if PLATFORM(WIN)
     154// The absoluteTime is in seconds, starting on January 1, 1970. The time is assumed to use the same time zone as WTF::currentTime().
     155// Returns an interval in milliseconds suitable for passing to one of the Win32 wait functions (e.g., ::WaitForSingleObject).
     156DWORD absoluteTimeToWaitTimeoutInterval(double absoluteTime);
     157#endif
     158
    153159} // namespace WTF
    154160
     
    157163using WTF::ThreadCondition;
    158164
     165#if PLATFORM(WIN)
     166using WTF::absoluteTimeToWaitTimeoutInterval;
     167#endif
     168
    159169#endif // ThreadingPrimitives_h
  • trunk/Source/JavaScriptCore/wtf/ThreadingWin.cpp

    r74983 r76967  
    459459bool ThreadCondition::timedWait(Mutex& mutex, double absoluteTime)
    460460{
     461    DWORD interval = absoluteTimeToWaitTimeoutInterval(absoluteTime);
     462
     463    if (!interval) {
     464        // Consider the wait to have timed out, even if our condition has already been signaled, to
     465        // match the pthreads implementation.
     466        return false;
     467    }
     468
     469    return m_condition.timedWait(mutex.impl(), interval);
     470}
     471
     472void ThreadCondition::signal()
     473{
     474    m_condition.signal(false); // Unblock only 1 thread.
     475}
     476
     477void ThreadCondition::broadcast()
     478{
     479    m_condition.signal(true); // Unblock all threads.
     480}
     481
     482DWORD absoluteTimeToWaitTimeoutInterval(double absoluteTime)
     483{
    461484    double currentTime = WTF::currentTime();
    462485
    463486    // Time is in the past - return immediately.
    464487    if (absoluteTime < currentTime)
    465         return false;
     488        return 0;
    466489
    467490    // Time is too far in the future (and would overflow unsigned long) - wait forever.
    468     if (absoluteTime - currentTime > static_cast<double>(INT_MAX) / 1000.0) {
    469         wait(mutex);
    470         return true;
    471     }
    472 
    473     double intervalMilliseconds = (absoluteTime - currentTime) * 1000.0;
    474     return m_condition.timedWait(mutex.impl(), static_cast<unsigned long>(intervalMilliseconds));
    475 }
    476 
    477 void ThreadCondition::signal()
    478 {
    479     m_condition.signal(false); // Unblock only 1 thread.
    480 }
    481 
    482 void ThreadCondition::broadcast()
    483 {
    484     m_condition.signal(true); // Unblock all threads.
     491    if (absoluteTime - currentTime > static_cast<double>(INT_MAX) / 1000.0)
     492        return INFINITE;
     493
     494    return (absoluteTime - currentTime) * 1000;
    485495}
    486496
  • trunk/Source/WebKit2/ChangeLog

    r76962 r76967  
     12011-01-27  Adam Roben  <aroben@apple.com>
     2
     3        Change BinarySemaphore to wrap an auto-reset Win32 event on Windows
     4
     5        Fixes <http://webkit.org/b/53208> <rdar://problem/8922490>.
     6
     7        Reviewed by Dave Hyatt.
     8
     9        * Platform/CoreIPC/BinarySemaphore.cpp: Wrap this implementation in #if !PLATFORM(WIN).
     10
     11        * Platform/CoreIPC/BinarySemaphore.h: Make the Windows implementation have a single HANDLE
     12        member that holds the event.
     13
     14        * Platform/CoreIPC/win/BinarySemaphoreWin.cpp: Copied from Source/WebKit2/Platform/CoreIPC/BinarySemaphore.cpp.
     15        (CoreIPC::BinarySemaphore::BinarySemaphore): Create our event.
     16        (CoreIPC::BinarySemaphore::~BinarySemaphore): Destory our event.
     17        (CoreIPC::BinarySemaphore::signal): Signal the event.
     18        (CoreIPC::BinarySemaphore::wait): Convert the absolute time to a wait interval, then wait
     19        for the event to be signaled or for the interval to elapse.
     20
     21        * win/WebKit2.vcproj: Added BinarySemaphoreWin.cpp. Also let VS have its way with the file.
     22
    1232011-01-27  Chris Marrin  <cmarrin@apple.com>
    224
  • trunk/Source/WebKit2/Platform/CoreIPC/BinarySemaphore.cpp

    r76916 r76967  
    2828
    2929namespace CoreIPC {
     30
     31#if !PLATFORM(WIN)
    3032
    3133BinarySemaphore::BinarySemaphore()
     
    6264}
    6365
     66#endif // !PLATFORM(WIN)
    6467
    6568} // namespace CoreIPC
  • trunk/Source/WebKit2/Platform/CoreIPC/BinarySemaphore.h

    r69584 r76967  
    4343
    4444private:
     45#if PLATFORM(WIN)
     46    HANDLE m_event;
     47#else
    4548    bool m_isSet;
    4649
    4750    Mutex m_mutex;
    4851    ThreadCondition m_condition;
     52#endif
    4953};
    5054
  • trunk/Source/WebKit2/Platform/CoreIPC/win/BinarySemaphoreWin.cpp

    r76964 r76967  
    11/*
    2  * Copyright (C) 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2011 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3030
    3131BinarySemaphore::BinarySemaphore()
    32     : m_isSet(false)
     32    : m_event(::CreateEventW(0, FALSE, FALSE, 0))
    3333{
    3434}
    35    
     35
    3636BinarySemaphore::~BinarySemaphore()
    3737{
     38    ::CloseHandle(m_event);
    3839}
    3940
    4041void BinarySemaphore::signal()
    4142{
    42     MutexLocker locker(m_mutex);
    43 
    44     m_isSet = true;
    45     m_condition.signal();
     43    ::SetEvent(m_event);
    4644}
    4745
    4846bool BinarySemaphore::wait(double absoluteTime)
    4947{
    50     MutexLocker locker(m_mutex);
    51 
    52     bool timedOut = false;
    53     while (!m_isSet) {
    54         timedOut = !m_condition.timedWait(m_mutex, absoluteTime);
    55         if (timedOut)
    56             return false;
     48    DWORD interval = absoluteTimeToWaitTimeoutInterval(absoluteTime);
     49    if (!interval) {
     50        // Consider the wait to have timed out, even if the event has already been signaled, to
     51        // match the WTF::ThreadCondition implementation.
     52        return false;
    5753    }
    5854
    59     // Reset the semaphore.
    60     m_isSet = false;
    61     return true;
     55    DWORD result = ::WaitForSingleObjectEx(m_event, interval, FALSE);
     56    switch (result) {
     57    case WAIT_OBJECT_0:
     58        // The event was signaled.
     59        return true;
     60
     61    case WAIT_TIMEOUT:
     62        // The wait timed out.
     63        return false;
     64
     65    case WAIT_FAILED:
     66        ASSERT_WITH_MESSAGE(false, "::WaitForSingleObjectEx failed with error %lu", ::GetLastError());
     67        return false;
     68    default:
     69        ASSERT_WITH_MESSAGE(false, "::WaitForSingleObjectEx returned unexpected result %lu", result);
     70        return false;
     71    }
    6272}
    6373
    64 
    6574} // namespace CoreIPC
  • trunk/Source/WebKit2/win/WebKit2.vcproj

    r76769 r76967  
    400400                        </File>
    401401                        <File
     402                                RelativePath="..\Shared\CacheModel.h"
     403                                >
     404                        </File>
     405                        <File
     406                                RelativePath="..\Shared\ChildProcess.cpp"
     407                                >
     408                        </File>
     409                        <File
     410                                RelativePath="..\Shared\ChildProcess.h"
     411                                >
     412                        </File>
     413                        <File
     414                                RelativePath="..\Shared\CommandLine.h"
     415                                >
     416                        </File>
     417                        <File
     418                                RelativePath="..\Shared\ContextMenuState.h"
     419                                >
     420                        </File>
     421                        <File
     422                                RelativePath="..\Shared\DrawingAreaInfo.h"
     423                                >
     424                        </File>
     425                        <File
     426                                RelativePath="..\Shared\FontSmoothingLevel.h"
     427                                >
     428                        </File>
     429                        <File
     430                                RelativePath="..\Shared\ImmutableArray.cpp"
     431                                >
     432                        </File>
     433                        <File
     434                                RelativePath="..\Shared\ImmutableArray.h"
     435                                >
     436                        </File>
     437                        <File
     438                                RelativePath="..\Shared\ImmutableDictionary.cpp"
     439                                >
     440                        </File>
     441                        <File
     442                                RelativePath="..\Shared\ImmutableDictionary.h"
     443                                >
     444                        </File>
     445                        <File
     446                                RelativePath="..\Shared\MutableArray.cpp"
     447                                >
     448                        </File>
     449                        <File
     450                                RelativePath="..\Shared\MutableArray.h"
     451                                >
     452                        </File>
     453                        <File
     454                                RelativePath="..\Shared\MutableDictionary.cpp"
     455                                >
     456                        </File>
     457                        <File
     458                                RelativePath="..\Shared\MutableDictionary.h"
     459                                >
     460                        </File>
     461                        <File
     462                                RelativePath="..\Shared\NativeWebKeyboardEvent.h"
     463                                >
     464                        </File>
     465                        <File
     466                                RelativePath="..\Shared\NotImplemented.h"
     467                                >
     468                        </File>
     469                        <File
     470                                RelativePath="..\Shared\OriginAndDatabases.cpp"
     471                                >
     472                        </File>
     473                        <File
     474                                RelativePath="..\Shared\OriginAndDatabases.h"
     475                                >
     476                        </File>
     477                        <File
     478                                RelativePath="..\Shared\PlatformPopupMenuData.cpp"
     479                                >
     480                        </File>
     481                        <File
     482                                RelativePath="..\Shared\PlatformPopupMenuData.h"
     483                                >
     484                        </File>
     485                        <File
     486                                RelativePath="..\Shared\PrintInfo.cpp"
     487                                >
     488                        </File>
     489                        <File
     490                                RelativePath="..\Shared\PrintInfo.h"
     491                                >
     492                        </File>
     493                        <File
     494                                RelativePath="..\Shared\SameDocumentNavigationType.h"
     495                                >
     496                        </File>
     497                        <File
     498                                RelativePath="..\Shared\SelectionState.h"
     499                                >
     500                        </File>
     501                        <File
     502                                RelativePath="..\Shared\SessionState.cpp"
     503                                >
     504                        </File>
     505                        <File
     506                                RelativePath="..\Shared\SessionState.h"
     507                                >
     508                        </File>
     509                        <File
    402510                                RelativePath="..\Shared\ShareableBitmap.cpp"
    403511                                >
     
    405513                        <File
    406514                                RelativePath="..\Shared\ShareableBitmap.h"
    407                                 >
    408                         </File>
    409                         <File
    410                                 RelativePath="..\Shared\CacheModel.h"
    411                                 >
    412                         </File>
    413                         <File
    414                                 RelativePath="..\Shared\ChildProcess.cpp"
    415                                 >
    416                         </File>
    417                         <File
    418                                 RelativePath="..\Shared\ChildProcess.h"
    419                                 >
    420                         </File>
    421                         <File
    422                                 RelativePath="..\Shared\CommandLine.h"
    423                                 >
    424                         </File>
    425                         <File
    426                                 RelativePath="..\Shared\ContextMenuState.h"
    427                                 >
    428                         </File>
    429                         <File
    430                                 RelativePath="..\Shared\DrawingAreaInfo.h"
    431                                 >
    432                         </File>
    433                         <File
    434                                 RelativePath="..\Shared\FontSmoothingLevel.h"
    435                                 >
    436                         </File>
    437                         <File
    438                                 RelativePath="..\Shared\ImmutableArray.cpp"
    439                                 >
    440                         </File>
    441                         <File
    442                                 RelativePath="..\Shared\ImmutableArray.h"
    443                                 >
    444                         </File>
    445                         <File
    446                                 RelativePath="..\Shared\ImmutableDictionary.cpp"
    447                                 >
    448                         </File>
    449                         <File
    450                                 RelativePath="..\Shared\ImmutableDictionary.h"
    451                                 >
    452                         </File>
    453                         <File
    454                                 RelativePath="..\Shared\MutableArray.cpp"
    455                                 >
    456                         </File>
    457                         <File
    458                                 RelativePath="..\Shared\MutableArray.h"
    459                                 >
    460                         </File>
    461                         <File
    462                                 RelativePath="..\Shared\MutableDictionary.cpp"
    463                                 >
    464                         </File>
    465                         <File
    466                                 RelativePath="..\Shared\MutableDictionary.h"
    467                                 >
    468                         </File>
    469                         <File
    470                                 RelativePath="..\Shared\NativeWebKeyboardEvent.h"
    471                                 >
    472                         </File>
    473                         <File
    474                                 RelativePath="..\Shared\NotImplemented.h"
    475                                 >
    476                         </File>
    477                         <File
    478                                 RelativePath="..\Shared\OriginAndDatabases.cpp"
    479                                 >
    480                         </File>
    481                         <File
    482                                 RelativePath="..\Shared\OriginAndDatabases.h"
    483                                 >
    484                         </File>
    485                         <File
    486                                 RelativePath="..\Shared\PlatformPopupMenuData.cpp"
    487                                 >
    488                         </File>
    489                         <File
    490                                 RelativePath="..\Shared\PlatformPopupMenuData.h"
    491                                 >
    492                         </File>
    493                         <File
    494                                 RelativePath="..\Shared\PrintInfo.cpp"
    495                                 >
    496                         </File>
    497                         <File
    498                                 RelativePath="..\Shared\PrintInfo.h"
    499                                 >
    500                         </File>
    501                         <File
    502                                 RelativePath="..\Shared\SameDocumentNavigationType.h"
    503                                 >
    504                         </File>
    505                         <File
    506                                 RelativePath="..\Shared\SelectionState.h"
    507                                 >
    508                         </File>
    509                         <File
    510                                 RelativePath="..\Shared\SessionState.cpp"
    511                                 >
    512                         </File>
    513                         <File
    514                                 RelativePath="..\Shared\SessionState.h"
    515515                                >
    516516                        </File>
     
    18091809                                                </File>
    18101810                                                <File
     1811                                                        RelativePath="..\WebProcess\InjectedBundle\API\c\WKBundleHitTestResult.cpp"
     1812                                                        >
     1813                                                </File>
     1814                                                <File
     1815                                                        RelativePath="..\WebProcess\InjectedBundle\API\c\WKBundleHitTestResult.h"
     1816                                                        >
     1817                                                </File>
     1818                                                <File
     1819                                                        RelativePath="..\WebProcess\InjectedBundle\API\c\WKBundleInitialize.h"
     1820                                                        >
     1821                                                </File>
     1822                                                <File
    18111823                                                        RelativePath="..\WebProcess\InjectedBundle\API\c\WKBundleInspector.cpp"
    18121824                                                        >
     
    18141826                                                <File
    18151827                                                        RelativePath="..\WebProcess\InjectedBundle\API\c\WKBundleInspector.h"
    1816                                                         >
    1817                                                 </File>
    1818                                                 <File
    1819                                                         RelativePath="..\WebProcess\InjectedBundle\API\c\WKBundleHitTestResult.cpp"
    1820                                                         >
    1821                                                 </File>
    1822                                                 <File
    1823                                                         RelativePath="..\WebProcess\InjectedBundle\API\c\WKBundleHitTestResult.h"
    1824                                                         >
    1825                                                 </File>
    1826                                                 <File
    1827                                                         RelativePath="..\WebProcess\InjectedBundle\API\c\WKBundleInitialize.h"
    18281828                                                        >
    18291829                                                </File>
     
    29772977                                        Name="win"
    29782978                                        >
     2979                                        <File
     2980                                                RelativePath="..\Platform\CoreIPC\win\BinarySemaphoreWin.cpp"
     2981                                                >
     2982                                        </File>
    29792983                                        <File
    29802984                                                RelativePath="..\Platform\CoreIPC\win\ConnectionWin.cpp"
Note: See TracChangeset for help on using the changeset viewer.