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

    r39487 r39908  
    3333#if !USE(PTHREADS)
    3434
     35#include "CurrentTime.h"
    3536#include "HashMap.h"
    3637#include "MainThread.h"
     
    3839
    3940#include <glib.h>
     41#include <limits.h>
    4042
    4143namespace WTF {
     
    206208}
    207209
    208 bool ThreadCondition::timedWait(Mutex& mutex, double interval)
    209 {
    210     if (interval < 0.0) {
     210bool ThreadCondition::timedWait(Mutex& mutex, double absoluteTime)
     211{
     212    // Time is in the past - return right away.
     213    if (absoluteTime < currentTime())
     214        return false;
     215   
     216    // Time is too far in the future for g_cond_timed_wait - wait forever.
     217    if (absoluteTime > INT_MAX) {
    211218        wait(mutex);
    212219        return true;
    213220    }
    214    
    215     int intervalSeconds = static_cast<int>(interval);
    216     int intervalMicroseconds = static_cast<int>((interval - intervalSeconds) * 1000000.0);
     221
     222    int timeSeconds = static_cast<int>(absoluteTime);
     223    int timeMicroseconds = static_cast<int>((absoluteTime - timeSeconds) * 1000000.0);
    217224   
    218225    GTimeVal targetTime;
    219     g_get_current_time(&targetTime);
    220        
    221     targetTime.tv_sec += intervalSeconds;
    222     targetTime.tv_usec += intervalMicroseconds;
    223     if (targetTime.tv_usec > 1000000) {
    224         targetTime.tv_usec -= 1000000;
    225         targetTime.tv_sec++;
    226     }
     226    targetTime.tv_sec = timeSeconds;
     227    targetTime.tv_usec = timeMicroseconds;
    227228
    228229    return g_cond_timed_wait(m_condition.get(), mutex.impl().get(), &targetTime);
Note: See TracChangeset for help on using the changeset viewer.