summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qthreadstorage.h
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2010-11-04 16:23:04 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2010-11-22 14:09:07 (GMT)
commit5e13c65b7083ba6a28820a82f2fa19ca8c1569b0 (patch)
treebb5f514be56ea2cd6f26641230e02c88ff70c405 /src/corelib/thread/qthreadstorage.h
parented8f3b6c98f1b305f0d183bc70c5f810a9c45ef2 (diff)
downloadQt-5e13c65b7083ba6a28820a82f2fa19ca8c1569b0.zip
Qt-5e13c65b7083ba6a28820a82f2fa19ca8c1569b0.tar.gz
Qt-5e13c65b7083ba6a28820a82f2fa19ca8c1569b0.tar.bz2
Make QThreadStorage supports value type and not only pointers.
Handling value type is much more natural than handling pointer. It was not possible to use normal type in QThreadStorage previously (probably because some compiler would not support it?) This should ease a lot the use of QThreadStorage and make it more intuitive. The only problem was the QThreadStorage::deleteData() that would not compile for nonn-pointer. This is now fixed Also updated the documentation. Reviewed-by: Joao Reviewed-by: Brad Task-number: QTBUG-15033
Diffstat (limited to 'src/corelib/thread/qthreadstorage.h')
-rw-r--r--src/corelib/thread/qthreadstorage.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/corelib/thread/qthreadstorage.h b/src/corelib/thread/qthreadstorage.h
index 6264674..475d20d 100644
--- a/src/corelib/thread/qthreadstorage.h
+++ b/src/corelib/thread/qthreadstorage.h
@@ -91,6 +91,11 @@ inline
void qThreadStorage_setLocalData(QThreadStorageData &d, T **t)
{ (void) d.set(*t); }
+template <typename T>
+inline
+void qThreadStorage_deleteData(void *d, T **)
+{ delete static_cast<T *>(d); }
+
// value-based specialization
template <typename T>
inline
@@ -114,6 +119,12 @@ inline
void qThreadStorage_setLocalData(QThreadStorageData &d, T *t)
{ (void) d.set(new T(*t)); }
+template <typename T>
+inline
+void qThreadStorage_deleteData(void *d, T *)
+{ delete static_cast<T *>(d); }
+
+
// MOC_SKIP_END
#endif
@@ -126,7 +137,7 @@ private:
Q_DISABLE_COPY(QThreadStorage)
static inline void deleteData(void *x)
- { delete static_cast<T>(x); }
+ { qThreadStorage_deleteData(x, reinterpret_cast<T*>(0)); }
public:
inline QThreadStorage() : d(deleteData) { }