Ignore:
Timestamp:
Jan 14, 2009, 1:57:30 PM (16 years ago)
Author:
[email protected]
Message:

2009-01-14 Dmitry Titov <[email protected]>

Reviewed by Alexey Proskuryakov.

https://bugs.webkit.org/show_bug.cgi?id=23312
Implement MessageQueue::waitForMessageTimed()
Also fixed ThreadCondition::timedWait() to take absolute time, as discussed on webkit-dev.
Win32 version of timedWait still has to be implemented.

  • wtf/MessageQueue.h: (WTF::MessageQueueWaitResult: new enum for the result of MessageQueue::waitForMessageTimed. (WTF::MessageQueue::waitForMessage): (WTF::MessageQueue::waitForMessageTimed): New method.
  • wtf/Threading.h:
  • wtf/ThreadingGtk.cpp: (WTF::ThreadCondition::timedWait): changed to use absolute time instead of interval.
  • wtf/ThreadingNone.cpp: (WTF::ThreadCondition::timedWait): ditto.
  • wtf/ThreadingPthreads.cpp: (WTF::ThreadCondition::timedWait): ditto.
  • wtf/ThreadingQt.cpp: (WTF::ThreadCondition::timedWait): ditto.
  • wtf/ThreadingWin.cpp: (WTF::ThreadCondition::timedWait): ditto. The actual Win32 code is still to be implemented.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/ThreadingPthreads.cpp

    r39487 r39908  
    3434#if USE(PTHREADS)
    3535
     36#include "CurrentTime.h"
    3637#include "HashMap.h"
    3738#include "MainThread.h"
     
    233234}
    234235
    235 bool ThreadCondition::timedWait(Mutex& mutex, double secondsToWait)
    236 {
    237     if (secondsToWait < 0.0) {
     236bool ThreadCondition::timedWait(Mutex& mutex, double absoluteTime)
     237{
     238    if (absoluteTime < currentTime())
     239        return false;
     240
     241    if (absoluteTime > INT_MAX) {
    238242        wait(mutex);
    239243        return true;
    240244    }
    241245
    242     int intervalSeconds = static_cast<int>(secondsToWait);
    243     int intervalMicroseconds = static_cast<int>((secondsToWait - intervalSeconds) * 1000000.0);
    244 
    245     // Current time comes in sec/microsec
    246     timeval currentTime;
    247     gettimeofday(&currentTime, NULL);
    248 
    249     // Target time comes in sec/nanosec
     246    int timeSeconds = static_cast<int>(absoluteTime);
     247    int timeNanoseconds = static_cast<int>((absoluteTime - timeSeconds) * 1E9);
     248
    250249    timespec targetTime;
    251     targetTime.tv_sec = currentTime.tv_sec + intervalSeconds;
    252     targetTime.tv_nsec = (currentTime.tv_usec + intervalMicroseconds) * 1000;
    253     if (targetTime.tv_nsec > 1000000000) {
    254         targetTime.tv_nsec -= 1000000000;
    255         targetTime.tv_sec++;
    256     }
     250    targetTime.tv_sec = timeSeconds;
     251    targetTime.tv_nsec = timeNanoseconds;
    257252
    258253    return pthread_cond_timedwait(&m_condition, &mutex.impl(), &targetTime) == 0;
Note: See TracChangeset for help on using the changeset viewer.