summaryrefslogtreecommitdiffstats
path: root/src/serialport/qtudev_p.h
diff options
context:
space:
mode:
authorLaszlo Papp <lpapp@kde.org>2014-02-16 01:01:03 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-16 11:59:41 +0100
commitc0e0bd80c3876ce1f9b7db80b5873e78b94fe039 (patch)
tree3bd80fcb62a52aa247e0711b0128838d4010b9d5 /src/serialport/qtudev_p.h
parent7c8dd1d696c61c4c49ffcb2c1c1b455389edb771 (diff)
Use Q_GLOBAL_STATIC for the udev symbol loading QLibrary instance
Even though this has been introduced in 5.1, officially, we can rely on it in the previous versions even if private API that it was. * Global variables are better avoided. * Q_GLOBAL_STATIC is thread-safe in Qt 5. * QLibrary depends on QCoreApplication and we need to make sure that is initialized afterwards, respectively. The instantiation is now moved into the corresponding source file so that if it is included at more than one place, it will not be instantiated each time it is used in a new source file including this header. Task-number: QTBUG-36870 Change-Id: I96de1257e5836b69d0c48b717d7c2e708d6b0fee Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com> Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Diffstat (limited to 'src/serialport/qtudev_p.h')
-rw-r--r--src/serialport/qtudev_p.h26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/serialport/qtudev_p.h b/src/serialport/qtudev_p.h
index 11871657..434292da 100644
--- a/src/serialport/qtudev_p.h
+++ b/src/serialport/qtudev_p.h
@@ -57,7 +57,7 @@ extern "C"
fp_##symbolName symbolName;
#define RESOLVE_SYMBOL(symbolName) \
- symbolName = (fp_##symbolName)resolveSymbol(#symbolName); \
+ symbolName = (fp_##symbolName)resolveSymbol(udevLibrary, #symbolName); \
if (!symbolName) \
return false;
@@ -89,16 +89,14 @@ GENERATE_SYMBOL_VARIABLE(void, udev_device_unref, struct udev_device *)
GENERATE_SYMBOL_VARIABLE(void, udev_enumerate_unref, struct udev_enumerate *)
GENERATE_SYMBOL_VARIABLE(void, udev_unref, struct udev *)
-QLibrary udevLibrary;
-
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
-inline QFunctionPointer resolveSymbol(const char *symbolName)
+inline QFunctionPointer resolveSymbol(QLibrary *udevLibrary, const char *symbolName)
{
- QFunctionPointer symbolFunctionPointer = udevLibrary.resolve(symbolName);
+ QFunctionPointer symbolFunctionPointer = udevLibrary->resolve(symbolName);
#else
-inline void *resolveSymbol(const char *symbolName)
+inline void *resolveSymbol(QLibrary *udevLibrary, const char *symbolName)
{
- void *symbolFunctionPointer = udevLibrary.resolve(symbolName);
+ void *symbolFunctionPointer = udevLibrary->resolve(symbolName);
#endif
if (!symbolFunctionPointer)
qWarning("Failed to resolve the udev symbol: %s", symbolName);
@@ -106,14 +104,14 @@ inline void *resolveSymbol(const char *symbolName)
return symbolFunctionPointer;
}
-inline bool resolveSymbols()
+inline bool resolveSymbols(QLibrary *udevLibrary)
{
- if (!udevLibrary.isLoaded()) {
- udevLibrary.setFileNameAndVersion(QStringLiteral("udev"), 1);
- if (!udevLibrary.load()) {
- udevLibrary.setFileNameAndVersion(QStringLiteral("udev"), 0);
- if (!udevLibrary.load()) {
- qWarning("Failed to load the library: %s, supported version(s): %i and %i", qPrintable(udevLibrary.fileName()), 1, 0);
+ if (!udevLibrary->isLoaded()) {
+ udevLibrary->setFileNameAndVersion(QStringLiteral("udev"), 1);
+ if (!udevLibrary->load()) {
+ udevLibrary->setFileNameAndVersion(QStringLiteral("udev"), 0);
+ if (!udevLibrary->load()) {
+ qWarning("Failed to load the library: %s, supported version(s): %i and %i", qPrintable(udevLibrary->fileName()), 1, 0);
return false;
}
}