From ccdb83457453f8cb4e3aba1de4a7ad57ef4c65f4 Mon Sep 17 00:00:00 2001 From: Ralph Castain Date: Thu, 19 Jul 2007 12:56:41 +0000 Subject: [PATCH] Fix a couple of compile errors. Also, we need to ensure that we only attempt to call destructors on tsd keys that were defined. This commit was SVN r15501. --- opal/threads/tsd.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/opal/threads/tsd.c b/opal/threads/tsd.c index 9395cd3f5f..56c3879c4e 100644 --- a/opal/threads/tsd.c +++ b/opal/threads/tsd.c @@ -11,6 +11,8 @@ #include "opal_config.h" +#include + #include "opal/threads/tsd.h" #if !OMPI_HAVE_POSIX_THREADS && !OMPI_HAVE_SOLARIS_THREADS && !defined(__WINDOWS__) @@ -27,23 +29,25 @@ typedef struct tsd_entry_t tsd_entry_t; static tsd_entry_t entries[TSD_ENTRIES]; static bool atexit_registered = false; -void +static void run_destructors(void) { int i; - for (i = 0 i < TSD_ENTRIES ; ++i) { + for (i = 0; i < TSD_ENTRIES ; ++i) { opal_tsd_destructor_t destructor; void *value; - destructor = entries[i].destructor; - value = entries[i].value; - - entries[i].used = false; - entries[i].destructor = NULL; - entries[i].value = NULL; - - destructor(value); + if (entries[i].used) { + destructor = entries[i].destructor; + value = entries[i].value; + + entries[i].used = false; + entries[i].destructor = NULL; + entries[i].value = NULL; + + destructor(value); + } } } @@ -66,6 +70,7 @@ opal_tsd_key_create(opal_tsd_key_t *key, entries[i].value = NULL; entries[i].destructor = destructor; *key = i; + break; } } if (i == TSD_ENTRIES) return ENOMEM;