File indexing completed on 2024-05-19 15:15:34

0001 /*
0002     This file is part of the KDE
0003     SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-only
0006 */
0007 
0008 #include <QCoreApplication>
0009 #include <QThread>
0010 
0011 #include "kinterprocesslock.h"
0012 
0013 #ifdef Q_OS_WIN
0014 #include <windows.h>
0015 #else
0016 #include <unistd.h>
0017 #endif
0018 
0019 int main(int argc, char **argv)
0020 {
0021     QCoreApplication app(argc, argv);
0022 
0023     KInterProcessLock lock(QStringLiteral("mytrash"));
0024     qDebug("retrieve lock...");
0025     lock.lock();
0026     qDebug("waiting...");
0027     lock.waitForLockGranted();
0028     qDebug("retrieved lock");
0029     qDebug("sleeping...");
0030 #ifdef Q_OS_WIN
0031     Sleep(10 * 1000);
0032 #else
0033     sleep(10);
0034 #endif
0035 
0036     if (argc != 2) {
0037         lock.unlock();
0038         qDebug("release lock");
0039     }
0040 
0041     return 0;
0042 }