/*
 * Close a component 
 */
static void ri_destructor(opal_object_t *obj)
{
  repository_item_t *ri = (repository_item_t *) obj;
  dependency_item_t *di;
  opal_list_item_t *item;
  int group_id;

  group_id = mca_base_var_group_find (NULL, ri->ri_type,
                                      ri->ri_component_struct->mca_component_name);
  if (0 <= group_id) {
    mca_base_var_group_deregister (group_id);
  }

  /* Close the component (and potentially unload it from memory */
  lt_dlclose(ri->ri_dlhandle);

  /* It should be obvious, but I'll state it anyway because it bit me
     during debugging: after the dlclose(), the mca_base_component_t
     pointer is no longer valid because it has [potentially] been
     unloaded from memory.  So don't try to use it.  :-) */

  /* Now go release/close (at a minimum: decrement the refcount) any
     dependencies of this component */

  for (item = opal_list_remove_first(&ri->ri_dependencies);
       NULL != item; 
       item = opal_list_remove_first(&ri->ri_dependencies)) {
    di = (dependency_item_t *) item;
    OBJ_RELEASE(di);
  }
  OBJ_DESTRUCT(&ri->ri_dependencies);
  opal_list_remove_item(&repository, (opal_list_item_t *) ri);
}
int mca_base_framework_close (struct mca_base_framework_t *framework) {
    bool is_open = !!framework->framework_refcnt;
    int ret, group_id;

    assert (NULL != framework);

    if (!framework_is_registered (framework) && 0 == framework->framework_refcnt) {
        return OPAL_SUCCESS;
    }

    if (framework->framework_refcnt && --framework->framework_refcnt) {
        return OPAL_SUCCESS;
    }

    /* find and deregister all component groups and variables */
    group_id = mca_base_var_group_find (framework->framework_project,
                                        framework->framework_name, NULL);
    if (0 <= group_id) {
        ret = mca_base_var_group_deregister (group_id);
        framework->framework_flags &= ~MCA_BASE_FRAMEWORK_FLAG_REGISTERED;
    }

    /* close the framework and all of its components */
    if (is_open) {
        if (NULL != framework->framework_close) {
            ret = framework->framework_close ();
        } else {
            ret = mca_base_framework_components_close (framework, NULL);
        }

        if (OPAL_SUCCESS != ret) {
            return ret;
        }
    } else {
        opal_list_item_t *item;
        while (NULL != (item = opal_list_remove_first (&framework->framework_components))) {
            mca_base_component_unload ((mca_base_component_t *) item, framework->framework_output);
            OBJ_RELEASE(item);
        }
        ret = OPAL_SUCCESS;
    }

    framework->framework_flags &= ~MCA_BASE_FRAMEWORK_FLAG_REGISTERED;

    framework_close_output (framework);

    return ret;
}
Esempio n. 3
0
void mca_base_component_unload (const mca_base_component_t *component, int output_id)
{
    int ret;

    /* Unload */
    opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id,
                         "mca: base: close: unloading component %s",
                         component->mca_component_name);

    ret = mca_base_var_group_find (component->mca_project_name, component->mca_type_name,
                                   component->mca_component_name);
    if (0 <= ret) {
        mca_base_var_group_deregister (ret);
    }

    mca_base_component_repository_release (component);
}