More PR feedback

This commit is contained in:
Brad Davis 2015-11-06 17:02:56 -08:00
parent 37a9538f10
commit 6122fa145d
3 changed files with 9 additions and 8 deletions

View file

@ -47,7 +47,7 @@
static const char* const MENU_PROPERTY_NAME = "com.highfidelity.Menu";
Menu* Menu::getInstance() {
static Menu* instance = globalInstace<Menu>(MENU_PROPERTY_NAME);
static Menu* instance = globalInstance<Menu>(MENU_PROPERTY_NAME);
return instance;
}

View file

@ -17,10 +17,10 @@
static const char* const DEPENDENCY_PROPERTY_NAME = "com.highfidelity.DependencyMananger";
DependencyManager& DependencyManager::manager() {
static DependencyManager* instance = globalInstace<DependencyManager>(DEPENDENCY_PROPERTY_NAME);
static DependencyManager* instance = globalInstance<DependencyManager>(DEPENDENCY_PROPERTY_NAME);
return *instance;
}
QSharedPointer<Dependency>& DependencyManager::safeGet(size_t hashCode) {
return _instanceHash[hashCode];
}
}

View file

@ -27,10 +27,10 @@
// Provides efficient access to a named global type. By storing the value
// in the QApplication by name we can implement the singleton pattern and
// have the single instance function across DLL boundaries.
template <typename T, typename ...Args>
T* globalInstace(const char* propertyName, Args&&... args) {
static std::shared_ptr<T> instancePtr;
static T *resultInstance { nullptr };
template <typename T, typename... Args>
T* globalInstance(const char* propertyName, Args&&... args) {
static std::unique_ptr<T> instancePtr;
static T* resultInstance { nullptr };
static std::mutex mutex;
if (!resultInstance) {
std::unique_lock<std::mutex> lock(mutex);
@ -39,7 +39,8 @@ T* globalInstace(const char* propertyName, Args&&... args) {
if (variant.isNull()) {
// Since we're building the object, store it in a shared_ptr so it's
// destroyed by the destructor of the static instancePtr
instancePtr = std::make_shared<T>(args...);
instancePtr = std::unique_ptr<T>(new T(std::forward<Args>(args)...));
void* voidInstance = &(*instancePtr);
variant = QVariant::fromValue(voidInstance);
qApp->setProperty(propertyName, variant);