forked from github_mirror/framelesshelper
minor tweaks
Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
c75712d3f1
commit
9715bd9d4b
|
@ -25,8 +25,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "framelesshelpercore_global.h"
|
||||
#include <QtCore/qhash.h>
|
||||
#include <QtCore/qmutex.h>
|
||||
|
||||
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||
|
||||
|
@ -54,10 +52,6 @@ public:
|
|||
{
|
||||
return reinterpret_cast<T>(get(function));
|
||||
}
|
||||
|
||||
private:
|
||||
static inline QMutex m_mutex{};
|
||||
static inline QHash<QString, std::optional<QFunctionPointer>> m_functionCache = {};
|
||||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
|
|
@ -365,7 +365,9 @@ void FramelessManagerPrivate::initialize()
|
|||
flagSet = true;
|
||||
// Set a global flag so that people can check whether FramelessHelper is being
|
||||
// used without actually accessing the FramelessHelper interface.
|
||||
qApp->setProperty(kGlobalFlagVarName, FramelessHelper::Core::version().version);
|
||||
const int ver = FramelessHelper::Core::version().version;
|
||||
qputenv(kGlobalFlagVarName, QByteArray::number(ver));
|
||||
qApp->setProperty(kGlobalFlagVarName, ver);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
*/
|
||||
|
||||
#include "sysapiloader_p.h"
|
||||
#include <QtCore/qhash.h>
|
||||
#include <QtCore/qmutex.h>
|
||||
#ifdef Q_OS_WINDOWS
|
||||
# include <QtCore/private/qsystemlibrary_p.h>
|
||||
#else
|
||||
|
@ -37,6 +39,14 @@ Q_LOGGING_CATEGORY(lcSysApiLoader, "wangwenx190.framelesshelper.core.sysapiloade
|
|||
#define WARNING qCWarning(lcSysApiLoader)
|
||||
#define CRITICAL qCCritical(lcSysApiLoader)
|
||||
|
||||
struct SysApiLoaderData
|
||||
{
|
||||
QMutex mutex;
|
||||
QHash<QString, std::optional<QFunctionPointer>> functionCache = {};
|
||||
};
|
||||
|
||||
Q_GLOBAL_STATIC(SysApiLoaderData, g_loaderData)
|
||||
|
||||
Q_GLOBAL_STATIC(SysApiLoader, g_sysApiLoader)
|
||||
|
||||
SysApiLoader::SysApiLoader(QObject *parent) : QObject(parent)
|
||||
|
@ -91,17 +101,17 @@ bool SysApiLoader::isAvailable(const QString &library, const QString &function)
|
|||
if (library.isEmpty() || function.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
const QMutexLocker locker(&m_mutex);
|
||||
if (m_functionCache.contains(function)) {
|
||||
return m_functionCache.value(function).has_value();
|
||||
const QMutexLocker locker(&g_loaderData()->mutex);
|
||||
if (g_loaderData()->functionCache.contains(function)) {
|
||||
return g_loaderData()->functionCache.value(function).has_value();
|
||||
}
|
||||
const QFunctionPointer symbol = SysApiLoader::resolve(library, function);
|
||||
if (symbol) {
|
||||
m_functionCache.insert(function, symbol);
|
||||
g_loaderData()->functionCache.insert(function, symbol);
|
||||
DEBUG << "Successfully loaded" << function << "from" << library;
|
||||
return true;
|
||||
}
|
||||
m_functionCache.insert(function, std::nullopt);
|
||||
g_loaderData()->functionCache.insert(function, std::nullopt);
|
||||
WARNING << "Failed to load" << function << "from" << library;
|
||||
return false;
|
||||
}
|
||||
|
@ -112,9 +122,9 @@ QFunctionPointer SysApiLoader::get(const QString &function)
|
|||
if (function.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
const QMutexLocker locker(&m_mutex);
|
||||
if (m_functionCache.contains(function)) {
|
||||
return m_functionCache.value(function).value_or(nullptr);
|
||||
const QMutexLocker locker(&g_loaderData()->mutex);
|
||||
if (g_loaderData()->functionCache.contains(function)) {
|
||||
return g_loaderData()->functionCache.value(function).value_or(nullptr);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue