Changeset 41081 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Feb 19, 2009, 11:40:07 AM (17 years ago)
Author:
[email protected]
Message:

2009-02-19 David Levin <[email protected]>

Reviewed by Alexey Proskuryakov.

Bug 23976: MessageQueue needs a way to wait for a message that satisfies an arbitrary criteria.
<https://bugs.webkit.org/show_bug.cgi?id=23976>

  • wtf/Deque.h: (WTF::Deque<T>::findIf):
  • wtf/MessageQueue.h: (WTF::MessageQueue<T>::waitForMessageFiltered):
Location:
trunk/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r41068 r41081  
     12009-02-19  David Levin  <[email protected]>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        Bug 23976: MessageQueue needs a way to wait for a message that satisfies an arbitrary criteria.
     6        <https://bugs.webkit.org/show_bug.cgi?id=23976>
     7
     8        * wtf/Deque.h:
     9        (WTF::Deque<T>::findIf):
     10        * wtf/MessageQueue.h:
     11        (WTF::MessageQueue<T>::waitForMessageFiltered):
     12
    1132009-02-18  David Levin  <[email protected]>
    214
  • trunk/JavaScriptCore/wtf/Deque.h

    r41068 r41081  
    8282        void clear();
    8383
     84        template<typename Predicate>
     85        iterator findIf(Predicate&);
     86
    8487    private:
    8588        friend class DequeIteratorBase<T>;
     
    354357    }
    355358
    356     template <typename T>
     359    template<typename T>
    357360    inline void Deque<T>::swap(Deque<T>& other)
    358361    {
     
    367370    }
    368371
    369     template <typename T>
     372    template<typename T>
    370373    inline void Deque<T>::clear()
    371374    {
     
    376379        m_end = 0;
    377380        checkValidity();
     381    }
     382
     383    template<typename T>
     384    template<typename Predicate>
     385    inline DequeIterator<T> Deque<T>::findIf(Predicate& predicate)
     386    {
     387        iterator end_iterator = end();
     388        for (iterator it = begin(); it != end_iterator; ++it) {
     389            if (predicate(*it))
     390                return it;
     391        }
     392        return end_iterator;
    378393    }
    379394
  • trunk/JavaScriptCore/wtf/MessageQueue.h

    r39908 r41081  
    11/*
    22 * Copyright (C) 2008 Apple Inc. All rights reserved.
     3 * Copyright (C) 2009 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    5152        void prepend(const DataType&);
    5253        bool waitForMessage(DataType&);
     54        template<typename Predicate>
     55        MessageQueueWaitResult waitForMessageFiltered(DataType&, Predicate&);
    5356        MessageQueueWaitResult waitForMessageTimed(DataType&, double absoluteTime);
    5457        void kill();
     
    98101        m_queue.removeFirst();
    99102        return true;
     103    }
     104
     105    template<typename DataType>
     106    template<typename Predicate>
     107    inline MessageQueueWaitResult MessageQueue<DataType>::waitForMessageFiltered(DataType& result, Predicate& predicate)
     108    {
     109        MutexLocker lock(m_mutex);
     110
     111        DequeConstIterator<DataType> found = m_queue.end();
     112        while (!m_killed && (found = m_queue.findIf(predicate)) == m_queue.end())
     113            m_condition.wait(m_mutex);
     114
     115        if (m_killed)
     116            return MessageQueueTerminated;
     117
     118        ASSERT(found != m_queue.end());
     119        result = *found;
     120        m_queue.remove(found);
     121        return MessageQueueMessageReceived;
    100122    }
    101123
     
    158180        return m_killed;
    159181    }
    160 }
     182} // namespace WTF
    161183
    162184using WTF::MessageQueue;
Note: See TracChangeset for help on using the changeset viewer.