Changeset 30849 in webkit for trunk/JavaScriptCore/wtf


Ignore:
Timestamp:
Mar 6, 2008, 10:55:02 AM (17 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

Reviewed by Darin

Add a timedWait() method to ThreadCondition

  • wtf/Threading.h:
  • wtf/ThreadingGtk.cpp: (WTF::ThreadCondition::timedWait):
  • wtf/ThreadingNone.cpp: (WTF::ThreadCondition::timedWait):
  • wtf/ThreadingPthreads.cpp: (WTF::ThreadCondition::timedWait):
  • wtf/ThreadingWin.cpp: (WTF::ThreadCondition::timedWait): Needs implementation

WebKitTools:

Reviewed by Darin

Added a cross-platform Watchdog thread to DRT.

The current watchdog in both DRTWin and DRTMac is Timer based. Therefore, deadlocks and long running
main thread hangs still affect DRT.

By placing the watchdog on a thread and having DRT "check in" after each test, long-running hangs
and true deadlocks can be caught.

There is one hook for platform specific code. As I did my development and testing on Mac, and Mac has
sample available, the Mac implementation of this hook samples the process before it is killed.

I arbitrarily chose 30 seconds as the timeout for now - this can be tweaked easily if we find a need.

  • DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
  • DumpRenderTree/mac/Configurations/Base.xcconfig: Added LINKER_DISPLAYS_MANGLED_NAMES
  • DumpRenderTree/ForwardingHeaders/wtf/Locker.h: Added.
  • DumpRenderTree/ForwardingHeaders/wtf/Threading.h: Added.
  • DumpRenderTree/Watchdog.cpp: Added. (Watchdog::Watchdog): (Watchdog::~Watchdog): (Watchdog::start): (Watchdog::stop): (Watchdog::checkIn): (Watchdog::setWatchdogInterval): (Watchdog::handleHang): (Watchdog::watchdogThreadStart): (Watchdog::watchdogThread):
  • DumpRenderTree/Watchdog.h: Added.
  • DumpRenderTree/mac/WatchdogMac.h: Added.
  • DumpRenderTree/mac/WatchdogMac.mm: Added. (WatchdogMac::handleHang): Sample the process and write it out to a file
  • DumpRenderTree/mac/DumpRenderTree.mm: (dumpRenderTree): Setup and start the watchdog before running any tests (runTest): Checkin with the watchdog after each test
Location:
trunk/JavaScriptCore/wtf
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/Threading.h

    r30842 r30849  
    159159   
    160160    void wait(Mutex& mutex);
     161    // Returns true if the condition was signaled before the timeout, false if the timeout was reached
     162    bool timedWait(Mutex&, double interval);
    161163    void signal();
    162164    void broadcast();
  • trunk/JavaScriptCore/wtf/ThreadingGtk.cpp

    r30842 r30849  
    177177}
    178178
     179bool ThreadCondition::timedWait(Mutex& mutex, double interval)
     180{
     181    if (interval < 0.0) {
     182        wait(mutex);
     183        return true;
     184    }
     185   
     186    int intervalSeconds = static_cast<int>(interval);
     187    int intervalMicroseconds = static_cast<int>((interval - intervalSeconds) * 1000000.0);
     188   
     189    GTimeVal targetTime;
     190    g_get_current_time(&targetTime);
     191       
     192    targetTime.tv_sec += intervalSeconds;
     193    targetTime.tv_usec += intervalMicroseconds;
     194    if (targetTime.tv_usec > 1000000) {
     195        targetTime.tv_usec -= 1000000;
     196        targetTime.tv_sec++;
     197    }
     198
     199    return g_cond_timedwait(m_condition, mutex.impl(), &targetTime);
     200}
     201
    179202void ThreadCondition::signal()
    180203{
  • trunk/JavaScriptCore/wtf/ThreadingNone.cpp

    r30842 r30849  
    4848ThreadCondition::~ThreadCondition() {}
    4949void ThreadCondition::wait(Mutex& mutex) {}
     50bool ThreadCondition::timedWait(Mutex& mutex, double interval) { return false; }
    5051void ThreadCondition::signal() {}
    5152void ThreadCondition::broadcast() {}
  • trunk/JavaScriptCore/wtf/ThreadingPthreads.cpp

    r30842 r30849  
    3333
    3434#include <errno.h>
     35#include <time.h>
    3536
    3637namespace WTF {
     
    185186        ASSERT(false);
    186187}
    187    
     188
     189bool ThreadCondition::timedWait(Mutex& mutex, double interval)
     190{
     191    if (interval < 0.0) {
     192        wait(mutex);
     193        return true;
     194    }
     195   
     196    int intervalSeconds = static_cast<int>(interval);
     197    int intervalMicroseconds = static_cast<int>((interval - intervalSeconds) * 1000000.0);
     198   
     199    // Current time comes in sec/microsec
     200    timeval currentTime;
     201    gettimeofday(&currentTime, NULL);
     202   
     203    // Target time comes in sec/nanosec
     204    timespec targetTime;
     205    targetTime.tv_sec = currentTime.tv_sec + intervalSeconds;
     206    targetTime.tv_nsec = (currentTime.tv_usec + intervalMicroseconds) * 1000;
     207    if (targetTime.tv_nsec > 1000000000) {
     208        targetTime.tv_nsec -= 1000000000;
     209        targetTime.tv_sec++;
     210    }
     211
     212    return pthread_cond_timedwait(&m_condition, &mutex.impl(), &targetTime) == 0;
     213}
     214
    188215void ThreadCondition::signal()
    189216{
  • trunk/JavaScriptCore/wtf/ThreadingWin.cpp

    r30842 r30849  
    284284
    285285    ::EnterCriticalSection (&cs.m_internalMutex);
     286}
     287
     288bool ThreadCondition::timedWait(Mutex& mutex, double interval)
     289{
     290    // Empty for now
     291    ASSERT(false);
    286292}
    287293
Note: See TracChangeset for help on using the changeset viewer.