From f21a844f60ae6c74fcf1fddca32461acce3c1ee0 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Wed, 6 Nov 2013 16:48:53 +0000 Subject: Import lldb as of SVN r194122 Sponsored by: DARPA, AFRL --- source/Core/PluginManager.cpp | 105 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) (limited to 'source/Core/PluginManager.cpp') diff --git a/source/Core/PluginManager.cpp b/source/Core/PluginManager.cpp index 7a2d3772e6c3..813cec227525 100644 --- a/source/Core/PluginManager.cpp +++ b/source/Core/PluginManager.cpp @@ -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 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 -- cgit v1.3