Add a new system runtime plugin type - just the top level

class, not any actual plugin implementation yet.
<rdar://problem/15314068> 

llvm-svn: 194044
This commit is contained in:
Jason Molenda
2013-11-05 03:57:19 +00:00
parent d6b40b51c7
commit eef510667b
11 changed files with 365 additions and 1 deletions

View File

@@ -854,6 +854,111 @@ PluginManager::GetLanguageRuntimeCreateCallbackForPluginName (const ConstString
return NULL;
}
#pragma mark SystemRuntime
struct SystemRuntimeInstance
{
SystemRuntimeInstance() :
name(),
description(),
create_callback(NULL)
{
}
ConstString name;
std::string description;
SystemRuntimeCreateInstance create_callback;
};
typedef std::vector<SystemRuntimeInstance> SystemRuntimeInstances;
static Mutex &
GetSystemRuntimeMutex ()
{
static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive);
return g_instances_mutex;
}
static SystemRuntimeInstances &
GetSystemRuntimeInstances ()
{
static SystemRuntimeInstances g_instances;
return g_instances;
}
bool
PluginManager::RegisterPlugin
(
const ConstString &name,
const char *description,
SystemRuntimeCreateInstance create_callback
)
{
if (create_callback)
{
SystemRuntimeInstance instance;
assert ((bool)name);
instance.name = name;
if (description && description[0])
instance.description = description;
instance.create_callback = create_callback;
Mutex::Locker locker (GetSystemRuntimeMutex ());
GetSystemRuntimeInstances ().push_back (instance);
}
return false;
}
bool
PluginManager::UnregisterPlugin (SystemRuntimeCreateInstance create_callback)
{
if (create_callback)
{
Mutex::Locker locker (GetSystemRuntimeMutex ());
SystemRuntimeInstances &instances = GetSystemRuntimeInstances ();
SystemRuntimeInstances::iterator pos, end = instances.end();
for (pos = instances.begin(); pos != end; ++ pos)
{
if (pos->create_callback == create_callback)
{
instances.erase(pos);
return true;
}
}
}
return false;
}
SystemRuntimeCreateInstance
PluginManager::GetSystemRuntimeCreateCallbackAtIndex (uint32_t idx)
{
Mutex::Locker locker (GetSystemRuntimeMutex ());
SystemRuntimeInstances &instances = GetSystemRuntimeInstances ();
if (idx < instances.size())
return instances[idx].create_callback;
return NULL;
}
SystemRuntimeCreateInstance
PluginManager::GetSystemRuntimeCreateCallbackForPluginName (const ConstString &name)
{
if (name)
{
Mutex::Locker locker (GetSystemRuntimeMutex ());
SystemRuntimeInstances &instances = GetSystemRuntimeInstances ();
SystemRuntimeInstances::iterator pos, end = instances.end();
for (pos = instances.begin(); pos != end; ++ pos)
{
if (name == pos->name)
return pos->create_callback;
}
}
return NULL;
}
#pragma mark ObjectFile
struct ObjectFileInstance