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/ThreadingQt.cpp

    r39487 r39908  
    3030#include "Threading.h"
    3131
     32#include "CurrentTime.h"
    3233#include "HashMap.h"
    3334#include "MainThread.h"
     
    234235}
    235236
    236 bool ThreadCondition::timedWait(Mutex& mutex, double secondsToWait)
    237 {
    238     if (secondsToWait < 0.0) {
    239         wait(mutex);
    240         return true;
    241     }
    242 
    243     unsigned long millisecondsToWait = static_cast<unsigned long>(secondsToWait * 1000.0);
    244     return m_condition->wait(mutex.impl(), millisecondsToWait);
     237bool ThreadCondition::timedWait(Mutex& mutex, double absoluteTime)
     238{
     239    double currentTime = WTF::currentTime();
     240
     241    // Time is in the past - return immediately.
     242    if (absoluteTime < currentTime)
     243        return false;
     244
     245    double intervalMilliseconds = (absoluteTime - currentTime) * 1000.0;
     246    // Qt defines wait for up to ULONG_MAX milliseconds.
     247    if (interval >= ULONG_MAX)
     248        interval = ULONG_MAX;
     249
     250    return m_condition->wait(mutex.impl(), static_cast<unsigned long>(interval));
    245251}
    246252
Note: See TracChangeset for help on using the changeset viewer.