| 118 | } |
| 119 | |
| 120 | void |
| 121 | AppTLS::cleanupTLSForThread() |
| 122 | { |
| 123 | QThread* curThread = QThread::currentThread(); |
| 124 | AbortableThread* isAbortableThread = dynamic_cast<AbortableThread*>(curThread); |
| 125 | |
| 126 | if (isAbortableThread) { |
| 127 | isAbortableThread->clearAbortInfo(); |
| 128 | } |
| 129 | |
| 130 | //Cleanup any cached data on the TLSHolder |
| 131 | { |
| 132 | QWriteLocker l(&_spawnsMutex); |
| 133 | |
| 134 | //This thread was spawned, but TLS not used, do not bother to clean-up |
| 135 | ThreadSpawnMap::iterator foundSpawned = _spawns.find(uintptr_t(curThread)); |
| 136 | if ( foundSpawned != _spawns.end() ) { |
| 137 | _spawns.erase(foundSpawned); |
| 138 | |
| 139 | return; |
| 140 | } |
| 141 | } |
| 142 | std::list<TLSHolderBaseConstPtr> objectsToClean; |
| 143 | { |
| 144 | QReadLocker k (&_objectMutex); |
| 145 | const TLSObjects& objectsCRef = _object->objects; |
| 146 | for (TLSObjects::iterator it = objectsCRef.begin(); |
| 147 | it != objectsCRef.end(); |
| 148 | ++it) { |
| 149 | TLSHolderBaseConstPtr p = (*it).lock(); |
| 150 | if (p) { |
| 151 | if ( p->canCleanupPerThreadData(curThread) ) { |
| 152 | objectsToClean.push_back(p); |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | if ( !objectsToClean.empty() ) { |
| 158 | #if 1 |
| 159 | // version from 1a0712b |
| 160 | // should be OK, since the bug in 1a0712b was in canCleanupPerThreadData |
| 161 | QWriteLocker k (&_objectMutex); |
| 162 | for (std::list<TLSHolderBaseConstPtr>::iterator it = objectsToClean.begin(); |
| 163 | it != objectsToClean.end(); |
| 164 | ++it) { |
| 165 | if ( (*it)->cleanupPerThreadData(curThread) ) { |
| 166 | TLSObjects::iterator found = _object->objects.find(*it); |
| 167 | if ( found != _object->objects.end() ) { |
| 168 | _object->objects.erase(found); |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | #else |
| 173 | // original version |
| 174 | TLSObjects newObjects; |
| 175 | QWriteLocker k (&_objectMutex); |
| 176 | for (TLSObjects::iterator it = _object->objects.begin(); |
| 177 | it != _object->objects.end(); ++it) { |
no test coverage detected