thread/m_thread_tls.c
/*! Destroy the current thread's TLS subsystem.  This is meant to be called internally
 *  by the threading system upon thread completion to destroy any memory associated
 *  with TLS for the thread.  M_thread_self() must still return a valid value. */
Destroy the current thread's TLS subsystem.  This is meant to be called internally
by the threading system upon thread completion to destroy any memory associated
with TLS for the thread.  M_thread_self() must still return a valid value.
Destroy the current thread ' s TLS subsystem . This is meant to be called internally by the threading system upon thread completion to destroy any memory associated with TLS for the thread . M_thread_self () must still return a valid value .
void M_thread_tls_purge_thread(void)
{
	M_hash_u64vp_t      *tls_store;
	M_hash_u64vp_enum_t *hashenum;
	M_uint64             key;
	M_list_u64_t        *keylist;
	size_t               i;
	size_t               len;
	M_thread_mutex_lock(M_thread_tls_key_mutex);
	tls_store = M_hash_u64vp_get_direct(M_thread_tls_storepool, M_thread_self());
	M_thread_mutex_unlock(M_thread_tls_key_mutex);
	if (tls_store == NULL)
		return;
	keylist = M_list_u64_create(M_LIST_U64_NONE);
	M_hash_u64vp_enumerate(tls_store, &hashenum);
	while (M_hash_u64vp_enumerate_next(tls_store, hashenum, &key, NULL)) {
		M_list_u64_insert(keylist, key);
	}
	M_hash_u64vp_enumerate_free(hashenum);
	len = M_list_u64_len(keylist);
	for (i=0; i<len; i++) {
		M_hash_u64vp_remove(tls_store, M_list_u64_at(keylist, i), M_TRUE);
	}
	M_list_u64_destroy(keylist);
	M_thread_mutex_lock(M_thread_tls_key_mutex);
	M_hash_u64vp_remove(M_thread_tls_storepool, M_thread_self(), M_TRUE);
	M_thread_mutex_unlock(M_thread_tls_key_mutex);
}
void M_thread_tls_purge_thread ( void ) { M_hash_u64vp_t * tls_store ; M_hash_u64vp_enum_t * hashenum ; M_uint64 key ; M_list_u64_t * keylist ; size_t i ; size_t len ; M_thread_mutex_lock ( M_thread_tls_key_mutex ) ; tls_store = M_hash_u64vp_get_direct ( M_thread_tls_storepool , M_thread_self ( ) ) ; M_thread_mutex_unlock ( M_thread_tls_key_mutex ) ; if ( tls_store == NULL ) return ; keylist = M_list_u64_create ( M_LIST_U64_NONE ) ; M_hash_u64vp_enumerate ( tls_store , & hashenum ) ; while ( M_hash_u64vp_enumerate_next ( tls_store , hashenum , & key , NULL ) ) { M_list_u64_insert ( keylist , key ) ; } M_hash_u64vp_enumerate_free ( hashenum ) ; len = M_list_u64_len ( keylist ) ; for ( i = 0 ; i < len ; i ++ ) { M_hash_u64vp_remove ( tls_store , M_list_u64_at ( keylist , i ) , M_TRUE ) ; } M_list_u64_destroy ( keylist ) ; M_thread_mutex_lock ( M_thread_tls_key_mutex ) ; M_hash_u64vp_remove ( M_thread_tls_storepool , M_thread_self ( ) , M_TRUE ) ; M_thread_mutex_unlock ( M_thread_tls_key_mutex ) ; }
Destroy the current thread's TLS subsystem.
Destroy the current thread ' s TLS subsystem .
/* No thread data */ /* We don't want to just remove the entry as it will iterate across all
	 * destructors while holding a GLOBAL lock.  Who knows how long that could
	 * take and cause the entire application to stall.  Instead, we are going
	 * to enumerate the hashtable, store the keys in a list, then iterate 
	 * over the list and destroy each value ... OUTSIDE of that GLOBAL lock.
	 */ /* Iterate across the keys (remember, can't enumerate and remove from a
	 * hashtable) */ /* Now we can re-lock that global mutex and remove the thread specific hash */