Skip to content

Commit

Permalink
Fix #495: Support HPX modules exporting startup/shutdown functions on…
Browse files Browse the repository at this point in the history
…ly, this also fixes the current problems with loading the new memory related performance counters
  • Loading branch information
hkaiser committed Aug 12, 2012
1 parent e7517d8 commit 89358ad
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 45 deletions.
78 changes: 41 additions & 37 deletions src/runtime/components/server/runtime_support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,9 @@ namespace hpx { namespace components { namespace server
std::string instance (i->second.get_name());
std::string component;

if (i->second.has_entry("name"))
if (i->second.has_entry("mangledname"))
component = i->second.get_entry("mangledname");
else if (i->second.has_entry("name"))
component = HPX_MANGLE_COMPONENT_NAME_STR(i->second.get_entry("name"));
else
component = HPX_MANGLE_COMPONENT_NAME_STR(instance);
Expand Down Expand Up @@ -1080,10 +1082,6 @@ namespace hpx { namespace components { namespace server
// get the handle of the library
boost::plugin::dll d (lib.string(), component);

// get the factory
boost::plugin::plugin_factory<component_factory_base> pf (d,
BOOST_PP_STRINGIZE(HPX_MANGLE_COMPONENT_NAME(factory)));

// initialize the factory instance using the preferences from the
// ini files
util::section const* glob_ini = NULL;
Expand All @@ -1095,39 +1093,49 @@ namespace hpx { namespace components { namespace server
if (ini.has_section(component_section))
component_ini = ini.get_section(component_section);

// create the component factory object
boost::shared_ptr<component_factory_base> factory (
pf.create(instance, glob_ini, component_ini, isenabled));
if (0 == component_ini || "0" == component_ini->get_entry("no_factory", "0")) {
// get the factory
boost::plugin::plugin_factory<component_factory_base> pf (d,
BOOST_PP_STRINGIZE(HPX_MANGLE_COMPONENT_NAME(factory)));

component_type t = factory->get_component_type(
prefix, agas_client);
if (0 == t) {
LRT_(info) << "component refused to load: " << instance;
return false; // module refused to load
}
// create the component factory object, if not disabled
boost::shared_ptr<component_factory_base> factory (
pf.create(instance, glob_ini, component_ini, isenabled));

// store component factory and module for later use
component_factory_type data(factory, d, isenabled);
std::pair<component_map_type::iterator, bool> p =
components_.insert(component_map_type::value_type(t, data));

if (components::get_derived_type(t) != 0) {
// insert three component types, the base type, the derived
// type and the combined one.
if (p.second) {
p = components_.insert(component_map_type::value_type(
components::get_derived_type(t), data));
component_type t = factory->get_component_type(
prefix, agas_client);
if (0 == t) {
LRT_(info) << "component refused to load: " << instance;
return false; // module refused to load
}
if (p.second) {
components_.insert(component_map_type::value_type(
components::get_base_type(t), data));

// store component factory and module for later use
component_factory_type data(factory, d, isenabled);
std::pair<component_map_type::iterator, bool> p =
components_.insert(component_map_type::value_type(t, data));

if (components::get_derived_type(t) != 0) {
// insert three component types, the base type, the derived
// type and the combined one.
if (p.second) {
p = components_.insert(component_map_type::value_type(
components::get_derived_type(t), data));
}
if (p.second) {
components_.insert(component_map_type::value_type(
components::get_base_type(t), data));
}
}

if (!p.second) {
LRT_(fatal) << "duplicate component id: " << instance
<< ": " << components::get_component_type_name(t);
return false; // duplicate component id?
}
}

if (!p.second) {
LRT_(fatal) << "duplicate component id: " << instance
<< ": " << components::get_component_type_name(t);
return false; // duplicate component id?
LRT_(info) << "dynamic loading succeeded: " << lib.string()
<< ": " << instance << ": "
<< components::get_component_type_name(t);
}

// make sure startup/shutdown registration is called once for each
Expand All @@ -1137,10 +1145,6 @@ namespace hpx { namespace components { namespace server
load_commandline_options(d, options);
load_startup_shutdown_functions(d);
}

LRT_(info) << "dynamic loading succeeded: " << lib.string()
<< ": " << instance << ": "
<< components::get_component_type_name(t);
}
catch (hpx::exception const&) {
throw;
Expand Down
29 changes: 21 additions & 8 deletions src/util/init_ini_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <boost/tokenizer.hpp>
#include <boost/plugin.hpp>
#include <boost/foreach.hpp>
#include <boost/assign/std/vector.hpp>

///////////////////////////////////////////////////////////////////////////////
namespace hpx { namespace util
Expand Down Expand Up @@ -197,14 +198,26 @@ namespace hpx { namespace util
pf.get_names(names); // throws on error

std::vector<std::string> ini_data;

// ask all registries
BOOST_FOREACH(std::string const& s, names)
{
// create the component registry object
boost::shared_ptr<components::component_registry_base>
registry (pf.create(s));
registry->get_component_info(ini_data);
if (names.empty()) {
// This HPX module does not export any factories, but
// might export startup/shutdown functions. Create some
// default configuration data.
using namespace boost::assign;
ini_data += std::string("[hpx.components.") + name + "]";
ini_data += "mangledname = " + name;
ini_data += "path = $[hpx.location]/lib/hpx/";
ini_data += "no_factory = 1";
ini_data += "enabled = 1";
}
else {
// ask all registries
BOOST_FOREACH(std::string const& s, names)
{
// create the component registry object
boost::shared_ptr<components::component_registry_base>
registry (pf.create(s));
registry->get_component_info(ini_data);
}
}

// incorporate all information from this module's
Expand Down

0 comments on commit 89358ad

Please sign in to comment.