1
1

mca/base: revive mca_base_component_repository_retain_component

This commit revives the component retention functionality that was
removed as part of the component repository rewrite. The new
mca_base_component_repository_retain_component function works by
preventing the dlclosing of a dynamic component until a matching call
to mca_base_component_repository_release is made.

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
Этот коммит содержится в:
Nathan Hjelm 2015-07-27 16:01:40 -06:00 коммит произвёл George Bosilca
родитель c801ffde86
Коммит 70186f9145
2 изменённых файлов: 61 добавлений и 10 удалений

Просмотреть файл

@ -280,30 +280,57 @@ static void mca_base_component_repository_release_internal (mca_base_component_r
}
#endif
void mca_base_component_repository_release(const mca_base_component_t *component)
{
#if OPAL_HAVE_DL_SUPPORT
static mca_base_component_repository_item_t *find_component (const char *type, const char *name)
{
mca_base_component_repository_item_t *ri;
opal_list_t *component_list;
int ret;
ret = opal_hash_table_get_value_ptr (&mca_base_component_repository, component->mca_type_name,
strlen (component->mca_type_name), (void **) &component_list);
ret = opal_hash_table_get_value_ptr (&mca_base_component_repository, type,
strlen (type), (void **) &component_list);
if (OPAL_SUCCESS != ret) {
/* component does not exist in the repository */
return;
return NULL;
}
OPAL_LIST_FOREACH(ri, component_list, mca_base_component_repository_item_t) {
if (0 == strcmp (ri->ri_name, component->mca_component_name)) {
/* go ahead and dlclose the component if it is open */
mca_base_component_repository_release_internal (ri);
break;
if (0 == strcmp (ri->ri_name, name)) {
return ri;
}
}
return NULL;
}
#endif
void mca_base_component_repository_release(const mca_base_component_t *component)
{
#if OPAL_HAVE_DL_SUPPORT
mca_base_component_repository_item_t *ri;
ri = find_component (component->mca_type_name, component->mca_component_name);
if (NULL != ri && !(--ri->ri_refcnt)) {
mca_base_component_repository_release_internal (ri);
}
#endif
}
int mca_base_component_repository_retain_component (const char *type, const char *name)
{
#if OPAL_HAVE_DL_SUPPORT
mca_base_component_repository_item_t *ri = find_component(type, name);
if (NULL != ri) {
++ri->ri_refcnt;
return OPAL_SUCCESS;
}
return OPAL_ERR_NOT_FOUND;
#else
return OPAL_ERR_NOT_SUPPORTED;
#endif
}
int mca_base_component_repository_open (mca_base_framework_t *framework,
mca_base_component_repository_item_t *ri)
@ -443,6 +470,7 @@ int mca_base_component_repository_open (mca_base_framework_t *framework,
component to be closed later. */
ri->ri_component_struct = mitem->cli_component = component_struct;
ri->ri_refcnt = 1;
opal_list_append(&framework->framework_components, &mitem->super);
opal_output_verbose (MCA_BASE_VERBOSE_INFO, 0, "mca_base_component_repository_open: opened dynamic %s MCA "

Просмотреть файл

@ -1,3 +1,4 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
@ -10,6 +11,8 @@
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -50,6 +53,8 @@ struct mca_base_component_repository_item_t {
opal_dl_handle_t *ri_dlhandle;
const mca_base_component_t *ri_component_struct;
int ri_refcnt;
};
typedef struct mca_base_component_repository_item_t mca_base_component_repository_item_t;
@ -102,7 +107,25 @@ int mca_base_component_repository_open (mca_base_framework_t *framework,
mca_base_component_repository_item_t *ri);
void mca_base_component_repository_release(const mca_base_component_t *component);
/**
* @brief Reduce the reference count of a component and dlclose it if necessary
*/
void mca_base_component_repository_release (const mca_base_component_t *component);
/**
* @brief Increase the reference count of a component
*
* Each component repository item starts with a reference count of 0. This ensures that
* when a framework closes it's components the repository items are all correctly
* dlclosed. This function can be used to prevent the dlclose if a component is needed
* after its framework has closed the associated component. Users of this function
* should call mca_base_component_repository_release() once they are finished with the
* component.
*
* @note all components are automatically unloaded by the
* mca_base_component_repository_finalize() call.
*/
int mca_base_component_repository_retain_component (const char *type, const char *name);
END_C_DECLS