Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:26:49

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