1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2022 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2008-2015 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2010-2015 Los Alamos National Security, LLC.
* All rights reserved.
* Copyright (c) 2013-2017 Intel, Inc. All rights reserved.
* Copyright (c) 2016-2017 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2017 Amazon.com, Inc. or its affiliates.
* All Rights reserved.
* Copyright (c) 2018 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/** @file **/
#include "opal_config.h"
#include "opal/class/opal_object.h"
#include "opal/constants.h"
#include "opal/runtime/opal.h"
#include "opal/util/output.h"
#include "opal/util/proc.h"
extern int opal_util_initialized;
static opal_mutex_t opal_finalize_cleanup_fns_lock = OPAL_MUTEX_STATIC_INIT;
opal_list_t opal_finalize_cleanup_fns = {{0}};
struct opal_cleanup_fn_item_t {
opal_list_item_t super;
opal_cleanup_fn_t cleanup_fn;
void *user_data;
#if OPAL_ENABLE_DEBUG
char *cleanup_fn_name;
#endif
};
typedef struct opal_cleanup_fn_item_t opal_cleanup_fn_item_t;
OBJ_CLASS_DECLARATION(opal_cleanup_fn_item_t);
static void opal_cleanup_fn_item_construct(opal_cleanup_fn_item_t *item)
{
#if OPAL_ENABLE_DEBUG
item->cleanup_fn_name = NULL;
#endif
}
static void opal_cleanup_fn_item_destruct(opal_cleanup_fn_item_t *item)
{
#if OPAL_ENABLE_DEBUG
free(item->cleanup_fn_name);
item->cleanup_fn_name = NULL;
#endif
}
OBJ_CLASS_INSTANCE(opal_cleanup_fn_item_t, opal_list_item_t, opal_cleanup_fn_item_construct,
opal_cleanup_fn_item_destruct);
static void opal_finalize_domain_construct(opal_finalize_domain_t *domain)
{
domain->domain_name = NULL;
}
static void opal_finalize_domain_destruct(opal_finalize_domain_t *domain)
{
free(domain->domain_name);
domain->domain_name = NULL;
}
OBJ_CLASS_INSTANCE(opal_finalize_domain_t, opal_list_t, opal_finalize_domain_construct,
opal_finalize_domain_destruct);
static opal_finalize_domain_t *current_finalize_domain;
opal_finalize_domain_t opal_init_util_domain = {{{0}}};
opal_finalize_domain_t opal_init_domain = {{{0}}};
void opal_finalize_append_cleanup(opal_cleanup_fn_t cleanup_fn, const char *fn_name,
void *user_data)
{
opal_cleanup_fn_item_t *cleanup_item = OBJ_NEW(opal_cleanup_fn_item_t);
assert(NULL != cleanup_item);
cleanup_item->cleanup_fn = cleanup_fn;
cleanup_item->user_data = user_data;
#if OPAL_ENABLE_DEBUG
cleanup_item->cleanup_fn_name = strdup(fn_name);
assert(NULL != cleanup_item->cleanup_fn_name);
#else
(void) fn_name;
#endif
opal_mutex_lock(&opal_finalize_cleanup_fns_lock);
opal_list_append(¤t_finalize_domain->super, &cleanup_item->super);
opal_mutex_unlock(&opal_finalize_cleanup_fns_lock);
}
void opal_finalize_domain_init(opal_finalize_domain_t *domain, const char *domain_name)
{
free(domain->domain_name);
domain->domain_name = domain_name ? strdup(domain_name) : NULL;
}
void opal_finalize_set_domain(opal_finalize_domain_t *domain)
{
current_finalize_domain = domain;
}
void opal_finalize_cleanup_domain(opal_finalize_domain_t *domain)
{
opal_cleanup_fn_item_t *cleanup_item, *next;
/* call any registered cleanup functions before tearing down OPAL */
OPAL_LIST_FOREACH_SAFE_REV (cleanup_item, next, &domain->super, opal_cleanup_fn_item_t) {
cleanup_item->cleanup_fn(cleanup_item->user_data);
opal_list_remove_item(&domain->super, &cleanup_item->super);
OBJ_RELEASE(cleanup_item);
}
}
int opal_finalize_util(void)
{
if (--opal_util_initialized != 0) {
if (opal_util_initialized < 0) {
return OPAL_ERROR;
}
return OPAL_SUCCESS;
}
opal_finalize_cleanup_domain(&opal_init_util_domain);
OBJ_DESTRUCT(&opal_init_util_domain);
/* finalize the class/object system */
opal_class_finalize();
free(opal_process_info.nodename);
opal_process_info.nodename = NULL;
return OPAL_SUCCESS;
}
|