source: webkit/trunk/JavaScriptCore/wtf/MessageQueue.h@ 50129

Last change on this file since 50129 was 45891, checked in by [email protected], 16 years ago

JavaScriptCore:

2009-07-14 Zoltan Horvath <[email protected]>

Reviewed by Darin Adler.

Change all Noncopyable inheriting visibility to public.
https://bugs.webkit.org/show_bug.cgi?id=27225

Change all Noncopyable inheriting visibility to public because
it is needed to the custom allocation framework (bug #20422).

  • bytecode/SamplingTool.h:
  • bytecompiler/RegisterID.h:
  • interpreter/CachedCall.h:
  • interpreter/RegisterFile.h:
  • parser/Lexer.h:
  • parser/Parser.h:
  • runtime/ArgList.h:
  • runtime/BatchedTransitionOptimizer.h:
  • runtime/Collector.h:
  • runtime/CommonIdentifiers.h:
  • runtime/JSCell.h:
  • runtime/JSGlobalObject.h:
  • runtime/JSLock.h:
  • runtime/JSONObject.cpp:
  • runtime/SmallStrings.cpp:
  • runtime/SmallStrings.h:
  • wtf/CrossThreadRefCounted.h:
  • wtf/GOwnPtr.h:
  • wtf/Locker.h:
  • wtf/MessageQueue.h:
  • wtf/OwnArrayPtr.h:
  • wtf/OwnFastMallocPtr.h:
  • wtf/OwnPtr.h:
  • wtf/RefCounted.h:
  • wtf/ThreadSpecific.h:
  • wtf/Threading.h:
  • wtf/Vector.h:
  • wtf/unicode/Collator.h:

WebCore:

2009-07-14 Zoltan Horvath <[email protected]>

Reviewed by Darin Adler.

Change all Noncopyable inheriting visibility to public.
https://bugs.webkit.org/show_bug.cgi?id=27225

Change all Noncopyable inheriting visibility to public because
it is needed to the custom allocation framework (bug #20422).

  • bindings/js/GCController.h:
  • bindings/js/WorkerScriptController.h:
  • bindings/v8/V8DOMMap.cpp: (WebCore::):
  • bridge/runtime.h:
  • css/CSSSelector.h:
  • css/CSSSelectorList.h:
  • css/CSSStyleSelector.h:
  • dom/ClassNames.h:
  • dom/MessagePortChannel.h:
  • dom/XMLTokenizerLibxml2.cpp:
  • dom/XMLTokenizerScope.h:
  • editing/ReplaceSelectionCommand.cpp:
  • editing/SelectionController.h:
  • editing/TextIterator.cpp:
  • history/PageCache.h:
  • html/CanvasRenderingContext2D.h:
  • html/HTMLParser.h:
  • html/HTMLParserQuirks.h:
  • html/PreloadScanner.h:
  • loader/Cache.h:
  • loader/CrossOriginPreflightResultCache.h:
  • loader/FrameLoader.h:
  • loader/ProgressTracker.h:
  • loader/ThreadableLoader.h:
  • loader/appcache/ApplicationCacheGroup.h:
  • loader/archive/ArchiveResourceCollection.h:
  • loader/icon/IconDatabase.h:
  • loader/icon/IconLoader.h:
  • loader/icon/PageURLRecord.h:
  • loader/loader.h:
  • page/ContextMenuController.h:
  • page/EventHandler.h:
  • page/FrameTree.h:
  • page/Page.h:
  • page/PageGroup.h:
  • page/PageGroupLoadDeferrer.h:
  • page/mac/EventHandlerMac.mm:
  • platform/AutodrainedPool.h:
  • platform/ContextMenu.h:
  • platform/EventLoop.h:
  • platform/HostWindow.h:
  • platform/Pasteboard.h:
  • platform/PurgeableBuffer.h:
  • platform/RunLoopTimer.h:
  • platform/ThreadGlobalData.h:
  • platform/ThreadTimers.h:
  • platform/Timer.h:
  • platform/TreeShared.h:
  • platform/graphics/FontData.h:
  • platform/graphics/GlyphWidthMap.h:
  • platform/graphics/GraphicsContext.h:
  • platform/graphics/ImageBuffer.h:
  • platform/graphics/ImageSource.h:
  • platform/graphics/MediaPlayer.h:
  • platform/graphics/skia/GraphicsContextPlatformPrivate.h:
  • platform/graphics/skia/PlatformContextSkia.h:
  • platform/graphics/win/QTMovieWin.cpp:
  • platform/mac/LocalCurrentGraphicsContext.h:
  • platform/network/FormDataBuilder.h:
  • platform/network/ResourceHandleInternal.h:
  • platform/network/soup/ResourceHandleSoup.cpp:
  • platform/text/StringBuffer.h:
  • platform/text/TextCodec.h:
  • platform/win/WindowMessageBroadcaster.h:
  • rendering/CounterNode.h:
  • rendering/LayoutState.h:
  • rendering/RenderFrameSet.h:
  • rendering/RenderView.h:
  • rendering/TransformState.h:
  • svg/SVGAnimatedProperty.h:
  • svg/SynchronizableTypeWrapper.h:
  • workers/WorkerMessagingProxy.h:
  • workers/WorkerRunLoop.cpp:
  • xml/XPathExpressionNode.h:
  • xml/XPathParser.h:
  • xml/XPathPredicate.h:
  • xml/XPathStep.h:

WebKit/gtk:

2009-07-14 Zoltan Horvath <[email protected]>

Reviewed by Darin Adler.

Change all Noncopyable inheriting visibility to public.
https://bugs.webkit.org/show_bug.cgi?id=27225

Change all Noncopyable inheriting visibility to public because
it is needed to the custom allocation framework (bug #20422).

  • webkit/webkitdownload.cpp:

WebKit/win:

2009-07-14 Zoltan Horvath <[email protected]>

Reviewed by Darin Adler.

Change all Noncopyable inheriting visibility to public.
https://bugs.webkit.org/show_bug.cgi?id=27225

Change all Noncopyable inheriting visibility to public because
it is needed to the custom allocation framework (bug #20422).

  • COMEnumVariant.h:
  • WebDatabaseManager.cpp:
  • WebInspector.h:
  • WebLocalizableStrings.cpp:
  • Property svn:eol-style set to native
File size: 6.2 KB
Line 
1/*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef MessageQueue_h
31#define MessageQueue_h
32
33#include <limits>
34#include <wtf/Assertions.h>
35#include <wtf/Deque.h>
36#include <wtf/Noncopyable.h>
37#include <wtf/Threading.h>
38
39namespace WTF {
40
41 enum MessageQueueWaitResult {
42 MessageQueueTerminated, // Queue was destroyed while waiting for message.
43 MessageQueueTimeout, // Timeout was specified and it expired.
44 MessageQueueMessageReceived, // A message was successfully received and returned.
45 };
46
47 template<typename DataType>
48 class MessageQueue : public Noncopyable {
49 public:
50 MessageQueue() : m_killed(false) { }
51
52 void append(const DataType&);
53 bool appendAndCheckEmpty(const DataType&);
54 void prepend(const DataType&);
55 bool waitForMessage(DataType&);
56 template<typename Predicate>
57 MessageQueueWaitResult waitForMessageFilteredWithTimeout(DataType&, Predicate&, double absoluteTime);
58 void kill();
59
60 bool tryGetMessage(DataType&);
61 bool killed() const;
62
63 // The result of isEmpty() is only valid if no other thread is manipulating the queue at the same time.
64 bool isEmpty();
65
66 static double infiniteTime() { return std::numeric_limits<double>::max(); }
67
68 private:
69 static bool alwaysTruePredicate(DataType&) { return true; }
70
71 mutable Mutex m_mutex;
72 ThreadCondition m_condition;
73 Deque<DataType> m_queue;
74 bool m_killed;
75 };
76
77 template<typename DataType>
78 inline void MessageQueue<DataType>::append(const DataType& message)
79 {
80 MutexLocker lock(m_mutex);
81 m_queue.append(message);
82 m_condition.signal();
83 }
84
85 // Returns true if the queue was empty before the item was added.
86 template<typename DataType>
87 inline bool MessageQueue<DataType>::appendAndCheckEmpty(const DataType& message)
88 {
89 MutexLocker lock(m_mutex);
90 bool wasEmpty = m_queue.isEmpty();
91 m_queue.append(message);
92 m_condition.signal();
93 return wasEmpty;
94 }
95
96 template<typename DataType>
97 inline void MessageQueue<DataType>::prepend(const DataType& message)
98 {
99 MutexLocker lock(m_mutex);
100 m_queue.prepend(message);
101 m_condition.signal();
102 }
103
104 template<typename DataType>
105 inline bool MessageQueue<DataType>::waitForMessage(DataType& result)
106 {
107 MessageQueueWaitResult exitReason = waitForMessageFilteredWithTimeout(result, MessageQueue<DataType>::alwaysTruePredicate, infiniteTime());
108 ASSERT(exitReason == MessageQueueTerminated || exitReason == MessageQueueMessageReceived);
109 return exitReason == MessageQueueMessageReceived;
110 }
111
112 template<typename DataType>
113 template<typename Predicate>
114 inline MessageQueueWaitResult MessageQueue<DataType>::waitForMessageFilteredWithTimeout(DataType& result, Predicate& predicate, double absoluteTime)
115 {
116 MutexLocker lock(m_mutex);
117 bool timedOut = false;
118
119 DequeConstIterator<DataType> found = m_queue.end();
120 while (!m_killed && !timedOut && (found = m_queue.findIf(predicate)) == m_queue.end())
121 timedOut = !m_condition.timedWait(m_mutex, absoluteTime);
122
123 ASSERT(!timedOut || absoluteTime != infiniteTime());
124
125 if (m_killed)
126 return MessageQueueTerminated;
127
128 if (timedOut)
129 return MessageQueueTimeout;
130
131 ASSERT(found != m_queue.end());
132 result = *found;
133 m_queue.remove(found);
134 return MessageQueueMessageReceived;
135 }
136
137 template<typename DataType>
138 inline bool MessageQueue<DataType>::tryGetMessage(DataType& result)
139 {
140 MutexLocker lock(m_mutex);
141 if (m_killed)
142 return false;
143 if (m_queue.isEmpty())
144 return false;
145
146 result = m_queue.first();
147 m_queue.removeFirst();
148 return true;
149 }
150
151 template<typename DataType>
152 inline bool MessageQueue<DataType>::isEmpty()
153 {
154 MutexLocker lock(m_mutex);
155 if (m_killed)
156 return true;
157 return m_queue.isEmpty();
158 }
159
160 template<typename DataType>
161 inline void MessageQueue<DataType>::kill()
162 {
163 MutexLocker lock(m_mutex);
164 m_killed = true;
165 m_condition.broadcast();
166 }
167
168 template<typename DataType>
169 inline bool MessageQueue<DataType>::killed() const
170 {
171 MutexLocker lock(m_mutex);
172 return m_killed;
173 }
174} // namespace WTF
175
176using WTF::MessageQueue;
177// MessageQueueWaitResult enum and all its values.
178using WTF::MessageQueueWaitResult;
179using WTF::MessageQueueTerminated;
180using WTF::MessageQueueTimeout;
181using WTF::MessageQueueMessageReceived;
182
183#endif // MessageQueue_h
Note: See TracBrowser for help on using the repository browser.