From 3bfda9681b17c62ff51a715882d40ef3091cdbb4 Mon Sep 17 00:00:00 2001 From: mquinson Date: Fri, 9 Mar 2007 16:47:06 +0000 Subject: [PATCH] Make the implementation more robust: don't die if something to destroy is already NULL, ignore instead; don't try to delete our pthread_key on shutdown. Valgrind detects no leak if we don't, and whine if we try to git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3231 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/xbt/xbt_thread.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/xbt/xbt_thread.c b/src/xbt/xbt_thread.c index adf3da7c44..024e50fc1c 100644 --- a/src/xbt/xbt_thread.c +++ b/src/xbt/xbt_thread.c @@ -39,10 +39,11 @@ void xbt_thread_mod_init(void) { THROW0(system_error,errcode,"pthread_key_create failed for xbt_self_thread_key"); } void xbt_thread_mod_exit(void) { - int errcode; + /* FIXME: don't try to free our key on shutdown. Valgrind detects no leak if we don't, and whine if we try to */ +// int errcode; - if ((errcode=pthread_key_delete(xbt_self_thread_key))) - THROW0(system_error,errcode,"pthread_key_delete failed for xbt_self_thread_key"); +// if ((errcode=pthread_key_delete(xbt_self_thread_key))) +// THROW0(system_error,errcode,"pthread_key_delete failed for xbt_self_thread_key"); } @@ -102,6 +103,8 @@ void xbt_mutex_unlock(xbt_mutex_t mutex) { void xbt_mutex_destroy(xbt_mutex_t mutex) { int errcode; + if (!mutex) return; + if ((errcode=pthread_mutex_destroy(&(mutex->m)))) THROW1(system_error,errcode,"pthread_mutex_destroy(%p) failed",mutex); free(mutex); @@ -140,6 +143,9 @@ void xbt_thcond_broadcast(xbt_thcond_t cond){ } void xbt_thcond_destroy(xbt_thcond_t cond){ int errcode; + + if (!cond) return; + if ((errcode=pthread_cond_destroy(&(cond->c)))) THROW1(system_error,errcode,"pthread_cond_destroy(%p) failed",cond); free(cond); @@ -230,8 +236,9 @@ void xbt_mutex_unlock(xbt_mutex_t mutex) { void xbt_mutex_destroy(xbt_mutex_t mutex) { - DeleteCriticalSection(& mutex->lock); - + if (!mutex) return; + + DeleteCriticalSection(& mutex->lock); free(mutex); } @@ -349,6 +356,8 @@ void xbt_thcond_broadcast(xbt_thcond_t cond){ void xbt_thcond_destroy(xbt_thcond_t cond){ int error = 0; + if (!cond) return; + if(!CloseHandle(cond->events[SIGNAL])) error = 1; -- 2.20.1