Index: TSRM.c =================================================================== RCS file: /repository/TSRM/TSRM.c,v retrieving revision 1.63 diff -u -r1.63 TSRM.c --- TSRM.c 21 Feb 2005 10:05:07 -0000 1.63 +++ TSRM.c 7 Mar 2005 13:40:44 -0000 @@ -149,6 +149,17 @@ TSRM_API void tsrm_shutdown(void) { int i; +#if defined(GNUPTH) + pth_cleanup_pop(0); +#elif defined(PTHREADS) + pthread_cleanup_pop(0); +#elif defined(TSRM_ST) + //Not sure about the thread cleanup_pop routine +#elif defined(TSRM_WIN32) + //Not sure about the thread cleanup_pop routine +#elif defined(BETHREADS) + //Not sure about the thread cleanup_pop routine +#endif if (tsrm_tls_table) { for (i=0; icount; j++) { + if (thread_resources->storage[j]) { + if (resource_types_table && !resource_types_table[j].done && resource_types_table[j].dtor) { + resource_types_table[j].dtor(thread_resources->storage[j], &thread_resources->storage); + } + free(thread_resources->storage[j]); + } + } tsrm_mutex_lock(tsmm_mutex); - hash_value = THREAD_HASH_OF(thread_id, tsrm_tls_table_size); - thread_resources = tsrm_tls_table[hash_value]; - - while (thread_resources) { - if (thread_resources->thread_id == thread_id) { - for (i=0; icount; i++) { - if (resource_types_table[i].dtor) { - resource_types_table[i].dtor(thread_resources->storage[i], &thread_resources->storage); + if (tsrm_tls_table) { + hash_value = THREAD_HASH_OF(tsrm_thread_id(), tsrm_tls_table_size); + tmp_resource = tsrm_tls_table[hash_value]; + while(tmp_resource) { + if(tmp_resource->thread_id == tsrm_thread_id()) { + if(prev_entry) { + prev_entry->next = tmp_resource->next; + } else { + tsrm_tls_table[hash_value] = tmp_resource->next; } + break; } - for (i=0; icount; i++) { - free(thread_resources->storage[i]); - } - free(thread_resources->storage); - if (last) { - last->next = thread_resources->next; - } else { - tsrm_tls_table[hash_value] = thread_resources->next; - } -#if defined(PTHREADS) - pthread_setspecific(tls_key, 0); -#elif defined(TSRM_WIN32) - TlsSetValue(tls_key, 0); -#endif - free(thread_resources); - break; - } - if (thread_resources->next) { - last = thread_resources; + prev_entry = tmp_resource; + tmp_resource = tmp_resource->next; } - thread_resources = thread_resources->next; } tsrm_mutex_unlock(tsmm_mutex); + free(thread_resources->storage); + thread_resources->next=NULL; + free(thread_resources); + thread_resources = NULL; +#if defined(PTHREADS) + pthread_setspecific(tls_key, 0); +#elif defined(TSRM_WIN32) + TlsSetValue(tls_key, 0); +#endif } - /* deallocates all occurrences of a given id */ void ts_free_id(ts_rsrc_id id) {