PluginManager.cpp (254729) | PluginManager.cpp (258054) |
---|---|
1//===-- PluginManager.cpp ---------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 840 unchanged lines hidden (view full) --- 849 { 850 if (name == pos->name) 851 return pos->create_callback; 852 } 853 } 854 return NULL; 855} 856 | 1//===-- PluginManager.cpp ---------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 840 unchanged lines hidden (view full) --- 849 { 850 if (name == pos->name) 851 return pos->create_callback; 852 } 853 } 854 return NULL; 855} 856 |
857#pragma mark SystemRuntime 858 859 860struct SystemRuntimeInstance 861{ 862 SystemRuntimeInstance() : 863 name(), 864 description(), 865 create_callback(NULL) 866 { 867 } 868 869 ConstString name; 870 std::string description; 871 SystemRuntimeCreateInstance create_callback; 872}; 873 874typedef std::vector<SystemRuntimeInstance> SystemRuntimeInstances; 875 876static Mutex & 877GetSystemRuntimeMutex () 878{ 879 static Mutex g_instances_mutex (Mutex::eMutexTypeRecursive); 880 return g_instances_mutex; 881} 882 883static SystemRuntimeInstances & 884GetSystemRuntimeInstances () 885{ 886 static SystemRuntimeInstances g_instances; 887 return g_instances; 888} 889 890bool 891PluginManager::RegisterPlugin 892( 893 const ConstString &name, 894 const char *description, 895 SystemRuntimeCreateInstance create_callback 896) 897{ 898 if (create_callback) 899 { 900 SystemRuntimeInstance instance; 901 assert ((bool)name); 902 instance.name = name; 903 if (description && description[0]) 904 instance.description = description; 905 instance.create_callback = create_callback; 906 Mutex::Locker locker (GetSystemRuntimeMutex ()); 907 GetSystemRuntimeInstances ().push_back (instance); 908 } 909 return false; 910} 911 912bool 913PluginManager::UnregisterPlugin (SystemRuntimeCreateInstance create_callback) 914{ 915 if (create_callback) 916 { 917 Mutex::Locker locker (GetSystemRuntimeMutex ()); 918 SystemRuntimeInstances &instances = GetSystemRuntimeInstances (); 919 920 SystemRuntimeInstances::iterator pos, end = instances.end(); 921 for (pos = instances.begin(); pos != end; ++ pos) 922 { 923 if (pos->create_callback == create_callback) 924 { 925 instances.erase(pos); 926 return true; 927 } 928 } 929 } 930 return false; 931} 932 933SystemRuntimeCreateInstance 934PluginManager::GetSystemRuntimeCreateCallbackAtIndex (uint32_t idx) 935{ 936 Mutex::Locker locker (GetSystemRuntimeMutex ()); 937 SystemRuntimeInstances &instances = GetSystemRuntimeInstances (); 938 if (idx < instances.size()) 939 return instances[idx].create_callback; 940 return NULL; 941} 942 943SystemRuntimeCreateInstance 944PluginManager::GetSystemRuntimeCreateCallbackForPluginName (const ConstString &name) 945{ 946 if (name) 947 { 948 Mutex::Locker locker (GetSystemRuntimeMutex ()); 949 SystemRuntimeInstances &instances = GetSystemRuntimeInstances (); 950 951 SystemRuntimeInstances::iterator pos, end = instances.end(); 952 for (pos = instances.begin(); pos != end; ++ pos) 953 { 954 if (name == pos->name) 955 return pos->create_callback; 956 } 957 } 958 return NULL; 959} 960 961 |
|
857#pragma mark ObjectFile 858 859struct ObjectFileInstance 860{ 861 ObjectFileInstance() : 862 name(), 863 description(), 864 create_callback(NULL), --- 1200 unchanged lines hidden --- | 962#pragma mark ObjectFile 963 964struct ObjectFileInstance 965{ 966 ObjectFileInstance() : 967 name(), 968 description(), 969 create_callback(NULL), --- 1200 unchanged lines hidden --- |