| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Google Inc. All rights reserved. | 3 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 // when messages are fetched from the queue. | 48 // when messages are fetched from the queue. |
| 49 // Essentially, MessageQueue acts as a queue of OwnPtr<DataType>. | 49 // Essentially, MessageQueue acts as a queue of OwnPtr<DataType>. |
| 50 template<typename DataType> | 50 template<typename DataType> |
| 51 class MessageQueue { | 51 class MessageQueue { |
| 52 WTF_MAKE_NONCOPYABLE(MessageQueue); | 52 WTF_MAKE_NONCOPYABLE(MessageQueue); |
| 53 public: | 53 public: |
| 54 MessageQueue() : m_killed(false) { } | 54 MessageQueue() : m_killed(false) { } |
| 55 ~MessageQueue(); | 55 ~MessageQueue(); |
| 56 | 56 |
| 57 void append(PassOwnPtr<DataType>); | 57 void append(PassOwnPtr<DataType>); |
| 58 void appendAndKill(PassOwnPtr<DataType>); |
| 58 bool appendAndCheckEmpty(PassOwnPtr<DataType>); | 59 bool appendAndCheckEmpty(PassOwnPtr<DataType>); |
| 59 void prepend(PassOwnPtr<DataType>); | 60 void prepend(PassOwnPtr<DataType>); |
| 60 | 61 |
| 61 PassOwnPtr<DataType> waitForMessage(); | 62 PassOwnPtr<DataType> waitForMessage(); |
| 62 PassOwnPtr<DataType> tryGetMessage(); | 63 PassOwnPtr<DataType> tryGetMessage(); |
| 63 PassOwnPtr<DataType> tryGetMessageIgnoringKilled(); | 64 PassOwnPtr<DataType> tryGetMessageIgnoringKilled(); |
| 64 template<typename Predicate> | 65 template<typename Predicate> |
| 65 PassOwnPtr<DataType> waitForMessageFilteredWithTimeout(MessageQueueWaitR
esult&, Predicate&, double absoluteTime); | 66 PassOwnPtr<DataType> waitForMessageFilteredWithTimeout(MessageQueueWaitR
esult&, Predicate&, double absoluteTime); |
| 66 | 67 |
| 67 template<typename Predicate> | 68 template<typename Predicate> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 91 } | 92 } |
| 92 | 93 |
| 93 template<typename DataType> | 94 template<typename DataType> |
| 94 inline void MessageQueue<DataType>::append(PassOwnPtr<DataType> message) | 95 inline void MessageQueue<DataType>::append(PassOwnPtr<DataType> message) |
| 95 { | 96 { |
| 96 MutexLocker lock(m_mutex); | 97 MutexLocker lock(m_mutex); |
| 97 m_queue.append(message.leakPtr()); | 98 m_queue.append(message.leakPtr()); |
| 98 m_condition.signal(); | 99 m_condition.signal(); |
| 99 } | 100 } |
| 100 | 101 |
| 102 template<typename DataType> |
| 103 inline void MessageQueue<DataType>::appendAndKill(PassOwnPtr<DataType> messa
ge) |
| 104 { |
| 105 MutexLocker lock(m_mutex); |
| 106 m_queue.append(message.leakPtr()); |
| 107 m_killed = true; |
| 108 m_condition.broadcast(); |
| 109 } |
| 110 |
| 101 // Returns true if the queue was empty before the item was added. | 111 // Returns true if the queue was empty before the item was added. |
| 102 template<typename DataType> | 112 template<typename DataType> |
| 103 inline bool MessageQueue<DataType>::appendAndCheckEmpty(PassOwnPtr<DataType>
message) | 113 inline bool MessageQueue<DataType>::appendAndCheckEmpty(PassOwnPtr<DataType>
message) |
| 104 { | 114 { |
| 105 MutexLocker lock(m_mutex); | 115 MutexLocker lock(m_mutex); |
| 106 bool wasEmpty = m_queue.isEmpty(); | 116 bool wasEmpty = m_queue.isEmpty(); |
| 107 m_queue.append(message.leakPtr()); | 117 m_queue.append(message.leakPtr()); |
| 108 m_condition.signal(); | 118 m_condition.signal(); |
| 109 return wasEmpty; | 119 return wasEmpty; |
| 110 } | 120 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } // namespace WTF | 227 } // namespace WTF |
| 218 | 228 |
| 219 using WTF::MessageQueue; | 229 using WTF::MessageQueue; |
| 220 // MessageQueueWaitResult enum and all its values. | 230 // MessageQueueWaitResult enum and all its values. |
| 221 using WTF::MessageQueueWaitResult; | 231 using WTF::MessageQueueWaitResult; |
| 222 using WTF::MessageQueueTerminated; | 232 using WTF::MessageQueueTerminated; |
| 223 using WTF::MessageQueueTimeout; | 233 using WTF::MessageQueueTimeout; |
| 224 using WTF::MessageQueueMessageReceived; | 234 using WTF::MessageQueueMessageReceived; |
| 225 | 235 |
| 226 #endif // MessageQueue_h | 236 #endif // MessageQueue_h |
| OLD | NEW |