Skip to content

Commit

Permalink
Asynchronous component instantiation
Browse files Browse the repository at this point in the history
This introduces two main:

    * the QML compiler executes in a separate thread
    * item instantiation can be interrupted and resumed to
      allow it to be split across multiple frames.

Task-number: QTBUG-21151
Change-Id: I9631c62bb77da3a2e0c37f0da3719533fdce4fef
Reviewed-on: http://codereview.qt-project.org/5676
Reviewed-by: Martin Jones <martin.jones@nokia.com>
  • Loading branch information
Aaron Kennedy authored and Qt by Nokia committed Sep 29, 2011
1 parent 600e56a commit 703c808
Show file tree
Hide file tree
Showing 46 changed files with 3,807 additions and 1,094 deletions.
4 changes: 3 additions & 1 deletion src/declarative/qml/ftw/ftw.pri
Expand Up @@ -11,12 +11,14 @@ HEADERS += \
$$PWD/qfieldlist_p.h \
$$PWD/qfastmetabuilder_p.h \
$$PWD/qhashfield_p.h \
$$PWD/qdeclarativethread_p.h \
$$PWD/qfinitestack_p.h \

SOURCES += \
$$PWD/qintrusivelist.cpp \
$$PWD/qmetaobjectbuilder.cpp \
$$PWD/qhashedstring.cpp \
$$PWD/qdeclarativerefcount.cpp \
$$PWD/qdeclarativepool.cpp \
$$PWD/qfastmetabuilder.cpp \
$$PWD/qdeclarativethread.cpp \

58 changes: 52 additions & 6 deletions src/declarative/qml/ftw/qdeclarativerefcount_p.h
Expand Up @@ -54,23 +54,27 @@
//

#include <QtCore/qglobal.h>
#include <QtCore/qatomic.h>

QT_BEGIN_HEADER

QT_BEGIN_NAMESPACE

QT_MODULE(Declarative)

class Q_DECLARATIVE_EXPORT QDeclarativeRefCount
class QDeclarativeRefCount
{
public:
QDeclarativeRefCount();
virtual ~QDeclarativeRefCount();
void addref();
void release();
inline QDeclarativeRefCount();
inline virtual ~QDeclarativeRefCount();
inline void addref();
inline void release();

protected:
inline virtual void destroy();

private:
int refCount;
QAtomicInt refCount;
};

template<class T>
Expand All @@ -92,10 +96,40 @@ class QDeclarativeRefPointer
inline operator T*() const { return o; }
inline T* data() const { return o; }

inline QDeclarativeRefPointer<T> &take(T *);

private:
T *o;
};

QDeclarativeRefCount::QDeclarativeRefCount()
: refCount(1)
{
}

QDeclarativeRefCount::~QDeclarativeRefCount()
{
Q_ASSERT(refCount == 0);
}

void QDeclarativeRefCount::addref()
{
Q_ASSERT(refCount > 0);
refCount.ref();
}

void QDeclarativeRefCount::release()
{
Q_ASSERT(refCount > 0);
if (!refCount.deref())
destroy();
}

void QDeclarativeRefCount::destroy()
{
delete this;
}

template<class T>
QDeclarativeRefPointer<T>::QDeclarativeRefPointer()
: o(0)
Expand Down Expand Up @@ -140,6 +174,18 @@ QDeclarativeRefPointer<T> &QDeclarativeRefPointer<T>::operator=(T *other)
return *this;
}

/*!
Takes ownership of \a other. take() does *not* add a reference, as it assumes ownership
of the callers reference of other.
*/
template<class T>
QDeclarativeRefPointer<T> &QDeclarativeRefPointer<T>::take(T *other)
{
if (o) o->release();
o = other;
return *this;
}

QT_END_NAMESPACE

QT_END_HEADER
Expand Down

0 comments on commit 703c808

Please sign in to comment.