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.

Pick-to: 6.9 6.8
Task-number: QTBUG-132213
Change-Id: I8839865880647d76b77eb9a3f2858067db86234e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2024-05-14 06:51:05 +02:00
parent f9163ae7a8
commit 6da1f72311

View File

@ -115,18 +115,17 @@ public:
#else // !QT_CONFIG(thread)
#include <QtCore/qscopedpointer.h>
#include <memory>
#include <type_traits>
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;
}
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;
}
@ -150,14 +149,14 @@ class QThreadStorage
private:
struct ScopedPointerThreadStorageDeleter
{
static inline void cleanup(T *t)
void operator()(T *t) const noexcept
{
if (t == nullptr)
return;
qThreadStorage_deleteLocalData(t);
}
};
QScopedPointer<T, ScopedPointerThreadStorageDeleter> data;
std::unique_ptr<T, ScopedPointerThreadStorageDeleter> data;
public:
QThreadStorage() = default;