Move QtConcurrent::Exception as QException back to QtCore
Leave the old name as a deprecated typedef; adapt users. This is a prerequisite for moving QFuture back to QtCore. Change-Id: I81dcee2c7e6eb234c16f3f42e2415ca0da3dc4f8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
5414a9a03b
commit
3a29976eac
3
dist/changes-5.0.0
vendored
3
dist/changes-5.0.0
vendored
@ -563,6 +563,9 @@ QtConcurrent
|
|||||||
QT += concurrent
|
QT += concurrent
|
||||||
to include the new library.
|
to include the new library.
|
||||||
|
|
||||||
|
* QtConcurrent::Exception has been renamed to QException, and is still in QtCore.
|
||||||
|
Ditto QtConcurrent::UnhandledException.
|
||||||
|
|
||||||
QtOpenGL
|
QtOpenGL
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ SOURCES += \
|
|||||||
qtconcurrentresultstore.cpp \
|
qtconcurrentresultstore.cpp \
|
||||||
qtconcurrentthreadengine.cpp \
|
qtconcurrentthreadengine.cpp \
|
||||||
qtconcurrentiteratekernel.cpp \
|
qtconcurrentiteratekernel.cpp \
|
||||||
qtconcurrentexception.cpp
|
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
qtconcurrent_global.h \
|
qtconcurrent_global.h \
|
||||||
|
@ -238,7 +238,7 @@ void QFutureInterfaceBase::reportCanceled()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef QT_NO_EXCEPTIONS
|
#ifndef QT_NO_EXCEPTIONS
|
||||||
void QFutureInterfaceBase::reportException(const QtConcurrent::Exception &exception)
|
void QFutureInterfaceBase::reportException(const QException &exception)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&d->m_mutex);
|
QMutexLocker locker(&d->m_mutex);
|
||||||
if ((d->state & Canceled) || (d->state & Finished))
|
if ((d->state & Canceled) || (d->state & Finished))
|
||||||
@ -390,7 +390,7 @@ QMutex *QFutureInterfaceBase::mutex() const
|
|||||||
return &d->m_mutex;
|
return &d->m_mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
QtConcurrent::internal::ExceptionStore &QFutureInterfaceBase::exceptionStore()
|
QtPrivate::ExceptionStore &QFutureInterfaceBase::exceptionStore()
|
||||||
{
|
{
|
||||||
return d->m_exceptionStore;
|
return d->m_exceptionStore;
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
#ifndef QT_NO_QFUTURE
|
#ifndef QT_NO_QFUTURE
|
||||||
|
|
||||||
#include <QtCore/qmutex.h>
|
#include <QtCore/qmutex.h>
|
||||||
#include <QtConcurrent/qtconcurrentexception.h>
|
#include <QtCore/qexception.h>
|
||||||
#include <QtConcurrent/qtconcurrentresultstore.h>
|
#include <QtConcurrent/qtconcurrentresultstore.h>
|
||||||
|
|
||||||
QT_BEGIN_HEADER
|
QT_BEGIN_HEADER
|
||||||
@ -83,7 +83,7 @@ public:
|
|||||||
void reportFinished();
|
void reportFinished();
|
||||||
void reportCanceled();
|
void reportCanceled();
|
||||||
#ifndef QT_NO_EXCEPTIONS
|
#ifndef QT_NO_EXCEPTIONS
|
||||||
void reportException(const QtConcurrent::Exception &e);
|
void reportException(const QException &e);
|
||||||
#endif
|
#endif
|
||||||
void reportResultsReady(int beginIndex, int endIndex);
|
void reportResultsReady(int beginIndex, int endIndex);
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ public:
|
|||||||
void waitForResume();
|
void waitForResume();
|
||||||
|
|
||||||
QMutex *mutex() const;
|
QMutex *mutex() const;
|
||||||
QtConcurrent::internal::ExceptionStore &exceptionStore();
|
QtPrivate::ExceptionStore &exceptionStore();
|
||||||
QtConcurrent::ResultStoreBase &resultStoreBase();
|
QtConcurrent::ResultStoreBase &resultStoreBase();
|
||||||
const QtConcurrent::ResultStoreBase &resultStoreBase() const;
|
const QtConcurrent::ResultStoreBase &resultStoreBase() const;
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ public:
|
|||||||
QtConcurrent::ResultStoreBase m_results;
|
QtConcurrent::ResultStoreBase m_results;
|
||||||
bool manualProgress;
|
bool manualProgress;
|
||||||
int m_expectedResultCount;
|
int m_expectedResultCount;
|
||||||
QtConcurrent::internal::ExceptionStore m_exceptionStore;
|
QtPrivate::ExceptionStore m_exceptionStore;
|
||||||
QString m_progressText;
|
QString m_progressText;
|
||||||
QRunnable *runnable;
|
QRunnable *runnable;
|
||||||
|
|
||||||
|
@ -46,12 +46,7 @@
|
|||||||
|
|
||||||
#ifndef QT_NO_QFUTURE
|
#ifndef QT_NO_QFUTURE
|
||||||
|
|
||||||
#include <QtCore/qatomic.h>
|
#include <QtCore/qexception.h>
|
||||||
#include <QtCore/qshareddata.h>
|
|
||||||
|
|
||||||
#ifndef QT_NO_EXCEPTIONS
|
|
||||||
# include <exception>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QT_BEGIN_HEADER
|
QT_BEGIN_HEADER
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@ -62,59 +57,8 @@ namespace QtConcurrent
|
|||||||
|
|
||||||
#ifndef QT_NO_EXCEPTIONS
|
#ifndef QT_NO_EXCEPTIONS
|
||||||
|
|
||||||
class Q_CONCURRENT_EXPORT Exception : public std::exception
|
typedef Q_DECL_DEPRECATED QException Exception;
|
||||||
{
|
typedef Q_DECL_DEPRECATED QUnhandledException UnhandledException;
|
||||||
public:
|
|
||||||
virtual void raise() const;
|
|
||||||
virtual Exception *clone() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Q_CONCURRENT_EXPORT UnhandledException : public Exception
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void raise() const;
|
|
||||||
Exception *clone() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
class Base;
|
|
||||||
class ExceptionHolder
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ExceptionHolder(Exception *exception = 0);
|
|
||||||
ExceptionHolder(const ExceptionHolder &other);
|
|
||||||
void operator=(const ExceptionHolder &other);
|
|
||||||
~ExceptionHolder();
|
|
||||||
Exception *exception() const;
|
|
||||||
QExplicitlySharedDataPointer<Base> base;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Q_CONCURRENT_EXPORT ExceptionStore
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void setException(const Exception &e);
|
|
||||||
bool hasException() const;
|
|
||||||
ExceptionHolder exception();
|
|
||||||
void throwPossibleException();
|
|
||||||
bool hasThrown() const;
|
|
||||||
ExceptionHolder exceptionHolder;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace internal
|
|
||||||
|
|
||||||
#else // QT_NO_EXCEPTIONS
|
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
class Q_CONCURRENT_EXPORT ExceptionStore
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ExceptionStore() { }
|
|
||||||
inline void throwPossibleException() const {}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace internal
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -123,6 +67,6 @@ public:
|
|||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
QT_END_HEADER
|
QT_END_HEADER
|
||||||
|
|
||||||
#endif // QT_NO_CONCURRENT
|
#endif // QT_NO_QFUTURE
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -54,14 +54,6 @@
|
|||||||
\ingroup thread
|
\ingroup thread
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
|
||||||
\namespace QtConcurrent::internal
|
|
||||||
\internal
|
|
||||||
|
|
||||||
\brief The QtConcurrent::internal namespace contains QtConcurrent
|
|
||||||
implementation details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\enum QtConcurrent::ReduceOption
|
\enum QtConcurrent::ReduceOption
|
||||||
This enum specifies the order of which results from the map or filter
|
This enum specifies the order of which results from the map or filter
|
||||||
|
@ -104,10 +104,10 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
this->runFunctor();
|
this->runFunctor();
|
||||||
#ifndef QT_NO_EXCEPTIONS
|
#ifndef QT_NO_EXCEPTIONS
|
||||||
} catch (QtConcurrent::Exception &e) {
|
} catch (QException &e) {
|
||||||
QFutureInterface<T>::reportException(e);
|
QFutureInterface<T>::reportException(e);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
QFutureInterface<T>::reportException(QtConcurrent::UnhandledException());
|
QFutureInterface<T>::reportException(QUnhandledException());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -132,10 +132,10 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
this->runFunctor();
|
this->runFunctor();
|
||||||
#ifndef QT_NO_EXCEPTIONS
|
#ifndef QT_NO_EXCEPTIONS
|
||||||
} catch (QtConcurrent::Exception &e) {
|
} catch (QException &e) {
|
||||||
QFutureInterface<void>::reportException(e);
|
QFutureInterface<void>::reportException(e);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
QFutureInterface<void>::reportException(QtConcurrent::UnhandledException());
|
QFutureInterface<void>::reportException(QUnhandledException());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
this->reportFinished();
|
this->reportFinished();
|
||||||
|
@ -155,10 +155,10 @@ void ThreadEngineBase::startBlocking()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifndef QT_NO_EXCEPTIONS
|
#ifndef QT_NO_EXCEPTIONS
|
||||||
} catch (QtConcurrent::Exception &e) {
|
} catch (QException &e) {
|
||||||
handleException(e);
|
handleException(e);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
handleException(QtConcurrent::UnhandledException());
|
handleException(QUnhandledException());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -271,10 +271,10 @@ void ThreadEngineBase::run() // implements QRunnable.
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef QT_NO_EXCEPTIONS
|
#ifndef QT_NO_EXCEPTIONS
|
||||||
} catch (QtConcurrent::Exception &e) {
|
} catch (QException &e) {
|
||||||
handleException(e);
|
handleException(e);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
handleException(QtConcurrent::UnhandledException());
|
handleException(QUnhandledException());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
threadExit();
|
threadExit();
|
||||||
@ -282,7 +282,7 @@ void ThreadEngineBase::run() // implements QRunnable.
|
|||||||
|
|
||||||
#ifndef QT_NO_EXCEPTIONS
|
#ifndef QT_NO_EXCEPTIONS
|
||||||
|
|
||||||
void ThreadEngineBase::handleException(const QtConcurrent::Exception &exception)
|
void ThreadEngineBase::handleException(const QException &exception)
|
||||||
{
|
{
|
||||||
if (futureInterface)
|
if (futureInterface)
|
||||||
futureInterface->reportException(exception);
|
futureInterface->reportException(exception);
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
#include <QtCore/qthreadpool.h>
|
#include <QtCore/qthreadpool.h>
|
||||||
#include <QtConcurrent/qfuture.h>
|
#include <QtConcurrent/qfuture.h>
|
||||||
#include <QtCore/qdebug.h>
|
#include <QtCore/qdebug.h>
|
||||||
#include <QtConcurrent/qtconcurrentexception.h>
|
#include <QtCore/qexception.h>
|
||||||
#include <QtCore/qwaitcondition.h>
|
#include <QtCore/qwaitcondition.h>
|
||||||
#include <QtCore/qatomic.h>
|
#include <QtCore/qatomic.h>
|
||||||
#include <QtCore/qsemaphore.h>
|
#include <QtCore/qsemaphore.h>
|
||||||
@ -119,13 +119,13 @@ private:
|
|||||||
void run();
|
void run();
|
||||||
virtual void asynchronousFinish() = 0;
|
virtual void asynchronousFinish() = 0;
|
||||||
#ifndef QT_NO_EXCEPTIONS
|
#ifndef QT_NO_EXCEPTIONS
|
||||||
void handleException(const QtConcurrent::Exception &exception);
|
void handleException(const QException &exception);
|
||||||
#endif
|
#endif
|
||||||
protected:
|
protected:
|
||||||
QFutureInterfaceBase *futureInterface;
|
QFutureInterfaceBase *futureInterface;
|
||||||
QThreadPool *threadPool;
|
QThreadPool *threadPool;
|
||||||
ThreadEngineBarrier barrier;
|
ThreadEngineBarrier barrier;
|
||||||
QtConcurrent::internal::ExceptionStore exceptionStore;
|
QtPrivate::ExceptionStore exceptionStore;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,11 +40,11 @@
|
|||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
class MyException : public QtConcurrent::Exception
|
class MyException : public QException
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void raise() const { throw *this; }
|
void raise() const { throw *this; }
|
||||||
Exception *clone() const { return new MyException(*this); }
|
MyException *clone() const { return new MyException(*this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
@ -39,7 +39,7 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "qtconcurrentexception.h"
|
#include "qexception.h"
|
||||||
#include "QtCore/qshareddata.h"
|
#include "QtCore/qshareddata.h"
|
||||||
|
|
||||||
#ifndef QT_NO_QFUTURE
|
#ifndef QT_NO_QFUTURE
|
||||||
@ -48,23 +48,23 @@
|
|||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class QtConcurrent::Exception
|
\class QException
|
||||||
\brief The Exception class provides a base class for exceptions that can transferred across threads.
|
\brief The QException class provides a base class for exceptions that can transferred across threads.
|
||||||
\since 4.4
|
\since 5.0
|
||||||
|
|
||||||
Qt Concurrent supports throwing and catching exceptions across thread
|
Qt Concurrent supports throwing and catching exceptions across thread
|
||||||
boundaries, provided that the exception inherit from QtConcurrent::Exception
|
boundaries, provided that the exception inherit from QException
|
||||||
and implement two helper functions:
|
and implement two helper functions:
|
||||||
|
|
||||||
\snippet code/src_concurrent_qtconcurrentexception.cpp 0
|
\snippet code/src_corelib_thread_qexception.cpp 0
|
||||||
|
|
||||||
QtConcurrent::Exception subclasses must be thrown by value and
|
QException subclasses must be thrown by value and
|
||||||
caught by reference:
|
caught by reference:
|
||||||
|
|
||||||
\snippet code/src_concurrent_qtconcurrentexception.cpp 1
|
\snippet code/src_corelib_thread_qexception.cpp 1
|
||||||
|
|
||||||
If you throw an exception that is not a subclass of QtConcurrent::Exception,
|
If you throw an exception that is not a subclass of QException,
|
||||||
the Qt Concurrent functions will throw a QtConcurrent::UnhandledException
|
the Qt functions will throw a QUnhandledException
|
||||||
in the receiver thread.
|
in the receiver thread.
|
||||||
|
|
||||||
When using QFuture, transferred exceptions will be thrown when calling the following functions:
|
When using QFuture, transferred exceptions will be thrown when calling the following functions:
|
||||||
@ -77,83 +77,80 @@ QT_BEGIN_NAMESPACE
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn QtConcurrent::Exception::raise() const
|
\fn QException::raise() const
|
||||||
In your QtConcurrent::Exception subclass, reimplement raise() like this:
|
In your QException subclass, reimplement raise() like this:
|
||||||
|
|
||||||
\snippet code/src_concurrent_qtconcurrentexception.cpp 2
|
\snippet code/src_corelib_thread_qexception.cpp 2
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn QtConcurrent::Exception::clone() const
|
\fn QException::clone() const
|
||||||
In your QtConcurrent::Exception subclass, reimplement clone() like this:
|
In your QException subclass, reimplement clone() like this:
|
||||||
|
|
||||||
\snippet code/src_concurrent_qtconcurrentexception.cpp 3
|
\snippet code/src_corelib_thread_qexception.cpp 3
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class QtConcurrent::UnhandledException
|
\class QUnhandledException
|
||||||
|
|
||||||
\brief The UnhandledException class represents an unhandled exception in a worker thread.
|
\brief The UnhandledException class represents an unhandled exception in a worker thread.
|
||||||
\since 4.4
|
\since 5.0
|
||||||
|
|
||||||
If a worker thread throws an exception that is not a subclass of QtConcurrent::Exception,
|
If a worker thread throws an exception that is not a subclass of QException,
|
||||||
the Qt Concurrent functions will throw a QtConcurrent::UnhandledException
|
the Qt functions will throw a QUnhandledException
|
||||||
on the receiver thread side.
|
on the receiver thread side.
|
||||||
|
|
||||||
Inheriting from this class is not supported.
|
Inheriting from this class is not supported.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn QtConcurrent::UnhandledException::raise() const
|
\fn QUnhandledException::raise() const
|
||||||
\internal
|
\internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn QtConcurrent::UnhandledException::clone() const
|
\fn QUnhandledException::clone() const
|
||||||
\internal
|
\internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace QtConcurrent
|
void QException::raise() const
|
||||||
{
|
{
|
||||||
|
QException e = *this;
|
||||||
void Exception::raise() const
|
|
||||||
{
|
|
||||||
Exception e = *this;
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
Exception *Exception::clone() const
|
QException *QException::clone() const
|
||||||
{
|
{
|
||||||
return new Exception(*this);
|
return new QException(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnhandledException::raise() const
|
void QUnhandledException::raise() const
|
||||||
{
|
{
|
||||||
UnhandledException e = *this;
|
QUnhandledException e = *this;
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
Exception *UnhandledException::clone() const
|
QUnhandledException *QUnhandledException::clone() const
|
||||||
{
|
{
|
||||||
return new UnhandledException(*this);
|
return new QUnhandledException(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef qdoc
|
#ifndef qdoc
|
||||||
|
|
||||||
namespace internal {
|
namespace QtPrivate {
|
||||||
|
|
||||||
class Base : public QSharedData
|
class Base : public QSharedData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Base(Exception *exception)
|
Base(QException *exception)
|
||||||
: exception(exception), hasThrown(false) { }
|
: exception(exception), hasThrown(false) { }
|
||||||
~Base() { delete exception; }
|
~Base() { delete exception; }
|
||||||
|
|
||||||
Exception *exception;
|
QException *exception;
|
||||||
bool hasThrown;
|
bool hasThrown;
|
||||||
};
|
};
|
||||||
|
|
||||||
ExceptionHolder::ExceptionHolder(Exception *exception)
|
ExceptionHolder::ExceptionHolder(QException *exception)
|
||||||
: base(new Base(exception)) {}
|
: base(new Base(exception)) {}
|
||||||
|
|
||||||
ExceptionHolder::ExceptionHolder(const ExceptionHolder &other)
|
ExceptionHolder::ExceptionHolder(const ExceptionHolder &other)
|
||||||
@ -168,12 +165,12 @@ void ExceptionHolder::operator=(const ExceptionHolder &other)
|
|||||||
ExceptionHolder::~ExceptionHolder()
|
ExceptionHolder::~ExceptionHolder()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Exception *ExceptionHolder::exception() const
|
QException *ExceptionHolder::exception() const
|
||||||
{
|
{
|
||||||
return base->exception;
|
return base->exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExceptionStore::setException(const Exception &e)
|
void ExceptionStore::setException(const QException &e)
|
||||||
{
|
{
|
||||||
if (hasException() == false)
|
if (hasException() == false)
|
||||||
exceptionHolder = ExceptionHolder(e.clone());
|
exceptionHolder = ExceptionHolder(e.clone());
|
||||||
@ -199,13 +196,11 @@ void ExceptionStore::throwPossibleException()
|
|||||||
|
|
||||||
bool ExceptionStore::hasThrown() const { return exceptionHolder.base->hasThrown; }
|
bool ExceptionStore::hasThrown() const { return exceptionHolder.base->hasThrown; }
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace QtPrivate
|
||||||
|
|
||||||
#endif //qdoc
|
#endif //qdoc
|
||||||
|
|
||||||
} // namespace QtConcurrent
|
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
#endif // QT_NO_EXCEPTIONS
|
#endif // QT_NO_EXCEPTIONS
|
||||||
#endif // QT_NO_CONCURRENT
|
#endif // QT_NO_QFUTURE
|
123
src/corelib/thread/qexception.h
Normal file
123
src/corelib/thread/qexception.h
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** Contact: http://www.qt-project.org/legal
|
||||||
|
**
|
||||||
|
** This file is part of the QtCore 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 QTCORE_QEXCEPTION_H
|
||||||
|
#define QTCORE_QEXCEPTION_H
|
||||||
|
|
||||||
|
#include <QtCore/qglobal.h>
|
||||||
|
|
||||||
|
#ifndef QT_NO_QFUTURE
|
||||||
|
|
||||||
|
#include <QtCore/qatomic.h>
|
||||||
|
#include <QtCore/qshareddata.h>
|
||||||
|
|
||||||
|
#ifndef QT_NO_EXCEPTIONS
|
||||||
|
# include <exception>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QT_BEGIN_HEADER
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef QT_NO_EXCEPTIONS
|
||||||
|
|
||||||
|
class Q_CORE_EXPORT QException : public std::exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void raise() const;
|
||||||
|
virtual QException *clone() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Q_CORE_EXPORT QUnhandledException : public QException
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void raise() const;
|
||||||
|
QUnhandledException *clone() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace QtPrivate {
|
||||||
|
|
||||||
|
class Base;
|
||||||
|
class Q_CORE_EXPORT ExceptionHolder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ExceptionHolder(QException *exception = 0);
|
||||||
|
ExceptionHolder(const ExceptionHolder &other);
|
||||||
|
void operator=(const ExceptionHolder &other);
|
||||||
|
~ExceptionHolder();
|
||||||
|
QException *exception() const;
|
||||||
|
QExplicitlySharedDataPointer<Base> base;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Q_CORE_EXPORT ExceptionStore
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void setException(const QException &e);
|
||||||
|
bool hasException() const;
|
||||||
|
ExceptionHolder exception();
|
||||||
|
void throwPossibleException();
|
||||||
|
bool hasThrown() const;
|
||||||
|
ExceptionHolder exceptionHolder;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace QtPrivate
|
||||||
|
|
||||||
|
#else // QT_NO_EXCEPTIONS
|
||||||
|
|
||||||
|
namespace QtPrivate {
|
||||||
|
|
||||||
|
class Q_CORE_EXPORT ExceptionStore
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ExceptionStore() { }
|
||||||
|
inline void throwPossibleException() const {}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace QtPrivate
|
||||||
|
|
||||||
|
#endif // QT_NO_EXCEPTIONS
|
||||||
|
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
QT_END_HEADER
|
||||||
|
|
||||||
|
#endif // QT_NO_QFUTURE
|
||||||
|
|
||||||
|
#endif
|
@ -10,6 +10,7 @@ HEADERS += thread/qmutex.h \
|
|||||||
thread/qthreadstorage.h \
|
thread/qthreadstorage.h \
|
||||||
thread/qwaitcondition.h \
|
thread/qwaitcondition.h \
|
||||||
thread/qatomic.h \
|
thread/qatomic.h \
|
||||||
|
thread/qexception.h \
|
||||||
thread/qbasicatomic.h \
|
thread/qbasicatomic.h \
|
||||||
thread/qgenericatomic.h \
|
thread/qgenericatomic.h \
|
||||||
thread/qoldbasicatomic.h
|
thread/qoldbasicatomic.h
|
||||||
@ -23,6 +24,7 @@ HEADERS += thread/qmutex_p.h \
|
|||||||
thread/qthreadpool_p.h
|
thread/qthreadpool_p.h
|
||||||
|
|
||||||
SOURCES += thread/qatomic.cpp \
|
SOURCES += thread/qatomic.cpp \
|
||||||
|
thread/qexception.cpp \
|
||||||
thread/qmutex.cpp \
|
thread/qmutex.cpp \
|
||||||
thread/qreadwritelock.cpp \
|
thread/qreadwritelock.cpp \
|
||||||
thread/qrunnable.cpp \
|
thread/qrunnable.cpp \
|
||||||
|
@ -1276,7 +1276,7 @@ QFuture<void> createExceptionFuture()
|
|||||||
i.reportStarted();
|
i.reportStarted();
|
||||||
QFuture<void> f = i.future();
|
QFuture<void> f = i.future();
|
||||||
|
|
||||||
Exception e;
|
QException e;
|
||||||
i.reportException(e);
|
i.reportException(e);
|
||||||
i.reportFinished();
|
i.reportFinished();
|
||||||
return f;
|
return f;
|
||||||
@ -1290,17 +1290,17 @@ QFuture<int> createExceptionResultFuture()
|
|||||||
int r = 0;
|
int r = 0;
|
||||||
i.reportResult(r);
|
i.reportResult(r);
|
||||||
|
|
||||||
Exception e;
|
QException e;
|
||||||
i.reportException(e);
|
i.reportException(e);
|
||||||
i.reportFinished();
|
i.reportFinished();
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DerivedException : public Exception
|
class DerivedException : public QException
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void raise() const { throw *this; }
|
void raise() const { throw *this; }
|
||||||
Exception *clone() const { return new DerivedException(*this); }
|
DerivedException *clone() const { return new DerivedException(*this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
QFuture<void> createDerivedExceptionFuture()
|
QFuture<void> createDerivedExceptionFuture()
|
||||||
@ -1323,7 +1323,7 @@ void tst_QFuture::exceptions()
|
|||||||
bool caught = false;
|
bool caught = false;
|
||||||
try {
|
try {
|
||||||
f.waitForFinished();
|
f.waitForFinished();
|
||||||
} catch (Exception &) {
|
} catch (QException &) {
|
||||||
caught = true;
|
caught = true;
|
||||||
}
|
}
|
||||||
QVERIFY(caught);
|
QVERIFY(caught);
|
||||||
@ -1335,7 +1335,7 @@ void tst_QFuture::exceptions()
|
|||||||
bool caught = false;
|
bool caught = false;
|
||||||
try {
|
try {
|
||||||
f.result();
|
f.result();
|
||||||
} catch (Exception &) {
|
} catch (QException &) {
|
||||||
caught = true;
|
caught = true;
|
||||||
}
|
}
|
||||||
QVERIFY(caught);
|
QVERIFY(caught);
|
||||||
@ -1346,7 +1346,7 @@ void tst_QFuture::exceptions()
|
|||||||
bool caught = false;
|
bool caught = false;
|
||||||
try {
|
try {
|
||||||
createExceptionResultFuture().result();
|
createExceptionResultFuture().result();
|
||||||
} catch (Exception &) {
|
} catch (QException &) {
|
||||||
caught = true;
|
caught = true;
|
||||||
}
|
}
|
||||||
QVERIFY(caught);
|
QVERIFY(caught);
|
||||||
@ -1358,7 +1358,7 @@ void tst_QFuture::exceptions()
|
|||||||
bool caught = false;
|
bool caught = false;
|
||||||
try {
|
try {
|
||||||
f.results();
|
f.results();
|
||||||
} catch (Exception &) {
|
} catch (QException &) {
|
||||||
caught = true;
|
caught = true;
|
||||||
}
|
}
|
||||||
QVERIFY(caught);
|
QVERIFY(caught);
|
||||||
@ -1373,7 +1373,7 @@ void tst_QFuture::exceptions()
|
|||||||
Q_UNUSED(e);
|
Q_UNUSED(e);
|
||||||
QFAIL("did not get exception");
|
QFAIL("did not get exception");
|
||||||
}
|
}
|
||||||
} catch (Exception &) {
|
} catch (QException &) {
|
||||||
caught = true;
|
caught = true;
|
||||||
}
|
}
|
||||||
QVERIFY(caught);
|
QVERIFY(caught);
|
||||||
@ -1384,7 +1384,7 @@ void tst_QFuture::exceptions()
|
|||||||
bool caught = false;
|
bool caught = false;
|
||||||
try {
|
try {
|
||||||
createDerivedExceptionFuture().waitForFinished();
|
createDerivedExceptionFuture().waitForFinished();
|
||||||
} catch (Exception &) {
|
} catch (QException &) {
|
||||||
caught = true;
|
caught = true;
|
||||||
}
|
}
|
||||||
QVERIFY(caught);
|
QVERIFY(caught);
|
||||||
@ -1409,7 +1409,7 @@ public:
|
|||||||
QFuture<void> f = createExceptionFuture();
|
QFuture<void> f = createExceptionFuture();
|
||||||
try {
|
try {
|
||||||
f.waitForFinished();
|
f.waitForFinished();
|
||||||
} catch (Exception &) {
|
} catch (QException &) {
|
||||||
caught = true;
|
caught = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2205,7 +2205,7 @@ void tst_QtConcurrentMap::throttling()
|
|||||||
void throwMapper(int &e)
|
void throwMapper(int &e)
|
||||||
{
|
{
|
||||||
Q_UNUSED(e);
|
Q_UNUSED(e);
|
||||||
throw QtConcurrent::Exception();
|
throw QException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QtConcurrentMap::exceptions()
|
void tst_QtConcurrentMap::exceptions()
|
||||||
@ -2214,7 +2214,7 @@ void tst_QtConcurrentMap::exceptions()
|
|||||||
try {
|
try {
|
||||||
QList<int> list = QList<int>() << 1 << 2 << 3;
|
QList<int> list = QList<int>() << 1 << 2 << 3;
|
||||||
QtConcurrent::map(list, throwMapper).waitForFinished();
|
QtConcurrent::map(list, throwMapper).waitForFinished();
|
||||||
} catch (const Exception &) {
|
} catch (const QException &) {
|
||||||
caught = true;
|
caught = true;
|
||||||
}
|
}
|
||||||
if (!caught)
|
if (!caught)
|
||||||
|
@ -367,12 +367,12 @@ int fn2(double, int *)
|
|||||||
#ifndef QT_NO_EXCEPTIONS
|
#ifndef QT_NO_EXCEPTIONS
|
||||||
void throwFunction()
|
void throwFunction()
|
||||||
{
|
{
|
||||||
throw QtConcurrent::Exception();
|
throw QException();
|
||||||
}
|
}
|
||||||
|
|
||||||
int throwFunctionReturn()
|
int throwFunctionReturn()
|
||||||
{
|
{
|
||||||
throw QtConcurrent::Exception();
|
throw QException();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,7 +381,7 @@ void tst_QtConcurrentRun::exceptions()
|
|||||||
bool caught = false;
|
bool caught = false;
|
||||||
try {
|
try {
|
||||||
QtConcurrent::run(throwFunction).waitForFinished();
|
QtConcurrent::run(throwFunction).waitForFinished();
|
||||||
} catch (Exception &) {
|
} catch (QException &) {
|
||||||
caught = true;
|
caught = true;
|
||||||
}
|
}
|
||||||
if (!caught)
|
if (!caught)
|
||||||
@ -390,7 +390,7 @@ void tst_QtConcurrentRun::exceptions()
|
|||||||
caught = false;
|
caught = false;
|
||||||
try {
|
try {
|
||||||
QtConcurrent::run(throwFunctionReturn).waitForFinished();
|
QtConcurrent::run(throwFunctionReturn).waitForFinished();
|
||||||
} catch (Exception &) {
|
} catch (QException &) {
|
||||||
caught = true;
|
caught = true;
|
||||||
}
|
}
|
||||||
if (!caught)
|
if (!caught)
|
||||||
|
@ -425,7 +425,7 @@ public:
|
|||||||
ThreadFunctionResult threadFunction()
|
ThreadFunctionResult threadFunction()
|
||||||
{
|
{
|
||||||
QTest::qSleep(50);
|
QTest::qSleep(50);
|
||||||
throw QtConcurrent::Exception();
|
throw QException();
|
||||||
return ThreadFinished;
|
return ThreadFinished;
|
||||||
}
|
}
|
||||||
QThread *blockThread;
|
QThread *blockThread;
|
||||||
@ -457,7 +457,7 @@ void tst_QtConcurrentThreadEngine::exceptions()
|
|||||||
QtConcurrentExceptionThrower *e = new QtConcurrentExceptionThrower();
|
QtConcurrentExceptionThrower *e = new QtConcurrentExceptionThrower();
|
||||||
QFuture<void> f = e->startAsynchronously();
|
QFuture<void> f = e->startAsynchronously();
|
||||||
f.waitForFinished();
|
f.waitForFinished();
|
||||||
} catch (const Exception &) {
|
} catch (const QException &) {
|
||||||
caught = true;
|
caught = true;
|
||||||
}
|
}
|
||||||
QVERIFY2(caught, "did not get exception");
|
QVERIFY2(caught, "did not get exception");
|
||||||
@ -470,7 +470,7 @@ void tst_QtConcurrentThreadEngine::exceptions()
|
|||||||
try {
|
try {
|
||||||
QtConcurrentExceptionThrower e(QThread::currentThread());
|
QtConcurrentExceptionThrower e(QThread::currentThread());
|
||||||
e.startBlocking();
|
e.startBlocking();
|
||||||
} catch (const Exception &) {
|
} catch (const QException &) {
|
||||||
caught = true;
|
caught = true;
|
||||||
}
|
}
|
||||||
QVERIFY2(caught, "did not get exception");
|
QVERIFY2(caught, "did not get exception");
|
||||||
@ -482,7 +482,7 @@ void tst_QtConcurrentThreadEngine::exceptions()
|
|||||||
try {
|
try {
|
||||||
QtConcurrentExceptionThrower e(0);
|
QtConcurrentExceptionThrower e(0);
|
||||||
e.startBlocking();
|
e.startBlocking();
|
||||||
} catch (const Exception &) {
|
} catch (const QException &) {
|
||||||
caught = true;
|
caught = true;
|
||||||
}
|
}
|
||||||
QVERIFY2(caught, "did not get exception");
|
QVERIFY2(caught, "did not get exception");
|
||||||
@ -495,7 +495,7 @@ void tst_QtConcurrentThreadEngine::exceptions()
|
|||||||
UnrelatedExceptionThrower *e = new UnrelatedExceptionThrower();
|
UnrelatedExceptionThrower *e = new UnrelatedExceptionThrower();
|
||||||
QFuture<void> f = e->startAsynchronously();
|
QFuture<void> f = e->startAsynchronously();
|
||||||
f.waitForFinished();
|
f.waitForFinished();
|
||||||
} catch (const QtConcurrent::UnhandledException &) {
|
} catch (const QUnhandledException &) {
|
||||||
caught = true;
|
caught = true;
|
||||||
}
|
}
|
||||||
QVERIFY2(caught, "did not get exception");
|
QVERIFY2(caught, "did not get exception");
|
||||||
@ -508,7 +508,7 @@ void tst_QtConcurrentThreadEngine::exceptions()
|
|||||||
try {
|
try {
|
||||||
UnrelatedExceptionThrower e(QThread::currentThread());
|
UnrelatedExceptionThrower e(QThread::currentThread());
|
||||||
e.startBlocking();
|
e.startBlocking();
|
||||||
} catch (const QtConcurrent::UnhandledException &) {
|
} catch (const QUnhandledException &) {
|
||||||
caught = true;
|
caught = true;
|
||||||
}
|
}
|
||||||
QVERIFY2(caught, "did not get exception");
|
QVERIFY2(caught, "did not get exception");
|
||||||
@ -520,7 +520,7 @@ void tst_QtConcurrentThreadEngine::exceptions()
|
|||||||
try {
|
try {
|
||||||
UnrelatedExceptionThrower e(0);
|
UnrelatedExceptionThrower e(0);
|
||||||
e.startBlocking();
|
e.startBlocking();
|
||||||
} catch (const QtConcurrent::UnhandledException &) {
|
} catch (const QUnhandledException &) {
|
||||||
caught = true;
|
caught = true;
|
||||||
}
|
}
|
||||||
QVERIFY2(caught, "did not get exception");
|
QVERIFY2(caught, "did not get exception");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user