Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef HTMLParserThread_h | 31 #ifndef UnsafePersistent_h |
| 32 #define HTMLParserThread_h | 32 #define UnsafePersistent_h |
| 33 | 33 |
| 34 #include <wtf/Functional.h> | 34 #include <v8.h> |
| 35 #include <wtf/MessageQueue.h> | |
| 36 #include <wtf/PassOwnPtr.h> | |
| 37 #include <wtf/PassRefPtr.h> | |
| 38 #include <wtf/Threading.h> | |
| 39 | 35 |
| 40 namespace WebCore { | 36 namespace WebCore { |
| 41 | 37 |
| 42 // FIXME:: Closure is the Chromium-name for Function<void()>, but we may want so mething else for WebCore. | 38 // An unsafe way to pass Persistent handles around. Do not use unless you know |
| 43 typedef Function<void()> Closure; | 39 // what you're doing. UnsafePersistent is only safe to use when we know that the |
| 40 // memory pointed by the it is not going away: 1) When GC cannot happen while | |
| 41 // the UnsafePersistent is alive or 2) when there is a strong Persistent keeping | |
|
haraken
2013/04/29 10:42:17
Would you add an ASSERT() that checks that GC has
marja
2013/04/29 12:02:07
Can't be a bool, because we wouldn't know when to
| |
| 42 // the memory alive while the UnsafePersistent is alive. | |
| 43 template<typename T> class UnsafePersistent { | |
| 44 public: | |
| 45 UnsafePersistent(T* value) : m_value(value) { } | |
| 44 | 46 |
| 45 class HTMLParserThread { | 47 // The end result is generally unsafe to use, see the class level comment |
| 46 public: | 48 // for when it's safe to use. |
| 47 static PassOwnPtr<HTMLParserThread> create() | 49 void makePersistentHandle(v8::Persistent<T>* handle) const |
| 48 { | 50 { |
| 49 return adoptPtr(new HTMLParserThread()); | 51 T** rawValue = reinterpret_cast<T**>(handle); |
| 52 *rawValue = m_value; | |
| 50 } | 53 } |
| 51 ~HTMLParserThread(); | |
| 52 | 54 |
| 53 static HTMLParserThread* shared(); | 55 T* value() const |
|
dcarney
2013/04/29 10:33:51
is this needed?
marja
2013/04/29 12:02:07
This is used for constructing the UniqueId.
| |
| 54 | 56 { |
| 55 bool start(); | 57 return m_value; |
| 56 void stop(); | 58 } |
| 57 | |
| 58 void postTask(const Closure&); | |
| 59 | |
| 60 ThreadIdentifier threadId() const { return m_threadID; } | |
| 61 | 59 |
| 62 private: | 60 private: |
| 63 HTMLParserThread(); | 61 T* m_value; |
| 64 | |
| 65 static void threadStart(void*); | |
| 66 void runLoop(); | |
| 67 | |
| 68 Mutex m_threadCreationMutex; | |
| 69 MessageQueue<Closure> m_queue; | |
| 70 ThreadIdentifier m_threadID; | |
| 71 }; | 62 }; |
| 72 | 63 |
| 73 } // namespace WebCore | |
| 74 | 64 |
| 75 #endif // HTMLParserThread_h | 65 |
| 66 | |
| 67 } | |
| 68 | |
| 69 #endif | |
| OLD | NEW |