QThreadStorage: replace QScoped- with std::unique_ptr
This only affects the !QT_CONFIG(thread) case and requires the rewrite of the old-style static cleanup() deleter protocol into the modern operator()() one. As a drive-by, mark the deleter noexcept, like destructors are supposed to be. Task-number: QTBUG-132213 Change-Id: I8839865880647d76b77eb9a3f2858067db86234e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 6da1f72311b844b2232da3067ad6e1e24614e67c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 7aadf25ccd70fd739a7b06f6b6bccbdee03847a5)
This commit is contained in:
parent
f5000beeb6
commit
ec002f5a04
@ -115,18 +115,17 @@ public:
|
|||||||
|
|
||||||
#else // !QT_CONFIG(thread)
|
#else // !QT_CONFIG(thread)
|
||||||
|
|
||||||
#include <QtCore/qscopedpointer.h>
|
#include <memory>
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
inline bool qThreadStorage_hasLocalData(const QScopedPointer<T, U> &data)
|
inline bool qThreadStorage_hasLocalData(const std::unique_ptr<T, U> &data)
|
||||||
{
|
{
|
||||||
return !!data;
|
return !!data;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
inline bool qThreadStorage_hasLocalData(const QScopedPointer<T*, U> &data)
|
inline bool qThreadStorage_hasLocalData(const std::unique_ptr<T*, U> &data)
|
||||||
{
|
{
|
||||||
return !!data ? *data != nullptr : false;
|
return !!data ? *data != nullptr : false;
|
||||||
}
|
}
|
||||||
@ -150,14 +149,14 @@ class QThreadStorage
|
|||||||
private:
|
private:
|
||||||
struct ScopedPointerThreadStorageDeleter
|
struct ScopedPointerThreadStorageDeleter
|
||||||
{
|
{
|
||||||
static inline void cleanup(T *t)
|
void operator()(T *t) const noexcept
|
||||||
{
|
{
|
||||||
if (t == nullptr)
|
if (t == nullptr)
|
||||||
return;
|
return;
|
||||||
qThreadStorage_deleteLocalData(t);
|
qThreadStorage_deleteLocalData(t);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
QScopedPointer<T, ScopedPointerThreadStorageDeleter> data;
|
std::unique_ptr<T, ScopedPointerThreadStorageDeleter> data;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QThreadStorage() = default;
|
QThreadStorage() = default;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user