diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
commit | 9364f22aed35e1a1e9d07c121510f80be3ab0502 (patch) | |
tree | d49911209b132da58d838efa852daf28d516df21 /JavaScriptCore/wtf | |
parent | 87eb0cb35bad8784770ebc807e6c982432e47107 (diff) | |
download | external_webkit-9364f22aed35e1a1e9d07c121510f80be3ab0502.zip external_webkit-9364f22aed35e1a1e9d07c121510f80be3ab0502.tar.gz external_webkit-9364f22aed35e1a1e9d07c121510f80be3ab0502.tar.bz2 |
Initial Contribution
Diffstat (limited to 'JavaScriptCore/wtf')
-rw-r--r-- | JavaScriptCore/wtf/ASCIICType.h | 47 | ||||
-rw-r--r-- | JavaScriptCore/wtf/Deque.h | 591 | ||||
-rw-r--r-- | JavaScriptCore/wtf/FastMalloc.cpp | 2 | ||||
-rw-r--r-- | JavaScriptCore/wtf/HashTable.cpp | 4 | ||||
-rw-r--r-- | JavaScriptCore/wtf/ListHashSet.h | 3 | ||||
-rw-r--r-- | JavaScriptCore/wtf/Locker.h | 47 | ||||
-rw-r--r-- | JavaScriptCore/wtf/MessageQueue.h | 124 | ||||
-rw-r--r-- | JavaScriptCore/wtf/Platform.h | 21 | ||||
-rw-r--r-- | JavaScriptCore/wtf/RefCounted.h | 2 | ||||
-rw-r--r-- | JavaScriptCore/wtf/TCPackedCache.h | 2 | ||||
-rw-r--r-- | JavaScriptCore/wtf/TCPageMap.h | 2 | ||||
-rw-r--r-- | JavaScriptCore/wtf/TCSpinLock.h | 2 | ||||
-rw-r--r-- | JavaScriptCore/wtf/TCSystemAlloc.cpp | 2 | ||||
-rw-r--r-- | JavaScriptCore/wtf/TCSystemAlloc.h | 2 | ||||
-rw-r--r-- | JavaScriptCore/wtf/Threading.h | 255 | ||||
-rw-r--r-- | JavaScriptCore/wtf/ThreadingGtk.cpp | 185 | ||||
-rw-r--r-- | JavaScriptCore/wtf/ThreadingNone.cpp | 51 | ||||
-rw-r--r-- | JavaScriptCore/wtf/ThreadingPthreads.cpp | 198 | ||||
-rw-r--r-- | JavaScriptCore/wtf/ThreadingWin.cpp | 370 | ||||
-rw-r--r-- | JavaScriptCore/wtf/Vector.h | 54 |
20 files changed, 138 insertions, 1826 deletions
diff --git a/JavaScriptCore/wtf/ASCIICType.h b/JavaScriptCore/wtf/ASCIICType.h index 7d24f0e..990c1ea 100644 --- a/JavaScriptCore/wtf/ASCIICType.h +++ b/JavaScriptCore/wtf/ASCIICType.h @@ -50,12 +50,13 @@ namespace WTF { #endif inline bool isASCIIAlpha(int c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; } - inline bool isASCIIAlphanumeric(char c) { return c >= '0' && c <= '9' || (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; } - inline bool isASCIIAlphanumeric(unsigned short c) { return c >= '0' && c <= '9' || (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; } +// ANDROID: extra parentheses around expressions to suppress warnings + inline bool isASCIIAlphanumeric(char c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); } + inline bool isASCIIAlphanumeric(unsigned short c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); } #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED) - inline bool isASCIIAlphanumeric(wchar_t c) { return c >= '0' && c <= '9' || (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; } + inline bool isASCIIAlphanumeric(wchar_t c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); } #endif - inline bool isASCIIAlphanumeric(int c) { return c >= '0' && c <= '9' || (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; } + inline bool isASCIIAlphanumeric(int c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); } inline bool isASCIIDigit(char c) { return (c >= '0') & (c <= '9'); } inline bool isASCIIDigit(unsigned short c) { return (c >= '0') & (c <= '9'); } @@ -64,12 +65,12 @@ namespace WTF { #endif inline bool isASCIIDigit(int c) { return (c >= '0') & (c <= '9'); } - inline bool isASCIIHexDigit(char c) { return c >= '0' && c <= '9' || (c | 0x20) >= 'a' && (c | 0x20) <= 'f'; } - inline bool isASCIIHexDigit(unsigned short c) { return c >= '0' && c <= '9' || (c | 0x20) >= 'a' && (c | 0x20) <= 'f'; } + inline bool isASCIIHexDigit(char c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); } + inline bool isASCIIHexDigit(unsigned short c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); } #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED) - inline bool isASCIIHexDigit(wchar_t c) { return c >= '0' && c <= '9' || (c | 0x20) >= 'a' && (c | 0x20) <= 'f'; } + inline bool isASCIIHexDigit(wchar_t c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); } #endif - inline bool isASCIIHexDigit(int c) { return c >= '0' && c <= '9' || (c | 0x20) >= 'a' && (c | 0x20) <= 'f'; } + inline bool isASCIIHexDigit(int c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); } inline bool isASCIILower(char c) { return c >= 'a' && c <= 'z'; } inline bool isASCIILower(unsigned short c) { return c >= 'a' && c <= 'z'; } @@ -86,18 +87,19 @@ namespace WTF { inline bool isASCIIUpper(int c) { return c >= 'A' && c <= 'Z'; } /* - Statistics from a run of Apple's page load test for callers of isASCIISpace: - - character count - --------- ----- - non-spaces 689383 - 20 space 294720 - 0A \n 89059 - 09 \t 28320 - 0D \r 0 - 0C \f 0 - 0B \v 0 + Statistics from a run of the PLT on the usage of isASCIISpace: + Hex Name Count + --- ---- ----- + ALL OTHER VALUES 689383 + x20 SPACE 294720 + x0A NEWLINE 89059 + x09 TAB 28320 + x0D CARRIAGE RETURN 0 + x0C FORMFEED 0 + x0B VERTICAL TAB 0 + */ + inline bool isASCIISpace(char c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); } inline bool isASCIISpace(unsigned short c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); } #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED) @@ -119,13 +121,6 @@ namespace WTF { #endif inline int toASCIIUpper(int c) { return static_cast<int>(c & ~((c >= 'a' && c <= 'z') << 5)); } - inline int toASCIIHexValue(char c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; } - inline int toASCIIHexValue(unsigned short c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; } -#if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED) - inline int toASCIIHexValue(wchar_t c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; } -#endif - inline int toASCIIHexValue(int c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; } - } #endif diff --git a/JavaScriptCore/wtf/Deque.h b/JavaScriptCore/wtf/Deque.h index f8cf4fe..c09ef42 100644 --- a/JavaScriptCore/wtf/Deque.h +++ b/JavaScriptCore/wtf/Deque.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2007 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -25,556 +25,99 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #ifndef WTF_Deque_h #define WTF_Deque_h -// FIXME: Could move what Vector and Deque share into a separate file. -// Deque doesn't actually use Vector. - -#include "Vector.h" +#include <wtf/Assertions.h> +#include <wtf/Noncopyable.h> namespace WTF { - template<typename T> class DequeIteratorBase; - template<typename T> class DequeIterator; - template<typename T> class DequeConstIterator; - template<typename T> class DequeReverseIterator; - template<typename T> class DequeConstReverseIterator; - - template<typename T> - class Deque { - public: - typedef DequeIterator<T> iterator; - typedef DequeConstIterator<T> const_iterator; - typedef DequeReverseIterator<T> reverse_iterator; - typedef DequeConstReverseIterator<T> const_reverse_iterator; - - Deque(); - Deque(const Deque<T>&); - Deque& operator=(const Deque<T>&); - ~Deque(); - - void swap(Deque<T>&); - - size_t size() const { return m_start <= m_end ? m_end - m_start : m_end + m_buffer.capacity() - m_start; } - bool isEmpty() const { return m_start == m_end; } - - iterator begin() { return iterator(this, m_start); } - iterator end() { return iterator(this, m_end); } - const_iterator begin() const { return const_iterator(this, m_start); } - const_iterator end() const { return const_iterator(this, m_end); } - reverse_iterator rbegin() { return reverse_iterator(this, m_end); } - reverse_iterator rend() { return reverse_iterator(this, m_start); } - const_reverse_iterator rbegin() const { return const_reverse_iterator(this, m_end); } - const_reverse_iterator rend() const { return const_reverse_iterator(this, m_start); } - - T& first() { ASSERT(m_start != m_end); return m_buffer.buffer()[m_start]; } - const T& first() const { ASSERT(m_start != m_end); return m_buffer.buffer()[m_start]; } - - template<typename U> void append(const U&); - template<typename U> void prepend(const U&); - void removeFirst(); - - void clear(); - - private: - friend class DequeIteratorBase<T>; - - typedef VectorBuffer<T, 0> Buffer; - typedef VectorTypeOperations<T> TypeOperations; - typedef DequeIteratorBase<T> IteratorBase; - - void invalidateIterators(); - void destroyAll(); - void checkValidity() const; - void checkIndexValidity(size_t) const; - void expandCapacityIfNeeded(); - void expandCapacity(); - - size_t m_start; - size_t m_end; - Buffer m_buffer; -#ifndef NDEBUG - mutable IteratorBase* m_iterators; -#endif - }; - - template<typename T> - class DequeIteratorBase { - private: - typedef DequeIteratorBase<T> Base; - - protected: - DequeIteratorBase(); - DequeIteratorBase(const Deque<T>*, size_t); - DequeIteratorBase(const Base&); - Base& operator=(const Base&); - ~DequeIteratorBase(); - - void assign(const Base& other) { *this = other; } - - void increment(); - void decrement(); - - T* before() const; - T* after() const; - - bool isEqual(const Base&) const; - - private: - void addToIteratorsList(); - void checkValidity() const; - void checkValidity(const Base&) const; - - Deque<T>* m_deque; - size_t m_index; - - friend class Deque<T>; - -#ifndef NDEBUG - mutable DequeIteratorBase* m_next; - mutable DequeIteratorBase* m_previous; -#endif - }; - template<typename T> - class DequeIterator : public DequeIteratorBase<T> { - private: - typedef DequeIteratorBase<T> Base; - typedef DequeIterator<T> Iterator; - + class DequeNode { public: - DequeIterator(Deque<T>* deque, size_t index) : Base(deque, index) { } - - DequeIterator(const Iterator& other) : Base(other) { } - DequeIterator& operator=(const Iterator& other) { Base::assign(other); return *this; } - - T& operator*() const { return *Base::after(); } - T* operator->() const { return Base::after(); } + DequeNode(const T& item) : m_value(item), m_next(0) { } - bool operator==(const Iterator& other) const { return Base::isEqual(other); } - bool operator!=(const Iterator& other) const { return !Base::isEqual(other); } - - Iterator& operator++() { Base::increment(); return *this; } - // postfix ++ intentionally omitted - Iterator& operator--() { Base::decrement(); return *this; } - // postfix -- intentionally omitted + T m_value; + DequeNode* m_next; }; template<typename T> - class DequeConstIterator : public DequeIteratorBase<T> { - private: - typedef DequeIteratorBase<T> Base; - typedef DequeConstIterator<T> Iterator; - typedef DequeIterator<T> NonConstIterator; - + class Deque : Noncopyable { public: - DequeConstIterator(const Deque<T>* deque, size_t index) : Base(deque, index) { } - - DequeConstIterator(const Iterator& other) : Base(other) { } - DequeConstIterator(const NonConstIterator& other) : Base(other) { } - DequeConstIterator& operator=(const Iterator& other) { Base::assign(other); return *this; } - DequeConstIterator& operator=(const NonConstIterator& other) { Base::assign(other); return *this; } - - const T& operator*() const { return *Base::after(); } - const T* operator->() const { return Base::after(); } - - bool operator==(const Iterator& other) const { return Base::isEqual(other); } - bool operator!=(const Iterator& other) const { return !Base::isEqual(other); } - - Iterator& operator++() { Base::increment(); return *this; } - // postfix ++ intentionally omitted - Iterator& operator--() { Base::decrement(); return *this; } - // postfix -- intentionally omitted - }; - - template<typename T> - class DequeReverseIterator : public DequeIteratorBase<T> { - private: - typedef DequeIteratorBase<T> Base; - typedef DequeReverseIterator<T> Iterator; - - public: - DequeReverseIterator(const Deque<T>* deque, size_t index) : Base(deque, index) { } - - DequeReverseIterator(const Iterator& other) : Base(other) { } - DequeReverseIterator& operator=(const Iterator& other) { Base::assign(other); return *this; } - - T& operator*() const { return *Base::before(); } - T* operator->() const { return Base::before(); } - - bool operator==(const Iterator& other) const { return Base::isEqual(other); } - bool operator!=(const Iterator& other) const { return !Base::isEqual(other); } - - Iterator& operator++() { Base::decrement(); return *this; } - // postfix ++ intentionally omitted - Iterator& operator--() { Base::increment(); return *this; } - // postfix -- intentionally omitted - }; - - template<typename T> - class DequeConstReverseIterator : public DequeIteratorBase<T> { - private: - typedef DequeIteratorBase<T> Base; - typedef DequeConstReverseIterator<T> Iterator; - typedef DequeReverseIterator<T> NonConstIterator; - - public: - DequeConstReverseIterator(const Deque<T>* deque, size_t index) : Base(deque, index) { } - - DequeConstReverseIterator(const Iterator& other) : Base(other) { } - DequeConstReverseIterator(const NonConstIterator& other) : Base(other) { } - DequeConstReverseIterator& operator=(const Iterator& other) { Base::assign(other); return *this; } - DequeConstReverseIterator& operator=(const NonConstIterator& other) { Base::assign(other); return *this; } - - const T& operator*() const { return *Base::before(); } - const T* operator->() const { return Base::before(); } - - bool operator==(const Iterator& other) const { return Base::isEqual(other); } - bool operator!=(const Iterator& other) const { return !Base::isEqual(other); } - - Iterator& operator++() { Base::decrement(); return *this; } - // postfix ++ intentionally omitted - Iterator& operator--() { Base::increment(); return *this; } - // postfix -- intentionally omitted - }; - -#ifdef NDEBUG - template<typename T> inline void Deque<T>::checkValidity() const { } - template<typename T> inline void Deque<T>::checkIndexValidity(size_t) const { } - template<typename T> inline void Deque<T>::invalidateIterators() { } -#else - template<typename T> - void Deque<T>::checkValidity() const - { - if (!m_buffer.capacity()) { - ASSERT(!m_start); - ASSERT(!m_end); - } else { - ASSERT(m_start < m_buffer.capacity()); - ASSERT(m_end < m_buffer.capacity()); + Deque() + : m_size(0) + , m_first(0) + , m_last(0) + { } - } - template<typename T> - void Deque<T>::checkIndexValidity(size_t index) const - { - ASSERT(index <= m_buffer.capacity()); - if (m_start <= m_end) { - ASSERT(index >= m_start); - ASSERT(index <= m_end); - } else { - ASSERT(index >= m_start || index <= m_end); + ~Deque() + { + clear(); } - } - template<typename T> - void Deque<T>::invalidateIterators() - { - IteratorBase* next; - for (IteratorBase* p = m_iterators; p; p = next) { - next = p->m_next; - p->m_deque = 0; - p->m_next = 0; - p->m_previous = 0; + size_t size() const { return m_size; } + bool isEmpty() const { return !size(); } + + void append(const T& item) + { + DequeNode<T>* newNode = new DequeNode<T>(item); + if (m_last) + m_last->m_next = newNode; + m_last = newNode; + if (!m_first) + m_first = newNode; + ++m_size; } - m_iterators = 0; - } -#endif - template<typename T> - inline Deque<T>::Deque() - : m_start(0) - , m_end(0) -#ifndef NDEBUG - , m_iterators(0) -#endif - { - checkValidity(); - } - - template<typename T> - inline Deque<T>::Deque(const Deque<T>& other) - : m_start(other.m_start) - , m_end(other.m_end) - , m_buffer(other.m_buffer.capacity()) -#ifndef NDEBUG - , m_iterators(0) -#endif - { - const T* otherBuffer = other.m_buffer.buffer(); - if (m_start <= m_end) - TypeOperations::uninitializedCopy(otherBuffer + m_start, otherBuffer + m_end, m_buffer.buffer() + m_start); - else { - TypeOperations::uninitializedCopy(otherBuffer, otherBuffer + m_end, m_buffer.buffer()); - TypeOperations::uninitializedCopy(otherBuffer + m_start, otherBuffer + m_buffer.capacity(), m_buffer.buffer() + m_start); - } - } - - template<typename T> - inline Deque<T>& Deque<T>::operator=(const Deque<T>& other) - { - Deque<T> copy(other); - swap(copy); - return *this; - } - - template<typename T> - inline void Deque<T>::destroyAll() - { - if (m_start <= m_end) - TypeOperations::destruct(m_buffer.buffer() + m_start, m_buffer.buffer() + m_end); - else { - TypeOperations::destruct(m_buffer.buffer(), m_buffer.buffer() + m_end); - TypeOperations::destruct(m_buffer.buffer() + m_start, m_buffer.buffer() + m_buffer.capacity()); - } - } - - template<typename T> - inline Deque<T>::~Deque() - { - checkValidity(); - invalidateIterators(); - destroyAll(); - } - - template <typename T> - inline void Deque<T>::swap(Deque<T>& other) - { - checkValidity(); - other.checkValidity(); - invalidateIterators(); - std::swap(m_start, other.m_start); - std::swap(m_end, other.m_end); - m_buffer.swap(other.m_buffer); - checkValidity(); - other.checkValidity(); - } - - template <typename T> - inline void Deque<T>::clear() - { - checkValidity(); - invalidateIterators(); - destroyAll(); - m_start = 0; - m_end = 0; - checkValidity(); - } - - template<typename T> - inline void Deque<T>::expandCapacityIfNeeded() - { - if (m_start) { - if (m_end + 1 != m_start) - return; - } else if (m_end) { - if (m_end != m_buffer.capacity() - 1) - return; - } else if (m_buffer.capacity()) - return; - - expandCapacity(); - } - - template<typename T> - void Deque<T>::expandCapacity() - { - checkValidity(); - size_t oldCapacity = m_buffer.capacity(); - size_t newCapacity = max(static_cast<size_t>(16), oldCapacity + oldCapacity / 4 + 1); - T* oldBuffer = m_buffer.buffer(); - m_buffer.allocateBuffer(newCapacity); - if (m_start <= m_end) - TypeOperations::move(oldBuffer + m_start, oldBuffer + m_end, m_buffer.buffer() + m_start); - else { - TypeOperations::move(oldBuffer, oldBuffer + m_end, m_buffer.buffer()); - size_t newStart = newCapacity - (oldCapacity - m_start); - TypeOperations::move(oldBuffer + m_start, oldBuffer + oldCapacity, m_buffer.buffer() + newStart); - m_start = newStart; + void prepend(const T& item) + { + DequeNode<T>* newNode = new DequeNode<T>(item); + newNode->m_next = m_first; + m_first = newNode; + if (!m_last) + m_last = newNode; + ++m_size; } - m_buffer.deallocateBuffer(oldBuffer); - checkValidity(); - } - template<typename T> template<typename U> - inline void Deque<T>::append(const U& value) - { - checkValidity(); - expandCapacityIfNeeded(); - new (&m_buffer.buffer()[m_end]) T(value); - if (m_end == m_buffer.capacity() - 1) - m_end = 0; - else - ++m_end; - checkValidity(); - } - - template<typename T> template<typename U> - inline void Deque<T>::prepend(const U& value) - { - checkValidity(); - expandCapacityIfNeeded(); - if (!m_start) - m_start = m_buffer.capacity() - 1; - else - --m_start; - new (&m_buffer.buffer()[m_start]) T(value); - checkValidity(); - } - - template<typename T> - inline void Deque<T>::removeFirst() - { - checkValidity(); - invalidateIterators(); - ASSERT(!isEmpty()); - TypeOperations::destruct(&m_buffer.buffer()[m_start], &m_buffer.buffer()[m_start + 1]); - if (m_start == m_buffer.capacity() - 1) - m_start = 0; - else - ++m_start; - checkValidity(); - } - -#ifdef NDEBUG - template<typename T> inline void DequeIteratorBase<T>::checkValidity() const { } - template<typename T> inline void DequeIteratorBase<T>::checkValidity(const DequeIteratorBase<T>&) const { } - template<typename T> inline void DequeIteratorBase<T>::addToIteratorsList() { } -#else - template<typename T> - void DequeIteratorBase<T>::checkValidity() const - { - ASSERT(m_deque); - m_deque->checkIndexValidity(m_index); - } - - template<typename T> - void DequeIteratorBase<T>::checkValidity(const Base& other) const - { - checkValidity(); - other.checkValidity(); - ASSERT(m_deque == other.m_deque); - } - - template<typename T> - void DequeIteratorBase<T>::addToIteratorsList() - { - if (!m_deque) - m_next = 0; - else { - m_next = m_deque->m_iterators; - m_deque->m_iterators = this; - if (m_next) - m_next->m_previous = this; + T& first() { ASSERT(m_first); return m_first->m_value; } + const T& first() const { ASSERT(m_first); return m_first->m_value; } + T& last() { ASSERT(m_last); return m_last->m_value; } + const T& last() const { ASSERT(m_last); return m_last->m_value; } + + void removeFirst() + { + ASSERT(m_first); + if (DequeNode<T>* n = m_first) { + m_first = m_first->m_next; + if (n == m_last) + m_last = 0; + + m_size--; + delete n; + } } - m_previous = 0; - } -#endif - - template<typename T> - inline DequeIteratorBase<T>::DequeIteratorBase() - : m_deque(0) - { - } - - template<typename T> - inline DequeIteratorBase<T>::DequeIteratorBase(const Deque<T>* deque, size_t index) - : m_deque(const_cast<Deque<T>*>(deque)) - , m_index(index) - { - addToIteratorsList(); - checkValidity(); - } - template<typename T> - inline DequeIteratorBase<T>::DequeIteratorBase(const Base& other) - : m_deque(other.m_deque) - , m_index(other.m_index) - { - addToIteratorsList(); - checkValidity(); - } - - template<typename T> - inline DequeIteratorBase<T>::~DequeIteratorBase() - { -#ifndef NDEBUG - // Delete iterator from doubly-linked list of iterators. - if (!m_deque) { - ASSERT(!m_next); - ASSERT(!m_previous); - } else { - if (m_next) { - ASSERT(m_next->m_previous == this); - m_next->m_previous = m_previous; - } - if (m_previous) { - ASSERT(m_deque->m_iterators != this); - ASSERT(m_previous->m_next == this); - m_previous->m_next = m_next; - } else { - ASSERT(m_deque->m_iterators == this); - m_deque->m_iterators = m_next; + void clear() + { + DequeNode<T>* n = m_first; + m_first = 0; + m_last = 0; + m_size = 0; + while (n) { + DequeNode<T>* next = n->m_next; + delete n; + n = next; } } - m_deque = 0; - m_next = 0; - m_previous = 0; -#endif - } - - template<typename T> - inline bool DequeIteratorBase<T>::isEqual(const Base& other) const - { - checkValidity(other); - return m_index == other.m_index; - } - - template<typename T> - inline void DequeIteratorBase<T>::increment() - { - checkValidity(); - ASSERT(m_index != m_deque->m_end); - ASSERT(m_deque->m_buffer.capacity()); - if (m_index == m_deque->m_buffer.capacity() - 1) - m_index = 0; - else - ++m_index; - checkValidity(); - } - - template<typename T> - inline void DequeIteratorBase<T>::decrement() - { - checkValidity(); - ASSERT(m_index != m_deque->m_start); - ASSERT(m_deque->m_buffer.capacity()); - if (!m_index) - m_index = m_deque->m_buffer.capacity() - 1; - else - --m_index; - checkValidity(); - } - template<typename T> - inline T* DequeIteratorBase<T>::after() const - { - checkValidity(); - ASSERT(m_index != m_deque->m_end); - return &m_deque->m_buffer.buffer()[m_index]; - } + private: + size_t m_size; + DequeNode<T>* m_first; + DequeNode<T>* m_last; - template<typename T> - inline T* DequeIteratorBase<T>::before() const - { - checkValidity(); - ASSERT(m_index != m_deque->m_start); - if (!m_index) - return &m_deque->m_buffer.buffer()[m_deque->m_buffer.capacity() - 1]; - return &m_deque->m_buffer.buffer()[m_index - 1]; - } + }; } // namespace WTF diff --git a/JavaScriptCore/wtf/FastMalloc.cpp b/JavaScriptCore/wtf/FastMalloc.cpp index b2dab4f..69df95e 100644 --- a/JavaScriptCore/wtf/FastMalloc.cpp +++ b/JavaScriptCore/wtf/FastMalloc.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2005, 2007, Google Inc. +// Copyright (c) 2005, 2007, The Android Open Source Project // All rights reserved. // // Redistribution and use in source and binary forms, with or without diff --git a/JavaScriptCore/wtf/HashTable.cpp b/JavaScriptCore/wtf/HashTable.cpp index f1f2a4f..ba45aee 100644 --- a/JavaScriptCore/wtf/HashTable.cpp +++ b/JavaScriptCore/wtf/HashTable.cpp @@ -1,5 +1,7 @@ /* - Copyright (C) 2005 Apple Inc. All rights reserved. + This file is part of the KDE libraries + + Copyright (C) 2005 Apple Computer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public diff --git a/JavaScriptCore/wtf/ListHashSet.h b/JavaScriptCore/wtf/ListHashSet.h index 5aa13cd..3172943 100644 --- a/JavaScriptCore/wtf/ListHashSet.h +++ b/JavaScriptCore/wtf/ListHashSet.h @@ -1,6 +1,6 @@ // -*- mode: c++; c-basic-offset: 4 -*- /* - * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -381,6 +381,7 @@ namespace WTF { std::swap(m_head, other.m_head); std::swap(m_tail, other.m_tail); m_allocator.swap(other.m_allocator); + return *this; } template<typename T, typename U> diff --git a/JavaScriptCore/wtf/Locker.h b/JavaScriptCore/wtf/Locker.h deleted file mode 100644 index 9feec1f..0000000 --- a/JavaScriptCore/wtf/Locker.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2008 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef Locker_h -#define Locker_h - -#include <wtf/Noncopyable.h> - -namespace WTF { - -template <typename T> class Locker : Noncopyable { -public: - Locker(T& lockable) : m_lockable(lockable) { m_lockable.lock(); } - ~Locker() { m_lockable.unlock(); } -private: - T& m_lockable; -}; - -} - -using WTF::Locker; - -#endif diff --git a/JavaScriptCore/wtf/MessageQueue.h b/JavaScriptCore/wtf/MessageQueue.h deleted file mode 100644 index c13b590..0000000 --- a/JavaScriptCore/wtf/MessageQueue.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2008 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef MessageQueue_h -#define MessageQueue_h - -#include <wtf/Assertions.h> -#include <wtf/Deque.h> -#include <wtf/Noncopyable.h> -#include <wtf/Threading.h> - -namespace WTF { - - template<typename DataType> - class MessageQueue : Noncopyable { - public: - MessageQueue() : m_killed(false) {} - - void append(const DataType&); - void prepend(const DataType&); - bool waitForMessage(DataType&); - bool tryGetMessage(DataType&); - void kill(); - bool killed() const; - - private: - mutable Mutex m_mutex; - ThreadCondition m_condition; - Deque<DataType> m_queue; - bool m_killed; - }; - - template<typename DataType> - inline void MessageQueue<DataType>::append(const DataType& message) - { - MutexLocker lock(m_mutex); - m_queue.append(message); - m_condition.signal(); - } - - template<typename DataType> - inline void MessageQueue<DataType>::prepend(const DataType& message) - { - MutexLocker lock(m_mutex); - m_queue.prepend(message); - m_condition.signal(); - } - - template<typename DataType> - inline bool MessageQueue<DataType>::waitForMessage(DataType& result) - { - MutexLocker lock(m_mutex); - if (m_killed) - return false; - - if (m_queue.isEmpty()) - m_condition.wait(m_mutex); - if (m_killed) - return false; - - ASSERT(!m_queue.isEmpty()); - result = m_queue.first(); - m_queue.removeFirst(); - return true; - } - - template<typename DataType> - inline bool MessageQueue<DataType>::tryGetMessage(DataType& result) - { - MutexLocker lock(m_mutex); - if (m_killed) - return false; - if (m_queue.isEmpty()) - return false; - - result = m_queue.first(); - m_queue.removeFirst(); - return true; - } - - template<typename DataType> - inline void MessageQueue<DataType>::kill() - { - MutexLocker lock(m_mutex); - m_killed = true; - m_condition.broadcast(); - } - - template<typename DataType> - inline bool MessageQueue<DataType>::killed() const - { - MutexLocker lock(m_mutex); - return m_killed; - } -} - -using WTF::MessageQueue; - -#endif // MessageQueue_h diff --git a/JavaScriptCore/wtf/Platform.h b/JavaScriptCore/wtf/Platform.h index 5396f8e..655361b 100644 --- a/JavaScriptCore/wtf/Platform.h +++ b/JavaScriptCore/wtf/Platform.h @@ -112,9 +112,6 @@ #define WTF_PLATFORM_CAIRO 1 #endif -#if PLATFORM(WIN)&& PLATFORM(CG) -#define WTF_USE_SAFARI_THEME 1 -#endif #ifdef __S60__ // we are cross-compiling, it is not really windows @@ -125,6 +122,22 @@ #define WTF_PLATFORM_SYMBIAN 1 #endif +#ifdef ANDROID +//due to pthread code in collector.cpp, we need PLATFORM(DARWIN) +//#undef WTF_PLATFORM_DARWIN +#undef WTF_PLATFORM_MAC +#undef WTF_PLATFORM_WIN_OS +#undef WTF_PLATFORM_WIN +#undef WTF_PLATFORM_CG +#undef WTF_PLATFORM_CI +#undef WTF_PLATFORM_CAIRO + +#define WTF_PLATFORM_SGL 1 +#define WTF_PLATFORM_UNIX 1 + +#define USE_SYSTEM_MALLOC 1 +#endif // ANDROID + /* CPU */ /* PLATFORM(PPC) */ @@ -152,8 +165,10 @@ #if defined(__ARMEB__) #define WTF_PLATFORM_BIG_ENDIAN 1 #elif !defined(__ARM_EABI__) && !defined(__ARMEB__) +#if !defined(ANDROID) || !defined(__VFP_FP__) #define WTF_PLATFORM_MIDDLE_ENDIAN 1 #endif +#endif #if !defined(__ARM_EABI__) #define WTF_PLATFORM_FORCE_PACK 1 #endif diff --git a/JavaScriptCore/wtf/RefCounted.h b/JavaScriptCore/wtf/RefCounted.h index 8f05b0f..dc93b11 100644 --- a/JavaScriptCore/wtf/RefCounted.h +++ b/JavaScriptCore/wtf/RefCounted.h @@ -28,7 +28,7 @@ namespace WTF { template<class T> class RefCounted : Noncopyable { public: - RefCounted(int initialRefCount = 1) + RefCounted(int initialRefCount = 0) : m_refCount(initialRefCount) #ifndef NDEBUG , m_deletionHasBegun(false) diff --git a/JavaScriptCore/wtf/TCPackedCache.h b/JavaScriptCore/wtf/TCPackedCache.h index 0464f8f..a33cb77 100644 --- a/JavaScriptCore/wtf/TCPackedCache.h +++ b/JavaScriptCore/wtf/TCPackedCache.h @@ -1,4 +1,4 @@ -// Copyright (c) 2007, Google Inc. +// Copyright (c) 2007, The Android Open Source Project // All rights reserved. // // Redistribution and use in source and binary forms, with or without diff --git a/JavaScriptCore/wtf/TCPageMap.h b/JavaScriptCore/wtf/TCPageMap.h index 21a87e4..3e6b80e 100644 --- a/JavaScriptCore/wtf/TCPageMap.h +++ b/JavaScriptCore/wtf/TCPageMap.h @@ -1,4 +1,4 @@ -// Copyright (c) 2005, Google Inc. +// Copyright (c) 2005, The Android Open Source Project // All rights reserved. // // Redistribution and use in source and binary forms, with or without diff --git a/JavaScriptCore/wtf/TCSpinLock.h b/JavaScriptCore/wtf/TCSpinLock.h index 2bfc14b..2bfd090 100644 --- a/JavaScriptCore/wtf/TCSpinLock.h +++ b/JavaScriptCore/wtf/TCSpinLock.h @@ -1,4 +1,4 @@ -// Copyright (c) 2005, 2006, Google Inc. +// Copyright (c) 2005, 2006, The Android Open Source Project // All rights reserved. // // Redistribution and use in source and binary forms, with or without diff --git a/JavaScriptCore/wtf/TCSystemAlloc.cpp b/JavaScriptCore/wtf/TCSystemAlloc.cpp index e2ac6ec..73f9341 100644 --- a/JavaScriptCore/wtf/TCSystemAlloc.cpp +++ b/JavaScriptCore/wtf/TCSystemAlloc.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2005, 2007, Google Inc. +// Copyright (c) 2005, 2007, The Android Open Source Project // All rights reserved. // // Redistribution and use in source and binary forms, with or without diff --git a/JavaScriptCore/wtf/TCSystemAlloc.h b/JavaScriptCore/wtf/TCSystemAlloc.h index a4d14ed..d9d4a2b 100644 --- a/JavaScriptCore/wtf/TCSystemAlloc.h +++ b/JavaScriptCore/wtf/TCSystemAlloc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2005, 2007, Google Inc. +// Copyright (c) 2005, 2007, The Android Open Source Project // All rights reserved. // // Redistribution and use in source and binary forms, with or without diff --git a/JavaScriptCore/wtf/Threading.h b/JavaScriptCore/wtf/Threading.h deleted file mode 100644 index 1cb5272..0000000 --- a/JavaScriptCore/wtf/Threading.h +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. - * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * - * Note: The implementations of InterlockedIncrement and InterlockedDecrement are based - * on atomic_increment and atomic_exchange_and_add from the Boost C++ Library. The license - * is virtually identical to the Apple license above but is included here for completeness. - * - * Boost Software License - Version 1.0 - August 17th, 2003 - * - * Permission is hereby granted, free of charge, to any person or organization - * obtaining a copy of the software and accompanying documentation covered by - * this license (the "Software") to use, reproduce, display, distribute, - * execute, and transmit the Software, and to prepare derivative works of the - * Software, and to permit third-parties to whom the Software is furnished to - * do so, all subject to the following: - * - * The copyright notices in the Software and this entire statement, including - * the above license grant, this restriction and the following disclaimer, - * must be included in all copies of the Software, in whole or in part, and - * all derivative works of the Software, unless such copies or derivative - * works are solely in the form of machine-executable object code generated by - * a source language processor. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT - * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE - * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifndef Threading_h -#define Threading_h - -#include <wtf/Assertions.h> -#include <wtf/Locker.h> -#include <wtf/Noncopyable.h> - -#if PLATFORM(WIN_OS) -#include <windows.h> -#elif PLATFORM(DARWIN) -#include <libkern/OSAtomic.h> -#elif COMPILER(GCC) -#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) -#include <ext/atomicity.h> -#else -#include <bits/atomicity.h> -#endif -#endif - -#if USE(PTHREADS) -#include <pthread.h> -#endif - -#if PLATFORM(GTK) -typedef struct _GMutex GMutex; -typedef struct _GCond GCond; -#endif - -#if PLATFORM(QT) -class QMutex; -class QWaitCondition; -#endif - -#include <stdint.h> - -namespace WTF { - -typedef uint32_t ThreadIdentifier; -typedef void* (*ThreadFunction)(void* argument); - -// Returns 0 if thread creation failed -ThreadIdentifier createThread(ThreadFunction, void*); -ThreadIdentifier currentThread(); -int waitForThreadCompletion(ThreadIdentifier, void**); -void detachThread(ThreadIdentifier); - -#if USE(PTHREADS) -typedef pthread_mutex_t PlatformMutex; -typedef pthread_cond_t PlatformCondition; -#elif PLATFORM(GTK) -typedef GMutex* PlatformMutex; -typedef GCond* PlatformCondition; -#elif PLATFORM(QT) -typedef QMutex* PlatformMutex; -typedef QWaitCondition* PlatformCondition; -#elif PLATFORM(WIN_OS) -struct PlatformMutex { - CRITICAL_SECTION m_internalMutex; - size_t m_recursionCount; -}; -struct PlatformCondition { - size_t m_timedOut; - size_t m_blocked; - size_t m_waitingForRemoval; - HANDLE m_gate; - HANDLE m_queue; - HANDLE m_mutex; -}; -#else -typedef void* PlatformMutex; -typedef void* PlatformCondition; -#endif - -class Mutex : Noncopyable { -public: - Mutex(); - ~Mutex(); - - void lock(); - bool tryLock(); - void unlock(); - -public: - PlatformMutex& impl() { return m_mutex; } -private: - PlatformMutex m_mutex; -}; - -typedef Locker<Mutex> MutexLocker; - -class ThreadCondition : Noncopyable { -public: - ThreadCondition(); - ~ThreadCondition(); - - void wait(Mutex& mutex); - void signal(); - void broadcast(); - -private: - PlatformCondition m_condition; -}; - -#if PLATFORM(WIN_OS) && !COMPILER(MSVC7) -#define WTF_USE_LOCKFREE_THREADSAFESHARED 1 - -inline void atomicIncrement(int volatile* addend) { InterlockedIncrement(reinterpret_cast<long volatile*>(addend)); } -inline int atomicDecrement(int volatile* addend) { return InterlockedDecrement(reinterpret_cast<long volatile*>(addend)); } - -#elif PLATFORM(DARWIN) -#define WTF_USE_LOCKFREE_THREADSAFESHARED 1 - -inline void atomicIncrement(int volatile* addend) { OSAtomicIncrement32Barrier(const_cast<int*>(addend)); } -inline int atomicDecrement(int volatile* addend) { return OSAtomicDecrement32Barrier(const_cast<int*>(addend)); } - -#elif COMPILER(GCC) -#define WTF_USE_LOCKFREE_THREADSAFESHARED 1 - -inline void atomicIncrement(int volatile* addend) { __gnu_cxx::__atomic_add(addend, 1); } -inline int atomicDecrement(int volatile* addend) { return __gnu_cxx::__exchange_and_add(addend, -1) - 1; } - -#endif - -template<class T> class ThreadSafeShared : Noncopyable { -public: - ThreadSafeShared() - : m_refCount(0) - { - } - - void ref() - { -#if USE(LOCKFREE_THREADSAFESHARED) - atomicIncrement(&m_refCount); -#else - MutexLocker locker(m_mutex); - ++m_refCount; -#endif - } - - void deref() - { -#if USE(LOCKFREE_THREADSAFESHARED) - if (atomicDecrement(&m_refCount) <= 0) -#else - { - MutexLocker locker(m_mutex); - --m_refCount; - } - if (m_refCount <= 0) -#endif - delete static_cast<T*>(this); - } - - bool hasOneRef() - { - return refCount() == 1; - } - - int refCount() const - { -#if !USE(LOCKFREE_THREADSAFESHARED) - MutexLocker locker(m_mutex); -#endif - return static_cast<int const volatile &>(m_refCount); - } - -private: - int m_refCount; -#if !USE(LOCKFREE_THREADSAFESHARED) - mutable Mutex m_mutex; -#endif -}; - -void initializeThreading(); - -#if !PLATFORM(GTK) -inline void initializeThreading() -{ -} -#endif - -} // namespace WTF - -using WTF::Mutex; -using WTF::MutexLocker; -using WTF::ThreadCondition; -using WTF::ThreadIdentifier; -using WTF::ThreadSafeShared; - -using WTF::createThread; -using WTF::currentThread; -using WTF::detachThread; -using WTF::initializeThreading; -using WTF::waitForThreadCompletion; - -#endif // Threading_h diff --git a/JavaScriptCore/wtf/ThreadingGtk.cpp b/JavaScriptCore/wtf/ThreadingGtk.cpp deleted file mode 100644 index a5de7a2..0000000 --- a/JavaScriptCore/wtf/ThreadingGtk.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. - * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "Threading.h" - -#include "HashMap.h" - -#include <glib.h> - -namespace WTF { - -void initializeThreading() -{ - if (!g_thread_supported()) - g_thread_init(NULL); - ASSERT(g_thread_supported()); -} - -static Mutex& threadMapMutex() -{ - static Mutex mutex; - return mutex; -} - -static HashMap<ThreadIdentifier, GThread*>& threadMap() -{ - static HashMap<ThreadIdentifier, GThread*> map; - return map; -} - -static ThreadIdentifier establishIdentifierForThread(GThread*& thread) -{ - MutexLocker locker(threadMapMutex()); - - static ThreadIdentifier identifierCount = 1; - - threadMap().add(identifierCount, thread); - - return identifierCount++; -} - -static ThreadIdentifier identifierByGthreadHandle(GThread*& thread) -{ - MutexLocker locker(threadMapMutex()); - - HashMap<ThreadIdentifier, GThread*>::iterator i = threadMap().begin(); - for (; i != threadMap().end(); ++i) { - if (i->second == thread) - return i->first; - } - - return 0; -} - -static GThread* threadForIdentifier(ThreadIdentifier id) -{ - MutexLocker locker(threadMapMutex()); - - return threadMap().get(id); -} - -static void clearThreadForIdentifier(ThreadIdentifier id) -{ - MutexLocker locker(threadMapMutex()); - - ASSERT(threadMap().contains(id)); - - threadMap().remove(id); -} - -ThreadIdentifier createThread(ThreadFunction entryPoint, void* data) -{ - GThread* thread; - if (!(thread = g_thread_create(entryPoint, data, TRUE, 0))) { - LOG_ERROR("Failed to create thread at entry point %p with data %p", entryPoint, data); - return 0; - } - - ThreadIdentifier threadID = establishIdentifierForThread(thread); - return threadID; -} - -int waitForThreadCompletion(ThreadIdentifier threadID, void** result) -{ - ASSERT(threadID); - - GThread* thread = threadForIdentifier(threadID); - - *result = g_thread_join(thread); - - clearThreadForIdentifier(threadID); - return 0; -} - -void detachThread(ThreadIdentifier) -{ -} - -ThreadIdentifier currentThread() -{ - GThread* currentThread = g_thread_self(); - if (ThreadIdentifier id = identifierByGthreadHandle(currentThread)) - return id; - return establishIdentifierForThread(currentThread); -} - -Mutex::Mutex() - : m_mutex(g_mutex_new()) -{ -} - -Mutex::~Mutex() -{ - g_mutex_free(m_mutex); -} - -void Mutex::lock() -{ - g_mutex_lock(m_mutex); -} - -bool Mutex::tryLock() -{ - return g_mutex_trylock(m_mutex); -} - -void Mutex::unlock() -{ - g_mutex_unlock(m_mutex); -} - -ThreadCondition::ThreadCondition() - : m_condition(g_cond_new()) -{ -} - -ThreadCondition::~ThreadCondition() -{ - g_cond_free(m_condition); -} - -void ThreadCondition::wait(Mutex& mutex) -{ - g_cond_wait(m_condition, mutex.impl()); -} - -void ThreadCondition::signal() -{ - g_cond_signal(m_condition); -} - -void ThreadCondition::broadcast() -{ - g_cond_broadcast(m_condition); -} - - -} diff --git a/JavaScriptCore/wtf/ThreadingNone.cpp b/JavaScriptCore/wtf/ThreadingNone.cpp deleted file mode 100644 index 2c20864..0000000 --- a/JavaScriptCore/wtf/ThreadingNone.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2007 Apple Inc. All rights reserved. - * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "config.h" -#include "Threading.h" - -namespace WTF { - -ThreadIdentifier createThread(ThreadFunction, void*) { return 0; } -int waitForThreadCompletion(ThreadIdentifier, void**) { return 0; } -void detachThread(ThreadIdentifier) { } -ThreadIdentifier currentThread() { return 0; } - -Mutex::Mutex() {} -Mutex::~Mutex() {} -void Mutex::lock() {} -bool Mutex::tryLock() { return false; } -void Mutex::unlock() {}; - -ThreadCondition::ThreadCondition() {} -ThreadCondition::~ThreadCondition() {} -void ThreadCondition::wait(Mutex& mutex) {} -void ThreadCondition::signal() {} -void ThreadCondition::broadcast() {} - -} // namespace WebCore diff --git a/JavaScriptCore/wtf/ThreadingPthreads.cpp b/JavaScriptCore/wtf/ThreadingPthreads.cpp deleted file mode 100644 index 2fea5ba..0000000 --- a/JavaScriptCore/wtf/ThreadingPthreads.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (C) 2007 Apple Inc. All rights reserved. - * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "config.h" -#include "Threading.h" - -#include <wtf/HashMap.h> - -#include <errno.h> - -namespace WTF { - -static Mutex& threadMapMutex() -{ - static Mutex mutex; - return mutex; -} - -static HashMap<ThreadIdentifier, pthread_t>& threadMap() -{ - static HashMap<ThreadIdentifier, pthread_t> map; - return map; -} - -static ThreadIdentifier establishIdentifierForPthreadHandle(pthread_t& pthreadHandle) -{ - MutexLocker locker(threadMapMutex()); - - static ThreadIdentifier identifierCount = 1; - - threadMap().add(identifierCount, pthreadHandle); - - return identifierCount++; -} - -static ThreadIdentifier identifierByPthreadHandle(const pthread_t& pthreadHandle) -{ - MutexLocker locker(threadMapMutex()); - - HashMap<ThreadIdentifier, pthread_t>::iterator i = threadMap().begin(); - for (; i != threadMap().end(); ++i) { - if (pthread_equal(i->second, pthreadHandle)) - return i->first; - } - - return 0; -} - -static pthread_t pthreadHandleForIdentifier(ThreadIdentifier id) -{ - MutexLocker locker(threadMapMutex()); - - return threadMap().get(id); -} - -static void clearPthreadHandleForIdentifier(ThreadIdentifier id) -{ - MutexLocker locker(threadMapMutex()); - - ASSERT(threadMap().contains(id)); - - threadMap().remove(id); -} - -ThreadIdentifier createThread(ThreadFunction entryPoint, void* data) -{ - pthread_t threadHandle; - if (pthread_create(&threadHandle, NULL, entryPoint, data)) { - LOG_ERROR("Failed to create pthread at entry point %p with data %p", entryPoint, data); - return 0; - } - - ThreadIdentifier threadID = establishIdentifierForPthreadHandle(threadHandle); - return threadID; -} - -int waitForThreadCompletion(ThreadIdentifier threadID, void** result) -{ - ASSERT(threadID); - - pthread_t pthreadHandle = pthreadHandleForIdentifier(threadID); - - int joinResult = pthread_join(pthreadHandle, result); - if (joinResult == EDEADLK) - LOG_ERROR("ThreadIdentifier %u was found to be deadlocked trying to quit", threadID); - - clearPthreadHandleForIdentifier(threadID); - return joinResult; -} - -void detachThread(ThreadIdentifier threadID) -{ - ASSERT(threadID); - - pthread_t pthreadHandle = pthreadHandleForIdentifier(threadID); - - pthread_detach(pthreadHandle); - - clearPthreadHandleForIdentifier(threadID); -} - -ThreadIdentifier currentThread() -{ - pthread_t currentThread = pthread_self(); - if (ThreadIdentifier id = identifierByPthreadHandle(currentThread)) - return id; - return establishIdentifierForPthreadHandle(currentThread); -} - -Mutex::Mutex() -{ - pthread_mutex_init(&m_mutex, NULL); -} - -Mutex::~Mutex() -{ - pthread_mutex_destroy(&m_mutex); -} - -void Mutex::lock() -{ - if (pthread_mutex_lock(&m_mutex) != 0) - ASSERT(false); -} - -bool Mutex::tryLock() -{ - int result = pthread_mutex_trylock(&m_mutex); - - if (result == 0) - return true; - else if (result == EBUSY) - return false; - - ASSERT(false); - return false; -} - -void Mutex::unlock() -{ - if (pthread_mutex_unlock(&m_mutex) != 0) - ASSERT(false); -} - -ThreadCondition::ThreadCondition() -{ - pthread_cond_init(&m_condition, NULL); -} - -ThreadCondition::~ThreadCondition() -{ - pthread_cond_destroy(&m_condition); -} - -void ThreadCondition::wait(Mutex& mutex) -{ - if (pthread_cond_wait(&m_condition, &mutex.impl()) != 0) - ASSERT(false); -} - -void ThreadCondition::signal() -{ - if (pthread_cond_signal(&m_condition) != 0) - ASSERT(false); -} - -void ThreadCondition::broadcast() -{ - if (pthread_cond_broadcast(&m_condition) != 0) - ASSERT(false); -} - -} // namespace WTF diff --git a/JavaScriptCore/wtf/ThreadingWin.cpp b/JavaScriptCore/wtf/ThreadingWin.cpp deleted file mode 100644 index c946313..0000000 --- a/JavaScriptCore/wtf/ThreadingWin.cpp +++ /dev/null @@ -1,370 +0,0 @@ -/* - * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * ============================================================================= - * Note: The implementation of condition variables under the Windows - * plaform was based on that of the excellent BOOST C++ library. It - * has been rewritten to fit in with the WebKit architecture and to - * use its coding conventions. - * ============================================================================= - * - * The Boost license is virtually identical to the Apple variation at the - * top of this file, but is included here for completeness: - * - * Boost Software License - Version 1.0 - August 17th, 2003 - * - * Permission is hereby granted, free of charge, to any person or organization - * obtaining a copy of the software and accompanying documentation covered by - * this license (the "Software") to use, reproduce, display, distribute, - * execute, and transmit the Software, and to prepare derivative works of the - * Software, and to permit third-parties to whom the Software is furnished to - * do so, all subject to the following: - * - * The copyright notices in the Software and this entire statement, including - * the above license grant, this restriction and the following disclaimer, - * must be included in all copies of the Software, in whole or in part, and - * all derivative works of the Software, unless such copies or derivative - * works are solely in the form of machine-executable object code generated by - * a source language processor. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT - * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE - * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#include "config.h" -#include "Threading.h" - -#include <windows.h> -#include <wtf/HashMap.h> - -namespace WTF { - -static Mutex& threadMapMutex() -{ - static Mutex mutex; - return mutex; -} - -static HashMap<DWORD, HANDLE>& threadMap() -{ - static HashMap<DWORD, HANDLE> map; - return map; -} - -static void storeThreadHandleByIdentifier(DWORD threadID, HANDLE threadHandle) -{ - MutexLocker locker(threadMapMutex()); - threadMap().add(threadID, threadHandle); -} - -static HANDLE threadHandleForIdentifier(ThreadIdentifier id) -{ - MutexLocker locker(threadMapMutex()); - return threadMap().get(id); -} - -static void clearThreadHandleForIdentifier(ThreadIdentifier id) -{ - MutexLocker locker(threadMapMutex()); - ASSERT(threadMap().contains(id)); - threadMap().remove(id); -} - -ThreadIdentifier createThread(ThreadFunction entryPoint, void* data) -{ - DWORD threadIdentifier = 0; - ThreadIdentifier threadID = 0; - HANDLE hEvent = ::CreateEvent(0, FALSE, FALSE, 0); - HANDLE threadHandle = ::CreateThread(0, 0, (LPTHREAD_START_ROUTINE)entryPoint, data, 0, &threadIdentifier); - if (!threadHandle) { - LOG_ERROR("Failed to create thread at entry point %p with data %p", entryPoint, data); - return 0; - } - - threadID = static_cast<ThreadIdentifier>(threadIdentifier); - storeThreadHandleByIdentifier(threadIdentifier, threadHandle); - - return threadID; -} - -int waitForThreadCompletion(ThreadIdentifier threadID, void** result) -{ - ASSERT(threadID); - - HANDLE threadHandle = threadHandleForIdentifier(threadID); - if (!threadHandle) - LOG_ERROR("ThreadIdentifier %u did not correspond to an active thread when trying to quit", threadID); - - DWORD joinResult = ::WaitForSingleObject(threadHandle, INFINITE); - if (joinResult == WAIT_FAILED) - LOG_ERROR("ThreadIdentifier %u was found to be deadlocked trying to quit", threadID); - - ::CloseHandle(threadHandle); - clearThreadHandleForIdentifier(threadID); - - return joinResult; -} - -void detachThread(ThreadIdentifier threadID) -{ - ASSERT(threadID); - - HANDLE threadHandle = threadHandleForIdentifier(threadID); - if (threadHandle) - ::CloseHandle(threadHandle); - clearThreadHandleForIdentifier(threadID); -} - -ThreadIdentifier currentThread() -{ - return static_cast<ThreadIdentifier>(::GetCurrentThreadId()); -} - -Mutex::Mutex() -{ - m_mutex.m_recursionCount = 0; - ::InitializeCriticalSection(&m_mutex.m_internalMutex); -} - -Mutex::~Mutex() -{ - ::DeleteCriticalSection(&m_mutex.m_internalMutex); -} - -void Mutex::lock() -{ - ::EnterCriticalSection(&m_mutex.m_internalMutex); - ++m_mutex.m_recursionCount; -} - -bool Mutex::tryLock() -{ - // This method is modeled after the behavior of pthread_mutex_trylock, - // which will return an error if the lock is already owned by the - // current thread. Since the primitive Win32 'TryEnterCriticalSection' - // treats this as a successful case, it changes the behavior of several - // tests in WebKit that check to see if the current thread already - // owned this mutex (see e.g., IconDatabase::getOrCreateIconRecord) - DWORD result = ::TryEnterCriticalSection(&m_mutex.m_internalMutex); - - if (result != 0) { // We got the lock - // If this thread already had the lock, we must unlock and - // return false so that we mimic the behavior of POSIX's - // pthread_mutex_trylock: - if (m_mutex.m_recursionCount > 0) { - ::LeaveCriticalSection(&m_mutex.m_internalMutex); - return false; - } - - ++m_mutex.m_recursionCount; - return true; - } - - return false; -} - -void Mutex::unlock() -{ - --m_mutex.m_recursionCount; - ::LeaveCriticalSection(&m_mutex.m_internalMutex); -} - -static const long MaxSemaphoreCount = static_cast<long>(~0UL >> 1); - -ThreadCondition::ThreadCondition() -{ - m_condition.m_timedOut = 0; - m_condition.m_blocked = 0; - m_condition.m_waitingForRemoval = 0; - m_condition.m_gate = ::CreateSemaphore(0, 1, 1, 0); - m_condition.m_queue = ::CreateSemaphore(0, 0, MaxSemaphoreCount, 0); - m_condition.m_mutex = ::CreateMutex(0, 0, 0); - - if (!m_condition.m_gate || !m_condition.m_queue || !m_condition.m_mutex) { - if (m_condition.m_gate) - ::CloseHandle(m_condition.m_gate); - if (m_condition.m_queue) - ::CloseHandle(m_condition.m_queue); - if (m_condition.m_mutex) - ::CloseHandle(m_condition.m_mutex); - } -} - -ThreadCondition::~ThreadCondition() -{ - ::CloseHandle(m_condition.m_gate); - ::CloseHandle(m_condition.m_queue); - ::CloseHandle(m_condition.m_mutex); -} - -void ThreadCondition::wait(Mutex& mutex) -{ - PlatformMutex& cs = mutex.impl(); - - // Enter the wait state. - DWORD res = ::WaitForSingleObject(m_condition.m_gate, INFINITE); - ASSERT(res == WAIT_OBJECT_0); - ++m_condition.m_blocked; - res = ::ReleaseSemaphore(m_condition.m_gate, 1, 0); - ASSERT(res); - - ::LeaveCriticalSection(&cs.m_internalMutex); - - res = ::WaitForSingleObject(m_condition.m_queue, INFINITE); - ASSERT(res == WAIT_OBJECT_0); - - res = ::WaitForSingleObject(m_condition.m_mutex, INFINITE); - ASSERT(res == WAIT_OBJECT_0); - size_t wasWaiting = m_condition.m_waitingForRemoval; - size_t wasTimedOut = m_condition.m_timedOut; - if (wasWaiting != 0) { - if (--m_condition.m_waitingForRemoval == 0) { - if (m_condition.m_blocked != 0) { - res = ::ReleaseSemaphore(m_condition.m_gate, 1, 0); // open m_gate - ASSERT(res); - wasWaiting = 0; - } - else if (m_condition.m_timedOut != 0) - m_condition.m_timedOut = 0; - } - } else if (++m_condition.m_timedOut == ((std::numeric_limits<unsigned>::max)() / 2)) { - // timeout occured, normalize the m_condition.m_timedOut count - // this may occur if many calls to wait with a timeout are made and - // no call to notify_* is made - res = ::WaitForSingleObject(m_condition.m_gate, INFINITE); - ASSERT(res == WAIT_OBJECT_0); - m_condition.m_blocked -= m_condition.m_timedOut; - res = ::ReleaseSemaphore(m_condition.m_gate, 1, 0); - ASSERT(res); - m_condition.m_timedOut = 0; - } - res = ::ReleaseMutex(m_condition.m_mutex); - ASSERT(res); - - if (wasWaiting == 1) { - for (/**/ ; wasTimedOut; --wasTimedOut) { - // better now than spurious later - res = ::WaitForSingleObject(m_condition.m_queue, INFINITE); - ASSERT(res == WAIT_OBJECT_0); - } - res = ::ReleaseSemaphore(m_condition.m_gate, 1, 0); - ASSERT(res); - } - - ::EnterCriticalSection (&cs.m_internalMutex); -} - -void ThreadCondition::signal() -{ - unsigned signals = 0; - - DWORD res = ::WaitForSingleObject(m_condition.m_mutex, INFINITE); - ASSERT(res == WAIT_OBJECT_0); - - if (m_condition.m_waitingForRemoval != 0) { // the m_gate is already closed - if (m_condition.m_blocked == 0) { - res = ::ReleaseMutex(m_condition.m_mutex); - ASSERT(res); - return; - } - - ++m_condition.m_waitingForRemoval; - --m_condition.m_blocked; - - signals = 1; - } else { - res = ::WaitForSingleObject(m_condition.m_gate, INFINITE); - ASSERT(res == WAIT_OBJECT_0); - if (m_condition.m_blocked > m_condition.m_timedOut) { - if (m_condition.m_timedOut != 0) { - m_condition.m_blocked -= m_condition.m_timedOut; - m_condition.m_timedOut = 0; - } - signals = m_condition.m_waitingForRemoval = 1; - --m_condition.m_blocked; - } else { - res = ::ReleaseSemaphore(m_condition.m_gate, 1, 0); - ASSERT(res); - } - } - - res =::ReleaseMutex(m_condition.m_mutex); - ASSERT(res); - - if (signals) { - res = ::ReleaseSemaphore(m_condition.m_queue, signals, 0); - ASSERT(res); - } -} - -void ThreadCondition::broadcast() -{ - unsigned signals = 0; - - WORD res = ::WaitForSingleObject(m_condition.m_mutex, INFINITE); - ASSERT(res == WAIT_OBJECT_0); - - if (m_condition.m_waitingForRemoval != 0) { // the m_gate is already closed - if (m_condition.m_blocked == 0) { - res = ::ReleaseMutex(m_condition.m_mutex); - ASSERT(res); - return; - } - - m_condition.m_waitingForRemoval += (signals = m_condition.m_blocked); - m_condition.m_blocked = 0; - } else { - res = ::WaitForSingleObject(m_condition.m_gate, INFINITE); - ASSERT(res == WAIT_OBJECT_0); - if (m_condition.m_blocked > m_condition.m_timedOut) { - if (m_condition.m_timedOut != 0) { - m_condition.m_blocked -= m_condition.m_timedOut; - m_condition.m_timedOut = 0; - } - signals = m_condition.m_waitingForRemoval = m_condition.m_blocked; - m_condition.m_blocked = 0; - } else { - res = ::ReleaseSemaphore(m_condition.m_gate, 1, 0); - ASSERT(res); - } - } - - res = ::ReleaseMutex(m_condition.m_mutex); - ASSERT(res); - - if (signals) { - res = ::ReleaseSemaphore(m_condition.m_queue, signals, 0); - ASSERT(res); - } -} - -} // namespace WTF diff --git a/JavaScriptCore/wtf/Vector.h b/JavaScriptCore/wtf/Vector.h index 63520f7..8fd412c 100644 --- a/JavaScriptCore/wtf/Vector.h +++ b/JavaScriptCore/wtf/Vector.h @@ -24,7 +24,6 @@ #include "Assertions.h" #include "FastMalloc.h" -#include "Noncopyable.h" #include "VectorTraits.h" #include <limits> #include <stdlib.h> @@ -241,7 +240,7 @@ namespace WTF { }; template<typename T> - class VectorBufferBase : Noncopyable { + class VectorBufferBase { public: void allocateBuffer(size_t newCapacity) { @@ -386,7 +385,7 @@ namespace WTF { template<typename T, size_t inlineCapacity = 0> class Vector { private: - typedef VectorBuffer<T, inlineCapacity> Buffer; + typedef VectorBuffer<T, inlineCapacity> Impl; typedef VectorTypeOperations<T> TypeOperations; public: @@ -402,7 +401,7 @@ namespace WTF { explicit Vector(size_t size) : m_size(size) - , m_buffer(size) + , m_impl(size) { TypeOperations::initialize(begin(), end()); } @@ -421,25 +420,25 @@ namespace WTF { Vector& operator=(const Vector<T, otherCapacity>&); size_t size() const { return m_size; } - size_t capacity() const { return m_buffer.capacity(); } + size_t capacity() const { return m_impl.capacity(); } bool isEmpty() const { return !size(); } T& at(size_t i) { ASSERT(i < size()); - return m_buffer.buffer()[i]; + return m_impl.buffer()[i]; } const T& at(size_t i) const { ASSERT(i < size()); - return m_buffer.buffer()[i]; + return m_impl.buffer()[i]; } T& operator[](size_t i) { return at(i); } const T& operator[](size_t i) const { return at(i); } - T* data() { return m_buffer.buffer(); } - const T* data() const { return m_buffer.buffer(); } + T* data() { return m_impl.buffer(); } + const T* data() const { return m_impl.buffer(); } iterator begin() { return data(); } iterator end() { return begin() + m_size; } @@ -472,7 +471,6 @@ namespace WTF { template<typename U, size_t c> void prepend(const Vector<U, c>&); void remove(size_t position); - void remove(size_t position, size_t length); void removeLast() { @@ -482,7 +480,7 @@ namespace WTF { Vector(size_t size, const T& val) : m_size(size) - , m_buffer(size) + , m_impl(size) { TypeOperations::uninitializedFill(begin(), end(), val); } @@ -497,7 +495,7 @@ namespace WTF { void swap(Vector<T, inlineCapacity>& other) { std::swap(m_size, other.m_size); - m_buffer.swap(other.m_buffer); + m_impl.swap(other.m_impl); } private: @@ -506,13 +504,13 @@ namespace WTF { template<typename U> U* expandCapacity(size_t newMinCapacity, U*); size_t m_size; - Buffer m_buffer; + Impl m_impl; }; template<typename T, size_t inlineCapacity> Vector<T, inlineCapacity>::Vector(const Vector& other) : m_size(other.size()) - , m_buffer(other.capacity()) + , m_impl(other.capacity()) { TypeOperations::uninitializedCopy(other.begin(), other.end(), begin()); } @@ -521,7 +519,7 @@ namespace WTF { template<size_t otherCapacity> Vector<T, inlineCapacity>::Vector(const Vector<T, otherCapacity>& other) : m_size(other.size()) - , m_buffer(other.capacity()) + , m_impl(other.capacity()) { TypeOperations::uninitializedCopy(other.begin(), other.end(), begin()); } @@ -654,9 +652,9 @@ namespace WTF { return; T* oldBuffer = begin(); T* oldEnd = end(); - m_buffer.allocateBuffer(newCapacity); + m_impl.allocateBuffer(newCapacity); TypeOperations::move(oldBuffer, oldEnd, begin()); - m_buffer.deallocateBuffer(oldBuffer); + m_impl.deallocateBuffer(oldBuffer); } // Templatizing these is better than just letting the conversion happen implicitly, @@ -682,13 +680,13 @@ namespace WTF { if (size() == capacity()) ptr = expandCapacity(size() + 1, ptr); -#if COMPILER(MSVC7) // FIXME: MSVC7 generates compilation errors when trying to assign // a pointer to a Vector of its base class (i.e. can't downcast). So far // I've been unable to determine any logical reason for this, so I can - // only assume it is a bug with the compiler. Casting is a bad solution, - // however, because it subverts implicit conversions, so a better - // one is needed. + // only assume it is a bug with the compiler. Casting is very bad + // however because it subverts implicit conversions, so a better + // solution is direly needed. +#if COMPILER(MSVC7) new (end()) T(static_cast<T>(*ptr)); #else new (end()) T(*ptr); @@ -776,21 +774,9 @@ namespace WTF { } template<typename T, size_t inlineCapacity> - inline void Vector<T, inlineCapacity>::remove(size_t position, size_t length) - { - ASSERT(position < size()); - ASSERT(position + length < size()); - T* beginSpot = begin() + position; - T* endSpot = beginSpot + length; - TypeOperations::destruct(beginSpot, endSpot); - TypeOperations::moveOverlapping(endSpot, end(), beginSpot); - m_size -= length; - } - - template<typename T, size_t inlineCapacity> inline T* Vector<T, inlineCapacity>::releaseBuffer() { - T* buffer = m_buffer.releaseBuffer(); + T* buffer = m_impl.releaseBuffer(); if (inlineCapacity && !buffer && m_size) { // If the vector had some data, but no buffer to release, // that means it was using the inline buffer. In that case, |