INCLUDEPATH += $$PWD/assembler
INCLUDEPATH += $$PWD/wtf
INCLUDEPATH += $$PWD/stubs
+INCLUDEPATH += $$PWD/stubs/wtf
INCLUDEPATH += $$PWD
DEFINES += WTF_USE_UDIS86=1
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the V4VM module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef PASSREFPTR_H
+#define PASSREFPTR_H
+
+template <typename T> class RefPtr;
+
+template <typename T>
+class PassRefPtr {
+public:
+ PassRefPtr() : m_ptr(0) {}
+
+ PassRefPtr(T* ptr)
+ : m_ptr(ptr)
+ {
+ if (m_ptr)
+ m_ptr->ref();
+ }
+
+ PassRefPtr(const PassRefPtr<T>& other)
+ : m_ptr(other.leakRef())
+ {
+ }
+
+ PassRefPtr(const RefPtr<T>& other)
+ : m_ptr(other.get())
+ {
+ if (m_ptr)
+ m_ptr->ref();
+ }
+
+ ~PassRefPtr()
+ {
+ if (m_ptr)
+ m_ptr->deref();
+ }
+
+ T* operator->() const { return m_ptr; }
+
+ T* leakRef() const
+ {
+ T* result = m_ptr;
+ m_ptr = 0;
+ return result;
+ }
+
+private:
+ PassRefPtr<T>& operator=(const PassRefPtr<T>&)
+ {}
+
+ template <typename PtrType> friend PassRefPtr<PtrType> adoptRef(PtrType*);
+ mutable T* m_ptr;
+};
+
+template <typename T>
+PassRefPtr<T> adoptRef(T* ptr)
+{
+ PassRefPtr<T> result;
+ result.m_ptr = ptr;
+ return result;
+}
+
+#endif // PASSREFPTR_H
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the V4VM module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef REFCOUNTED_H
+#define REFCOUNTED_H
+
+template <typename Base>
+class RefCounted {
+public:
+ RefCounted() : m_refCount(1) {}
+ ~RefCounted()
+ {
+ deref();
+ }
+
+ void ref()
+ {
+ ++m_refCount;
+ }
+
+ void deref()
+ {
+ if (!--m_refCount)
+ delete static_cast<Base*>(this);
+ }
+
+protected:
+ int m_refCount;
+};
+
+#endif // REFCOUNTED_H
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the V4VM module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef REFPTR_H
+#define REFPTR_H
+
+#include "PassRefPtr.h"
+
+template <typename T>
+class RefPtr {
+public:
+ RefPtr() : m_ptr(0) {}
+ RefPtr(const RefPtr<T> &other)
+ : m_ptr(other.m_ptr)
+ {
+ if (m_ptr)
+ m_ptr->ref();
+ }
+
+ RefPtr<T>& operator=(const RefPtr<T>& other)
+ {
+ if (other.m_ptr)
+ other.m_ptr->ref();
+ if (m_ptr)
+ m_ptr->deref();
+ m_ptr = other.m_ptr;
+ return *this;
+ }
+
+ RefPtr(const PassRefPtr<T>& other)
+ : m_ptr(other.leakRef())
+ {
+ }
+
+ ~RefPtr()
+ {
+ if (m_ptr)
+ m_ptr->deref();
+ }
+
+ T* operator->() const { return m_ptr; }
+ T* get() const { return m_ptr; }
+ bool operator!() const { return !m_ptr; }
+
+ PassRefPtr<T> release()
+ {
+ T* ptr = m_ptr;
+ m_ptr = 0;
+ return adoptRef(ptr);
+ }
+
+private:
+ T* m_ptr;
+};
+
+#endif // REFPTR_H
+++ /dev/null
-/*
- * Copyright (C) 2005, 2006, 2007, 2008 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
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef WTF_Alignment_h
-#define WTF_Alignment_h
-
-#include <wtf/Platform.h>
-#include <algorithm>
-#include <stdint.h>
-
-
-namespace WTF {
-
-#if COMPILER(GCC) || COMPILER(MINGW) || COMPILER(RVCT) || COMPILER(GCCE) || (COMPILER(SUNCC) && __SUNPRO_CC > 0x590)
- #define WTF_ALIGN_OF(type) __alignof__(type)
- #define WTF_ALIGNED(variable_type, variable, n) variable_type variable __attribute__((__aligned__(n)))
-#elif COMPILER(MSVC)
- #define WTF_ALIGN_OF(type) __alignof(type)
- #define WTF_ALIGNED(variable_type, variable, n) __declspec(align(n)) variable_type variable
-#else
- #error WTF_ALIGN macros need alignment control.
-#endif
-
-#if COMPILER(GCC) && !COMPILER(INTEL) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 303)
- typedef char __attribute__((__may_alias__)) AlignedBufferChar;
-#else
- typedef char AlignedBufferChar;
-#endif
-
- template<size_t size, size_t alignment> struct AlignedBuffer;
- template<size_t size> struct AlignedBuffer<size, 1> { AlignedBufferChar buffer[size]; };
- template<size_t size> struct AlignedBuffer<size, 2> { WTF_ALIGNED(AlignedBufferChar, buffer[size], 2); };
- template<size_t size> struct AlignedBuffer<size, 4> { WTF_ALIGNED(AlignedBufferChar, buffer[size], 4); };
- template<size_t size> struct AlignedBuffer<size, 8> { WTF_ALIGNED(AlignedBufferChar, buffer[size], 8); };
- template<size_t size> struct AlignedBuffer<size, 16> { WTF_ALIGNED(AlignedBufferChar, buffer[size], 16); };
- template<size_t size> struct AlignedBuffer<size, 32> { WTF_ALIGNED(AlignedBufferChar, buffer[size], 32); };
- template<size_t size> struct AlignedBuffer<size, 64> { WTF_ALIGNED(AlignedBufferChar, buffer[size], 64); };
-
- template <size_t size, size_t alignment>
- void swap(AlignedBuffer<size, alignment>& a, AlignedBuffer<size, alignment>& b)
- {
- for (size_t i = 0; i < size; ++i)
- std::swap(a.buffer[i], b.buffer[i]);
- }
-
- template <uintptr_t mask>
- inline bool isAlignedTo(const void* pointer)
- {
- return !(reinterpret_cast<uintptr_t>(pointer) & mask);
- }
-}
-
-#endif // WTF_Alignment_h
+++ /dev/null
-/*
- * Copyright (C) 2005, 2007, 2008 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
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
-
-/* This file is no longer necessary, since all the functionality has been moved to Compiler.h. */
-
-#include <wtf/Platform.h>
+++ /dev/null
-/*
- * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 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
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef WTF_PassRefPtr_h
-#define WTF_PassRefPtr_h
-
-#include <wtf/AlwaysInline.h>
-#include <wtf/Assertions.h>
-#include <wtf/NullPtr.h>
-
-namespace WTF {
-
- template<typename T> class RefPtr;
- template<typename T> class PassRefPtr;
- template<typename T> PassRefPtr<T> adoptRef(T*);
-
- inline void adopted(const void*) { }
-
-#if !(PLATFORM(QT) && CPU(ARM))
- #define REF_DEREF_INLINE ALWAYS_INLINE
-#else
- // Older version of gcc used by Harmattan SDK fails to build with ALWAYS_INLINE.
- // See https://bugs.webkit.org/show_bug.cgi?id=37253 for details.
- #define REF_DEREF_INLINE inline
-#endif
-
- template<typename T> REF_DEREF_INLINE void refIfNotNull(T* ptr)
- {
- if (LIKELY(ptr != 0))
- ptr->ref();
- }
-
- template<typename T> REF_DEREF_INLINE void derefIfNotNull(T* ptr)
- {
- if (LIKELY(ptr != 0))
- ptr->deref();
- }
-
- #undef REF_DEREF_INLINE
-
- template<typename T> class PassRefPtr {
- public:
- PassRefPtr() : m_ptr(0) { }
- PassRefPtr(T* ptr) : m_ptr(ptr) { refIfNotNull(ptr); }
- // It somewhat breaks the type system to allow transfer of ownership out of
- // a const PassRefPtr. However, it makes it much easier to work with PassRefPtr
- // temporaries, and we don't have a need to use real const PassRefPtrs anyway.
- PassRefPtr(const PassRefPtr& o) : m_ptr(o.leakRef()) { }
- template<typename U> PassRefPtr(const PassRefPtr<U>& o) : m_ptr(o.leakRef()) { }
-
- ALWAYS_INLINE ~PassRefPtr() { derefIfNotNull(m_ptr); }
-
- template<typename U> PassRefPtr(const RefPtr<U>&);
-
- T* get() const { return m_ptr; }
-
- T* leakRef() const WARN_UNUSED_RETURN;
-
- T& operator*() const { return *m_ptr; }
- T* operator->() const { return m_ptr; }
-
- bool operator!() const { return !m_ptr; }
-
- // This conversion operator allows implicit conversion to bool but not to other integer types.
- typedef T* (PassRefPtr::*UnspecifiedBoolType);
- operator UnspecifiedBoolType() const { return m_ptr ? &PassRefPtr::m_ptr : 0; }
-
- PassRefPtr& operator=(const PassRefPtr&) { COMPILE_ASSERT(!sizeof(T*), PassRefPtr_should_never_be_assigned_to); return *this; }
-
- friend PassRefPtr adoptRef<T>(T*);
-
- private:
- // adopting constructor
- PassRefPtr(T* ptr, bool) : m_ptr(ptr) { }
-
- mutable T* m_ptr;
- };
-
- template<typename T> template<typename U> inline PassRefPtr<T>::PassRefPtr(const RefPtr<U>& o)
- : m_ptr(o.get())
- {
- T* ptr = m_ptr;
- refIfNotNull(ptr);
- }
-
- template<typename T> inline T* PassRefPtr<T>::leakRef() const
- {
- T* ptr = m_ptr;
- m_ptr = 0;
- return ptr;
- }
-
- template<typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, const PassRefPtr<U>& b)
- {
- return a.get() == b.get();
- }
-
- template<typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, const RefPtr<U>& b)
- {
- return a.get() == b.get();
- }
-
- template<typename T, typename U> inline bool operator==(const RefPtr<T>& a, const PassRefPtr<U>& b)
- {
- return a.get() == b.get();
- }
-
- template<typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, U* b)
- {
- return a.get() == b;
- }
-
- template<typename T, typename U> inline bool operator==(T* a, const PassRefPtr<U>& b)
- {
- return a == b.get();
- }
-
- template<typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, const PassRefPtr<U>& b)
- {
- return a.get() != b.get();
- }
-
- template<typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, const RefPtr<U>& b)
- {
- return a.get() != b.get();
- }
-
- template<typename T, typename U> inline bool operator!=(const RefPtr<T>& a, const PassRefPtr<U>& b)
- {
- return a.get() != b.get();
- }
-
- template<typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, U* b)
- {
- return a.get() != b;
- }
-
- template<typename T, typename U> inline bool operator!=(T* a, const PassRefPtr<U>& b)
- {
- return a != b.get();
- }
-
- template<typename T> inline PassRefPtr<T> adoptRef(T* p)
- {
- adopted(p);
- return PassRefPtr<T>(p, true);
- }
-
- template<typename T, typename U> inline PassRefPtr<T> static_pointer_cast(const PassRefPtr<U>& p)
- {
- return adoptRef(static_cast<T*>(p.leakRef()));
- }
-
- template<typename T, typename U> inline PassRefPtr<T> const_pointer_cast(const PassRefPtr<U>& p)
- {
- return adoptRef(const_cast<T*>(p.leakRef()));
- }
-
- template<typename T> inline T* getPtr(const PassRefPtr<T>& p)
- {
- return p.get();
- }
-
-} // namespace WTF
-
-using WTF::PassRefPtr;
-using WTF::adoptRef;
-using WTF::static_pointer_cast;
-using WTF::const_pointer_cast;
-
-#endif // WTF_PassRefPtr_h
+++ /dev/null
-/*
- * Copyright (C) 2006, 2007, 2008, 2009, 2010 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
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef RefCounted_h
-#define RefCounted_h
-
-#include <wtf/Assertions.h>
-#include <wtf/FastAllocBase.h>
-#include <wtf/Noncopyable.h>
-#include <wtf/OwnPtr.h>
-#include <wtf/ThreadRestrictionVerifier.h>
-#include <wtf/UnusedParam.h>
-
-namespace WTF {
-
-#ifdef NDEBUG
-#define CHECK_REF_COUNTED_LIFECYCLE 0
-#else
-#define CHECK_REF_COUNTED_LIFECYCLE 1
-#endif
-
-// This base class holds the non-template methods and attributes.
-// The RefCounted class inherits from it reducing the template bloat
-// generated by the compiler (technique called template hoisting).
-class RefCountedBase {
-public:
- void ref()
- {
-#if CHECK_REF_COUNTED_LIFECYCLE
- // Start thread verification as soon as the ref count gets to 2. This
- // heuristic reflects the fact that items are often created on one thread
- // and then given to another thread to be used.
- // FIXME: Make this restriction tigher. Especially as we move to more
- // common methods for sharing items across threads like CrossThreadCopier.h
- // We should be able to add a "detachFromThread" method to make this explicit.
- if (m_refCount == 1)
- m_verifier.setShared(true);
- // If this assert fires, it either indicates a thread safety issue or
- // that the verification needs to change. See ThreadRestrictionVerifier for
- // the different modes.
- ASSERT(m_verifier.isSafeToUse());
- ASSERT(!m_deletionHasBegun);
- ASSERT(!m_adoptionIsRequired);
-#endif
- ++m_refCount;
- }
-
- bool hasOneRef() const
- {
-#if CHECK_REF_COUNTED_LIFECYCLE
- ASSERT(m_verifier.isSafeToUse());
- ASSERT(!m_deletionHasBegun);
-#endif
- return m_refCount == 1;
- }
-
- int refCount() const
- {
-#if CHECK_REF_COUNTED_LIFECYCLE
- ASSERT(m_verifier.isSafeToUse());
-#endif
- return m_refCount;
- }
-
- void setMutexForVerifier(Mutex&);
-
-#if HAVE(DISPATCH_H)
- void setDispatchQueueForVerifier(dispatch_queue_t);
-#endif
-
- // Turns off verification. Use of this method is discouraged (instead extend
- // ThreadRestrictionVerifier to verify your case).
- // NB. It is necessary to call this in the constructor of many objects in
- // JavaScriptCore, because JavaScriptCore objects may be used from multiple
- // threads even if the reference counting is done in a racy manner. This is
- // because a JSC instance may be used from multiple threads so long as all
- // accesses into that instance are protected by a per-instance lock. It would
- // be absolutely wrong to prohibit this pattern, and it would be a disastrous
- // regression to require that the objects within that instance use a thread-
- // safe version of reference counting.
- void turnOffVerifier()
- {
-#if CHECK_REF_COUNTED_LIFECYCLE
- m_verifier.turnOffVerification();
-#endif
- }
-
- void relaxAdoptionRequirement()
- {
-#if CHECK_REF_COUNTED_LIFECYCLE
- ASSERT(!m_deletionHasBegun);
- ASSERT(m_adoptionIsRequired);
- m_adoptionIsRequired = false;
-#endif
- }
-
- // Helper for generating JIT code. Please do not use for non-JIT purposes.
- const int* addressOfCount() const
- {
- return &m_refCount;
- }
-
-protected:
- RefCountedBase()
- : m_refCount(1)
-#if CHECK_REF_COUNTED_LIFECYCLE
- , m_deletionHasBegun(false)
- , m_adoptionIsRequired(true)
-#endif
- {
- }
-
- ~RefCountedBase()
- {
-#if CHECK_REF_COUNTED_LIFECYCLE
- ASSERT(m_deletionHasBegun);
- ASSERT(!m_adoptionIsRequired);
-#endif
- }
-
- // Returns whether the pointer should be freed or not.
- bool derefBase()
- {
-#if CHECK_REF_COUNTED_LIFECYCLE
- ASSERT(m_verifier.isSafeToUse());
- ASSERT(!m_deletionHasBegun);
- ASSERT(!m_adoptionIsRequired);
-#endif
-
- ASSERT(m_refCount > 0);
- if (m_refCount == 1) {
-#if CHECK_REF_COUNTED_LIFECYCLE
- m_deletionHasBegun = true;
-#endif
- return true;
- }
-
- --m_refCount;
-#if CHECK_REF_COUNTED_LIFECYCLE
- // Stop thread verification when the ref goes to 1 because it
- // is safe to be passed to another thread at this point.
- if (m_refCount == 1)
- m_verifier.setShared(false);
-#endif
- return false;
- }
-
-#if CHECK_REF_COUNTED_LIFECYCLE
- bool deletionHasBegun() const
- {
- return m_deletionHasBegun;
- }
-#endif
-
-private:
-
-#if CHECK_REF_COUNTED_LIFECYCLE
- friend void adopted(RefCountedBase*);
-#endif
-
- int m_refCount;
-#if CHECK_REF_COUNTED_LIFECYCLE
- bool m_deletionHasBegun;
- bool m_adoptionIsRequired;
- ThreadRestrictionVerifier m_verifier;
-#endif
-};
-
-#if CHECK_REF_COUNTED_LIFECYCLE
-inline void adopted(RefCountedBase* object)
-{
- if (!object)
- return;
- ASSERT(!object->m_deletionHasBegun);
- object->m_adoptionIsRequired = false;
-}
-#endif
-
-template<typename T> class RefCounted : public RefCountedBase {
- WTF_MAKE_NONCOPYABLE(RefCounted); WTF_MAKE_FAST_ALLOCATED;
-public:
- void deref()
- {
- if (derefBase())
- delete static_cast<T*>(this);
- }
-
-protected:
- RefCounted() { }
- ~RefCounted()
- {
- }
-};
-
-template<typename T> class RefCountedCustomAllocated : public RefCountedBase {
- WTF_MAKE_NONCOPYABLE(RefCountedCustomAllocated);
-
-public:
- void deref()
- {
- if (derefBase())
- delete static_cast<T*>(this);
- }
-
-protected:
- ~RefCountedCustomAllocated()
- {
- }
-};
-
-#if CHECK_REF_COUNTED_LIFECYCLE
-inline void RefCountedBase::setMutexForVerifier(Mutex& mutex)
-{
- m_verifier.setMutexMode(mutex);
-}
-#else
-inline void RefCountedBase::setMutexForVerifier(Mutex&) { }
-#endif
-
-#if HAVE(DISPATCH_H)
-#if CHECK_REF_COUNTED_LIFECYCLE
-inline void RefCountedBase::setDispatchQueueForVerifier(dispatch_queue_t queue)
-{
- m_verifier.setDispatchQueueMode(queue);
-}
-#else
-inline void RefCountedBase::setDispatchQueueForVerifier(dispatch_queue_t) { }
-#endif
-#endif // HAVE(DISPATCH_H)
-
-} // namespace WTF
-
-using WTF::RefCounted;
-using WTF::RefCountedCustomAllocated;
-
-#endif // RefCounted_h
+++ /dev/null
-/*
- * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 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
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
-
-// RefPtr and PassRefPtr are documented at http://webkit.org/coding/RefPtr.html
-
-#ifndef WTF_RefPtr_h
-#define WTF_RefPtr_h
-
-#include <algorithm>
-#include <wtf/FastAllocBase.h>
-#include <wtf/PassRefPtr.h>
-
-namespace WTF {
-
- enum PlacementNewAdoptType { PlacementNewAdopt };
-
- template<typename T> class PassRefPtr;
-
- enum HashTableDeletedValueType { HashTableDeletedValue };
-
- template<typename T> class RefPtr {
- WTF_MAKE_FAST_ALLOCATED;
- public:
- ALWAYS_INLINE RefPtr() : m_ptr(0) { }
- ALWAYS_INLINE RefPtr(T* ptr) : m_ptr(ptr) { refIfNotNull(ptr); }
- ALWAYS_INLINE RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { refIfNotNull(m_ptr); }
- template<typename U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { refIfNotNull(m_ptr); }
-
- // See comments in PassRefPtr.h for an explanation of why this takes a const reference.
- template<typename U> RefPtr(const PassRefPtr<U>&);
-
- // Special constructor for cases where we overwrite an object in place.
- ALWAYS_INLINE RefPtr(PlacementNewAdoptType) { }
-
- // Hash table deleted values, which are only constructed and never copied or destroyed.
- RefPtr(HashTableDeletedValueType) : m_ptr(hashTableDeletedValue()) { }
- bool isHashTableDeletedValue() const { return m_ptr == hashTableDeletedValue(); }
-
- ALWAYS_INLINE ~RefPtr() { derefIfNotNull(m_ptr); }
-
- T* get() const { return m_ptr; }
-
- void clear();
- PassRefPtr<T> release() { PassRefPtr<T> tmp = adoptRef(m_ptr); m_ptr = 0; return tmp; }
-
- T& operator*() const { return *m_ptr; }
- ALWAYS_INLINE T* operator->() const { return m_ptr; }
-
- bool operator!() const { return !m_ptr; }
-
- // This conversion operator allows implicit conversion to bool but not to other integer types.
- typedef T* (RefPtr::*UnspecifiedBoolType);
- operator UnspecifiedBoolType() const { return m_ptr ? &RefPtr::m_ptr : 0; }
-
- RefPtr& operator=(const RefPtr&);
- RefPtr& operator=(T*);
- RefPtr& operator=(const PassRefPtr<T>&);
-#if !COMPILER_SUPPORTS(CXX_NULLPTR)
- RefPtr& operator=(std::nullptr_t) { clear(); return *this; }
-#endif
- template<typename U> RefPtr& operator=(const RefPtr<U>&);
- template<typename U> RefPtr& operator=(const PassRefPtr<U>&);
-
- void swap(RefPtr&);
-
- static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); }
-
- private:
- T* m_ptr;
- };
-
- template<typename T> template<typename U> inline RefPtr<T>::RefPtr(const PassRefPtr<U>& o)
- : m_ptr(o.leakRef())
- {
- }
-
- template<typename T> inline void RefPtr<T>::clear()
- {
- T* ptr = m_ptr;
- m_ptr = 0;
- derefIfNotNull(ptr);
- }
-
- template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<T>& o)
- {
- T* optr = o.get();
- refIfNotNull(optr);
- T* ptr = m_ptr;
- m_ptr = optr;
- derefIfNotNull(ptr);
- return *this;
- }
-
- template<typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<U>& o)
- {
- T* optr = o.get();
- refIfNotNull(optr);
- T* ptr = m_ptr;
- m_ptr = optr;
- derefIfNotNull(ptr);
- return *this;
- }
-
- template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(T* optr)
- {
- refIfNotNull(optr);
- T* ptr = m_ptr;
- m_ptr = optr;
- derefIfNotNull(ptr);
- return *this;
- }
-
- template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(const PassRefPtr<T>& o)
- {
- T* ptr = m_ptr;
- m_ptr = o.leakRef();
- derefIfNotNull(ptr);
- return *this;
- }
-
- template<typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const PassRefPtr<U>& o)
- {
- T* ptr = m_ptr;
- m_ptr = o.leakRef();
- derefIfNotNull(ptr);
- return *this;
- }
-
- template<class T> inline void RefPtr<T>::swap(RefPtr<T>& o)
- {
- std::swap(m_ptr, o.m_ptr);
- }
-
- template<class T> inline void swap(RefPtr<T>& a, RefPtr<T>& b)
- {
- a.swap(b);
- }
-
- template<typename T, typename U> inline bool operator==(const RefPtr<T>& a, const RefPtr<U>& b)
- {
- return a.get() == b.get();
- }
-
- template<typename T, typename U> inline bool operator==(const RefPtr<T>& a, U* b)
- {
- return a.get() == b;
- }
-
- template<typename T, typename U> inline bool operator==(T* a, const RefPtr<U>& b)
- {
- return a == b.get();
- }
-
- template<typename T, typename U> inline bool operator!=(const RefPtr<T>& a, const RefPtr<U>& b)
- {
- return a.get() != b.get();
- }
-
- template<typename T, typename U> inline bool operator!=(const RefPtr<T>& a, U* b)
- {
- return a.get() != b;
- }
-
- template<typename T, typename U> inline bool operator!=(T* a, const RefPtr<U>& b)
- {
- return a != b.get();
- }
-
- template<typename T, typename U> inline RefPtr<T> static_pointer_cast(const RefPtr<U>& p)
- {
- return RefPtr<T>(static_cast<T*>(p.get()));
- }
-
- template<typename T, typename U> inline RefPtr<T> const_pointer_cast(const RefPtr<U>& p)
- {
- return RefPtr<T>(const_cast<T*>(p.get()));
- }
-
- template<typename T> inline T* getPtr(const RefPtr<T>& p)
- {
- return p.get();
- }
-
-} // namespace WTF
-
-using WTF::RefPtr;
-using WTF::static_pointer_cast;
-using WTF::const_pointer_cast;
-
-#endif // WTF_RefPtr_h
+++ /dev/null
-/*
- * Copyright (C) 2011 Google 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:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * 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.
- * * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
- * OWNER OR 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 ThreadRestrictionVerifier_h
-#define ThreadRestrictionVerifier_h
-
-#include <wtf/Assertions.h>
-#include <wtf/Threading.h>
-#include <wtf/ThreadingPrimitives.h>
-
-#if HAVE(DISPATCH_H)
-#include <dispatch/dispatch.h>
-#endif
-
-#ifndef NDEBUG
-
-namespace WTF {
-
-// Verifies that a class is used in a way that respects its lack of thread-safety.
-// The default mode is to verify that the object will only be used on a single thread. The
-// thread gets captured when setShared(true) is called.
-// The mode may be changed by calling useMutexMode (or turnOffVerification).
-#if !USE(JSC) // This verifier is completely wrong for JavaScript implementations that use threads
-class ThreadRestrictionVerifier {
-public:
- ThreadRestrictionVerifier()
- : m_mode(SingleThreadVerificationMode)
- , m_shared(false)
- , m_owningThread(0)
- , m_mutex(0)
-#if HAVE(DISPATCH_H)
- , m_owningQueue(0)
-#endif
- {
- }
-
-#if HAVE(DISPATCH_H)
- ~ThreadRestrictionVerifier()
- {
- if (m_owningQueue)
- dispatch_release(m_owningQueue);
- }
-#endif
-
- void setMutexMode(Mutex& mutex)
- {
- m_mode = MutexVerificationMode;
- m_mutex = &mutex;
- }
-
-#if HAVE(DISPATCH_H)
- void setDispatchQueueMode(dispatch_queue_t queue)
- {
- m_mode = SingleDispatchQueueVerificationMode;
- m_owningQueue = queue;
- dispatch_retain(m_owningQueue);
- }
-#endif
-
- void turnOffVerification()
- {
- m_mode = NoVerificationMode;
- }
-
- // Indicates that the object may (or may not) be owned by more than one place.
- void setShared(bool shared)
- {
-#if !ASSERT_DISABLED
- bool previouslyShared = m_shared;
-#endif
- m_shared = shared;
-
- if (!m_shared)
- return;
-
- switch (m_mode) {
- case SingleThreadVerificationMode:
- ASSERT(shared != previouslyShared);
- // Capture the current thread to verify that subsequent ref/deref happen on this thread.
- m_owningThread = currentThread();
- return;
-
-#if HAVE(DISPATCH_H)
- case SingleDispatchQueueVerificationMode:
-#endif
- case MutexVerificationMode:
- case NoVerificationMode:
- return;
- }
- ASSERT_NOT_REACHED();
- }
-
- // Is it OK to use the object at this moment on the current thread?
- bool isSafeToUse() const
- {
- if (!m_shared)
- return true;
-
- switch (m_mode) {
- case SingleThreadVerificationMode:
- return m_owningThread == currentThread();
-
- case MutexVerificationMode:
- if (!m_mutex->tryLock())
- return true;
- m_mutex->unlock();
- return false;
-
-#if HAVE(DISPATCH_H)
- case SingleDispatchQueueVerificationMode:
- return m_owningQueue == dispatch_get_current_queue();
-#endif
-
- case NoVerificationMode:
- return true;
- }
- ASSERT_NOT_REACHED();
- return true;
- }
-
-private:
- enum VerificationMode {
- SingleThreadVerificationMode,
- MutexVerificationMode,
- NoVerificationMode,
-#if HAVE(DISPATCH_H)
- SingleDispatchQueueVerificationMode,
-#endif
- };
-
- VerificationMode m_mode;
- bool m_shared;
-
- // Used by SingleThreadVerificationMode
- ThreadIdentifier m_owningThread;
-
- // Used by MutexVerificationMode.
- Mutex* m_mutex;
-
-#if HAVE(DISPATCH_H)
- // Used by SingleDispatchQueueVerificationMode.
- dispatch_queue_t m_owningQueue;
-#endif
-};
-#else // !USE(JSC) => so the JSC case
-class ThreadRestrictionVerifier {
-public:
- ThreadRestrictionVerifier()
- {
- }
-
- void setMutexMode(Mutex&)
- {
- }
-
-#if HAVE(DISPATCH_H)
- void setDispatchQueueMode(dispatch_queue_t)
- {
- }
-#endif
-
- void turnOffVerification()
- {
- }
-
- // Indicates that the object may (or may not) be owned by more than one place.
- void setShared(bool)
- {
- }
-
- // Is it OK to use the object at this moment on the current thread?
- bool isSafeToUse() const
- {
- return true;
- }
-};
-#endif
-
-}
-
-#endif
-#endif
+++ /dev/null
-/*
- * Copyright (C) 2007, 2008, 2010 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 ThreadSafeRefCounted_h
-#define ThreadSafeRefCounted_h
-
-#include <wtf/Platform.h>
-
-#include <wtf/Atomics.h>
-#include <wtf/DynamicAnnotations.h>
-#include <wtf/ThreadingPrimitives.h>
-
-namespace WTF {
-
-class ThreadSafeRefCountedBase {
- WTF_MAKE_NONCOPYABLE(ThreadSafeRefCountedBase);
- WTF_MAKE_FAST_ALLOCATED;
-public:
- ThreadSafeRefCountedBase(int initialRefCount = 1)
- : m_refCount(initialRefCount)
- {
- }
-
- void ref()
- {
-#if USE(LOCKFREE_THREADSAFEREFCOUNTED)
- atomicIncrement(&m_refCount);
-#else
- MutexLocker locker(m_mutex);
- ++m_refCount;
-#endif
- }
-
- bool hasOneRef()
- {
- return refCount() == 1;
- }
-
- int refCount() const
- {
-#if !USE(LOCKFREE_THREADSAFEREFCOUNTED)
- MutexLocker locker(m_mutex);
-#endif
- return static_cast<int const volatile &>(m_refCount);
- }
-
-protected:
- // Returns whether the pointer should be freed or not.
- bool derefBase()
- {
-#if USE(LOCKFREE_THREADSAFEREFCOUNTED)
- WTF_ANNOTATE_HAPPENS_BEFORE(&m_refCount);
- if (atomicDecrement(&m_refCount) <= 0) {
- WTF_ANNOTATE_HAPPENS_AFTER(&m_refCount);
- return true;
- }
-#else
- int refCount;
- {
- MutexLocker locker(m_mutex);
- --m_refCount;
- refCount = m_refCount;
- }
- if (refCount <= 0)
- return true;
-#endif
- return false;
- }
-
-private:
- int m_refCount;
-#if !USE(LOCKFREE_THREADSAFEREFCOUNTED)
- mutable Mutex m_mutex;
-#endif
-};
-
-template<class T> class ThreadSafeRefCounted : public ThreadSafeRefCountedBase {
-public:
- void deref()
- {
- if (derefBase())
- delete static_cast<T*>(this);
- }
-
-protected:
- ThreadSafeRefCounted()
- {
- }
-};
-
-} // namespace WTF
-
-using WTF::ThreadSafeRefCounted;
-
-#endif // ThreadSafeRefCounted_h
+++ /dev/null
-/*
- * Copyright (C) 2007, 2008, 2010 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/Platform.h>
-
-#include <stdint.h>
-#include <wtf/Assertions.h>
-#include <wtf/Atomics.h>
-#include <wtf/Locker.h>
-#include <wtf/Noncopyable.h>
-#include <wtf/ThreadSafeRefCounted.h>
-#include <wtf/ThreadingPrimitives.h>
-
-// For portability, we do not use thread-safe statics natively supported by some compilers (e.g. gcc).
-#define AtomicallyInitializedStatic(T, name) \
- WTF::lockAtomicallyInitializedStaticMutex(); \
- static T name; \
- WTF::unlockAtomicallyInitializedStaticMutex();
-
-namespace WTF {
-
-typedef uint32_t ThreadIdentifier;
-typedef void (*ThreadFunction)(void* argument);
-
-// This function must be called from the main thread. It is safe to call it repeatedly.
-// Darwin is an exception to this rule: it is OK to call it from any thread, the only
-// requirement is that the calls are not reentrant.
-WTF_EXPORT_PRIVATE void initializeThreading();
-
-// Returns 0 if thread creation failed.
-// The thread name must be a literal since on some platforms it's passed in to the thread.
-WTF_EXPORT_PRIVATE ThreadIdentifier createThread(ThreadFunction, void*, const char* threadName);
-
-// Internal platform-specific createThread implementation.
-ThreadIdentifier createThreadInternal(ThreadFunction, void*, const char* threadName);
-
-// Called in the thread during initialization.
-// Helpful for platforms where the thread name must be set from within the thread.
-void initializeCurrentThreadInternal(const char* threadName);
-
-WTF_EXPORT_PRIVATE ThreadIdentifier currentThread();
-WTF_EXPORT_PRIVATE int waitForThreadCompletion(ThreadIdentifier);
-WTF_EXPORT_PRIVATE void detachThread(ThreadIdentifier);
-
-WTF_EXPORT_PRIVATE void yield();
-
-WTF_EXPORT_PRIVATE void lockAtomicallyInitializedStaticMutex();
-WTF_EXPORT_PRIVATE void unlockAtomicallyInitializedStaticMutex();
-
-} // namespace WTF
-
-using WTF::ThreadIdentifier;
-using WTF::createThread;
-using WTF::currentThread;
-using WTF::detachThread;
-using WTF::waitForThreadCompletion;
-using WTF::yield;
-
-#endif // Threading_h
+++ /dev/null
-/*
- * Copyright (C) 2007, 2008, 2010 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.
- *
- */
-
-#ifndef ThreadingPrimitives_h
-#define ThreadingPrimitives_h
-
-#include <wtf/Platform.h>
-
-#include <wtf/Assertions.h>
-#include <wtf/FastAllocBase.h>
-#include <wtf/Locker.h>
-#include <wtf/Noncopyable.h>
-
-#if OS(WINDOWS)
-#include <windows.h>
-#endif
-
-#if USE(PTHREADS)
-#include <pthread.h>
-#endif
-
-namespace WTF {
-
-#if USE(PTHREADS)
-typedef pthread_mutex_t PlatformMutex;
-typedef pthread_cond_t PlatformCondition;
-#elif OS(WINDOWS)
-struct PlatformMutex {
- CRITICAL_SECTION m_internalMutex;
- size_t m_recursionCount;
-};
-struct PlatformCondition {
- size_t m_waitersGone;
- size_t m_waitersBlocked;
- size_t m_waitersToUnblock;
- HANDLE m_blockLock;
- HANDLE m_blockQueue;
- HANDLE m_unblockLock;
-
- bool timedWait(PlatformMutex&, DWORD durationMilliseconds);
- void signal(bool unblockAll);
-};
-#else
-typedef void* PlatformMutex;
-typedef void* PlatformCondition;
-#endif
-
-class Mutex {
- WTF_MAKE_NONCOPYABLE(Mutex); WTF_MAKE_FAST_ALLOCATED;
-public:
- WTF_EXPORT_PRIVATE Mutex();
- WTF_EXPORT_PRIVATE ~Mutex();
-
- WTF_EXPORT_PRIVATE void lock();
- WTF_EXPORT_PRIVATE bool tryLock();
- WTF_EXPORT_PRIVATE void unlock();
-
-public:
- PlatformMutex& impl() { return m_mutex; }
-private:
- PlatformMutex m_mutex;
-};
-
-typedef Locker<Mutex> MutexLocker;
-
-class MutexTryLocker {
- WTF_MAKE_NONCOPYABLE(MutexTryLocker);
-public:
- MutexTryLocker(Mutex& mutex) : m_mutex(mutex), m_locked(mutex.tryLock()) { }
- ~MutexTryLocker()
- {
- if (m_locked)
- m_mutex.unlock();
- }
-
- bool locked() const { return m_locked; }
-
-private:
- Mutex& m_mutex;
- bool m_locked;
-};
-
-class ThreadCondition {
- WTF_MAKE_NONCOPYABLE(ThreadCondition);
-public:
- WTF_EXPORT_PRIVATE ThreadCondition();
- WTF_EXPORT_PRIVATE ~ThreadCondition();
-
- WTF_EXPORT_PRIVATE void wait(Mutex& mutex);
- // Returns true if the condition was signaled before absoluteTime, false if the absoluteTime was reached or is in the past.
- // The absoluteTime is in seconds, starting on January 1, 1970. The time is assumed to use the same time zone as WTF::currentTime().
- WTF_EXPORT_PRIVATE bool timedWait(Mutex&, double absoluteTime);
- WTF_EXPORT_PRIVATE void signal();
- WTF_EXPORT_PRIVATE void broadcast();
-
-private:
- PlatformCondition m_condition;
-};
-
-#if OS(WINDOWS)
-// The absoluteTime is in seconds, starting on January 1, 1970. The time is assumed to use the same time zone as WTF::currentTime().
-// Returns an interval in milliseconds suitable for passing to one of the Win32 wait functions (e.g., ::WaitForSingleObject).
-WTF_EXPORT_PRIVATE DWORD absoluteTimeToWaitTimeoutInterval(double absoluteTime);
-#endif
-
-} // namespace WTF
-
-using WTF::Mutex;
-using WTF::MutexLocker;
-using WTF::MutexTryLocker;
-using WTF::ThreadCondition;
-
-#if OS(WINDOWS)
-using WTF::absoluteTimeToWaitTimeoutInterval;
-#endif
-
-#endif // ThreadingPrimitives_h