mitsuba-af602c6fd98a/src/libcore/tls.cpp
/// A thread has died -- destroy any remaining TLS entries associated with it
A thread has died -- destroy any remaining TLS entries associated with it
A thread has died -- destroy any remaining TLS entries associated with it
void destroyLocalTLS() {
	boost::lock_guard<boost::mutex> guard(ptdGlobalLock);
#if defined(__OSX__)
	PerThreadData *ptd = (PerThreadData *) pthread_getspecific(ptdLocal);
#else
	PerThreadData *ptd = ptdLocal;
#endif
	boost::unique_lock<boost::recursive_mutex> lock(ptd->mutex);
	for (PerThreadData::reverse_iterator it = mi::get<PerThreadData::seq_tag>(ptd->map).rbegin();
		it != mi::get<PerThreadData::seq_tag>(ptd->map).rend(); ++it) {
		TLSEntry &entry = it->second;
		entry.destructFunctor(entry.data);
	}
	lock.unlock();
	ptdGlobal.erase(ptd);
	delete ptd;
#if defined(__OSX__)
	pthread_setspecific(ptdLocal, NULL);
#else
	ptdLocal = NULL;
#endif
}
void destroyLocalTLS ( ) { boost :: lock_guard < boost :: mutex > guard ( ptdGlobalLock ) ; #if defined ( __OSX__ ) PerThreadData * ptd = ( PerThreadData * ) pthread_getspecific ( ptdLocal ) ; #else PerThreadData * ptd = ptdLocal ; #endif boost :: unique_lock < boost :: recursive_mutex > lock ( ptd -> mutex ) ; for ( PerThreadData :: reverse_iterator it = mi :: get < PerThreadData :: seq_tag > ( ptd -> map ) . rbegin ( ) ; it != mi :: get < PerThreadData :: seq_tag > ( ptd -> map ) . rend ( ) ; ++ it ) { TLSEntry & entry = it -> second ; entry . destructFunctor ( entry . data ) ; } lock . unlock ( ) ; ptdGlobal . erase ( ptd ) ; delete ptd ; #if defined ( __OSX__ ) pthread_setspecific ( ptdLocal , NULL ) ; #else ptdLocal = NULL ; #endif }
A thread has died -- destroy any remaining TLS entries associated with it
A thread has died -- destroy any remaining TLS entries associated with it
// Destroy the data in reverse order of creation