Skip to content

Commit

Permalink
QThreadStorage: replace QScoped- with std::unique_ptr
Browse files Browse the repository at this point in the history
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 <[email protected]>
(cherry picked from commit 6da1f72)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
(cherry picked from commit 7aadf25)
  • Loading branch information
marcmutz authored and Qt Cherry-pick Bot committed Jan 3, 2025
1 parent f5000be commit ec002f5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/corelib/thread/qthreadstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,17 @@ class QThreadStorage

#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;
}
Expand All @@ -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;
Expand Down

0 comments on commit ec002f5

Please sign in to comment.