修复多线程搜索崩溃问题
This commit is contained in:
parent
d461d53d01
commit
53b4d3e894
|
@ -41,6 +41,7 @@ SearchTaskPluginManager::SearchTaskPluginManager(QObject *parent) : QObject(pare
|
|||
|
||||
bool SearchTaskPluginManager::startSearch(const QUuid &uuid, SearchProperty::SearchType searchType, const QString &customType)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
if (m_managedPlugins.contains(uuid)) {
|
||||
ManagedPlugin* managedPlugin = m_managedPlugins.value(uuid);
|
||||
|
||||
|
@ -94,6 +95,7 @@ SearchTaskPluginIface *SearchTaskPluginManager::getPlugin(SearchProperty::Search
|
|||
|
||||
void SearchTaskPluginManager::registerPluginPath(const QString& customType, const QString &pluginPath)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
if (!m_loadedPluginPath.contains(customType)) {
|
||||
m_loadedPluginPath.insert(customType, pluginPath);
|
||||
}
|
||||
|
@ -101,6 +103,7 @@ void SearchTaskPluginManager::registerPluginPath(const QString& customType, cons
|
|||
|
||||
bool SearchTaskPluginManager::isSearching(const QUuid &uuid, SearchProperty::SearchType searchType, const QString &customType)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
if (m_managedPlugins.contains(uuid)) {
|
||||
ManagedPlugin* managedPlugin = m_managedPlugins.value(uuid);
|
||||
|
||||
|
@ -121,6 +124,7 @@ bool SearchTaskPluginManager::isSearching(const QUuid &uuid, SearchProperty::Sea
|
|||
|
||||
SearchTaskPluginIface *SearchTaskPluginManager::initPlugins(const QUuid& uuid, SearchProperty::SearchType searchType, const QString& customType)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
if (!m_managedPlugins.contains(uuid)) {
|
||||
m_managedPlugins.insert(uuid, new ManagedPlugin(nullptr));
|
||||
}
|
||||
|
@ -138,12 +142,8 @@ SearchTaskPluginIface *SearchTaskPluginManager::initPlugins(const QUuid& uuid, S
|
|||
|
||||
void SearchTaskPluginManager::destroyPlugins(const QUuid &uuid)
|
||||
{
|
||||
if (m_managedPlugins.contains(uuid)) {
|
||||
ManagedPlugin *managedPlugin = m_managedPlugins.value(uuid);
|
||||
m_managedPlugins.remove(uuid);
|
||||
|
||||
delete managedPlugin;
|
||||
}
|
||||
QMutexLocker locker(&m_mutex);
|
||||
delete m_managedPlugins.take(uuid);
|
||||
}
|
||||
|
||||
ManagedPlugin::~ManagedPlugin()
|
||||
|
@ -154,6 +154,7 @@ ManagedPlugin::~ManagedPlugin()
|
|||
|
||||
bool ManagedPlugin::insertInternalPlugin(const SearchProperty::SearchType &searchType, SearchTaskPluginIface *plugin)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
if (plugin) {
|
||||
auto type = static_cast<size_t>(searchType);
|
||||
plugin->setParent(this);
|
||||
|
@ -163,13 +164,14 @@ bool ManagedPlugin::insertInternalPlugin(const SearchProperty::SearchType &searc
|
|||
return true;
|
||||
}
|
||||
|
||||
plugin->deleteLater();
|
||||
delete plugin;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ManagedPlugin::insertExternalPlugin(const QString &customType, SearchTaskPluginIface *plugin)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
if (plugin) {
|
||||
plugin->setParent(this);
|
||||
if (!customType.isEmpty() && !m_externalPlugin.contains(customType)) {
|
||||
|
@ -177,7 +179,7 @@ bool ManagedPlugin::insertExternalPlugin(const QString &customType, SearchTaskPl
|
|||
return true;
|
||||
}
|
||||
|
||||
plugin->deleteLater();
|
||||
delete plugin;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -185,6 +187,7 @@ bool ManagedPlugin::insertExternalPlugin(const QString &customType, SearchTaskPl
|
|||
|
||||
inline SearchTaskPluginIface *ManagedPlugin::internalPlugin(const SearchProperty::SearchType &searchType)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
auto type = static_cast<size_t>(searchType);
|
||||
if (m_internalPlugins.contains(type)) {
|
||||
return m_internalPlugins.value(type);
|
||||
|
@ -194,6 +197,7 @@ inline SearchTaskPluginIface *ManagedPlugin::internalPlugin(const SearchProperty
|
|||
|
||||
inline SearchTaskPluginIface *ManagedPlugin::externalPlugin(const QString &customType)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
if (m_externalPlugin.contains(customType)) {
|
||||
return m_externalPlugin.value(customType);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include <QObject>
|
||||
#include <QUuid>
|
||||
#include <QMap>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include "search-task-plugin-iface.h"
|
||||
|
||||
namespace UkuiSearch {
|
||||
|
@ -41,6 +43,7 @@ public:
|
|||
bool insertExternalPlugin(const QString& customType, SearchTaskPluginIface* plugin);
|
||||
|
||||
private:
|
||||
QMutex m_mutex;
|
||||
QMap<size_t, SearchTaskPluginIface*> m_internalPlugins;
|
||||
QMap<QString, SearchTaskPluginIface*> m_externalPlugin;
|
||||
};
|
||||
|
@ -65,6 +68,8 @@ private:
|
|||
QHash<QString, SearchTaskPluginIface*> m_loadedPlugin;
|
||||
QMap<QString, QString> m_loadedPluginPath;
|
||||
QMap<QUuid, ManagedPlugin*> m_managedPlugins;
|
||||
|
||||
QMutex m_mutex;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue