54 #ifdef THREADSTORAGE_DEBUG 55 # define DEBUG_MSG qtsDebug 59 void qtsDebug(
const char *fmt, ...)
64 fprintf(stderr,
"QThreadStorage: ");
65 vfprintf(stderr, fmt, va);
66 fprintf(stderr,
"\n");
71 # define DEBUG_MSG if(false)qDebug 81 DestructorMap *destr = destructors();
93 id = data->
tls.count();
94 DEBUG_MSG(
"QThreadStorageData: Allocated id %d, destructor %p cannot be stored",
id, func);
97 for (
id = 0;
id < destr->
count();
id++) {
98 if (destr->
at(
id) == 0)
101 if (
id == destr->
count()) {
106 DEBUG_MSG(
"QThreadStorageData: Allocated id %d, destructor %p",
id, func);
111 DEBUG_MSG(
"QThreadStorageData: Released id %d",
id);
114 (*destructors())[
id] = 0;
121 qWarning(
"QThreadStorage::get: QThreadStorage can only be used with threads started with QThread");
125 if (tls.size() <=
id)
129 DEBUG_MSG(
"QThreadStorageData: Returning storage %d, data %p, for thread %p",
141 qWarning(
"QThreadStorage::set: QThreadStorage can only be used with threads started with QThread");
145 if (tls.size() <=
id)
148 void *&value = tls[
id];
151 DEBUG_MSG(
"QThreadStorageData: Deleting previous storage %d, data %p, for thread %p",
158 void (*destructor)(
void *) = destr ? destr->
value(
id) : 0;
170 DEBUG_MSG(
"QThreadStorageData: Set storage %d for thread %p to %p",
id, data->
thread, p);
177 if (!tls || tls->isEmpty() || !mutex())
181 while (!tls->isEmpty()) {
182 void *&value = tls->last();
185 int i = tls->size() - 1;
194 void (*destructor)(
void *) = destructors()->value(i);
199 qWarning(
"QThreadStorage: Thread %p exited after QThreadStorage %d destroyed",
205 if (tls->size() > i) {
348 #endif // QT_NO_THREAD static void finish(void **)
#define QT_END_NAMESPACE
This macro expands to.
The QMutex class provides access serialization between threads.
int count(const T &t) const
Returns the number of occurrences of value in the vector.
void unlock()
Unlocks this mutex locker.
The QVector class is a template class that provides a dynamic array.
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
#define QT_BEGIN_NAMESPACE
This macro expands to.
T value(int i) const
Returns the value at index position i in the vector.
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
void append(const T &t)
Inserts value at the end of the vector.
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
const T & at(int i) const
Returns the item at index position i in the vector.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
static QThreadData * current()
QThreadStorage< QSharedNetworkSessionManager * > tls