Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-10 10:21:42

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:significant reason:default
0004 
0005 #ifndef QSYSTEMSEMAPHORE_H
0006 #define QSYSTEMSEMAPHORE_H
0007 
0008 #include <QtCore/qcoreapplication.h>
0009 #include <QtCore/qtipccommon.h>
0010 #include <QtCore/qstring.h>
0011 #include <QtCore/qscopedpointer.h>
0012 
0013 #include <memory>
0014 
0015 QT_BEGIN_NAMESPACE
0016 
0017 #if QT_CONFIG(systemsemaphore)
0018 
0019 class QSystemSemaphorePrivate;
0020 
0021 class Q_CORE_EXPORT QSystemSemaphore
0022 {
0023     Q_GADGET
0024     Q_DECLARE_TR_FUNCTIONS(QSystemSemaphore)
0025 public:
0026     enum AccessMode
0027     {
0028         Open,
0029         Create
0030     };
0031     Q_ENUM(AccessMode)
0032 
0033     enum SystemSemaphoreError
0034     {
0035         NoError,
0036         PermissionDenied,
0037         KeyError,
0038         AlreadyExists,
0039         NotFound,
0040         OutOfResources,
0041         UnknownError
0042     };
0043 
0044     QSystemSemaphore(const QNativeIpcKey &key, int initialValue = 0, AccessMode = Open);
0045     ~QSystemSemaphore();
0046 
0047     void setNativeKey(const QNativeIpcKey &key, int initialValue = 0, AccessMode = Open);
0048     void setNativeKey(const QString &key, int initialValue = 0, AccessMode mode = Open,
0049                       QNativeIpcKey::Type type = QNativeIpcKey::legacyDefaultTypeForOs())
0050     { setNativeKey({ key, type }, initialValue, mode); }
0051     QNativeIpcKey nativeIpcKey() const;
0052 
0053     QSystemSemaphore(const QString &key, int initialValue = 0, AccessMode mode = Open);
0054     void setKey(const QString &key, int initialValue = 0, AccessMode mode = Open);
0055     QString key() const;
0056 
0057     bool acquire();
0058     bool release(int n = 1);
0059 
0060     SystemSemaphoreError error() const;
0061     QString errorString() const;
0062 
0063     static bool isKeyTypeSupported(QNativeIpcKey::Type type) Q_DECL_CONST_FUNCTION;
0064     static QNativeIpcKey platformSafeKey(const QString &key,
0065             QNativeIpcKey::Type type = QNativeIpcKey::DefaultTypeForOs);
0066     static QNativeIpcKey legacyNativeKey(const QString &key,
0067             QNativeIpcKey::Type type = QNativeIpcKey::legacyDefaultTypeForOs());
0068 
0069 private:
0070     Q_DISABLE_COPY(QSystemSemaphore)
0071     std::unique_ptr<QSystemSemaphorePrivate> d;
0072 };
0073 
0074 #endif // QT_CONFIG(systemsemaphore)
0075 
0076 QT_END_NAMESPACE
0077 
0078 #endif // QSYSTEMSEMAPHORE_H