QSystemSemaphore: Clear error after successful operation

Change-Id: I5c1021b2329439e3aefaa1c0d9c0b8a298d285de
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Konstantin Ritt 2013-11-10 15:42:05 +02:00 committed by The Qt Project
parent 6aa496c366
commit ed9e954f4b
5 changed files with 15 additions and 2 deletions

View File

@ -229,8 +229,7 @@ void QSystemSemaphore::setKey(const QString &key, int initialValue, AccessMode m
{ {
if (key == d->key && mode == Open) if (key == d->key && mode == Open)
return; return;
d->error = NoError; d->clearError();
d->errorString = QString();
#if !defined(Q_OS_WIN) #if !defined(Q_OS_WIN)
// optimization to not destroy/create the file & semaphore // optimization to not destroy/create the file & semaphore
if (key == d->key && mode == Create && d->createdSemaphore && d->createdFile) { if (key == d->key && mode == Create && d->createdSemaphore && d->createdFile) {

View File

@ -75,6 +75,11 @@ public:
return QSharedMemoryPrivate::makePlatformSafeKey(key, QLatin1String("qipc_systemsem_")); return QSharedMemoryPrivate::makePlatformSafeKey(key, QLatin1String("qipc_systemsem_"));
} }
inline void setError(QSystemSemaphore::SystemSemaphoreError e, const QString &message)
{ error = e; errorString = message; }
inline void clearError()
{ setError(QSystemSemaphore::NoError, QString()); }
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
Qt::HANDLE handle(QSystemSemaphore::AccessMode mode = QSystemSemaphore::Open); Qt::HANDLE handle(QSystemSemaphore::AccessMode mode = QSystemSemaphore::Open);
void setErrorString(const QString &function); void setErrorString(const QString &function);

View File

@ -229,6 +229,7 @@ bool QSystemSemaphorePrivate::modifySemaphore(int count)
return false; return false;
} }
clearError();
return true; return true;
} }

View File

@ -136,6 +136,7 @@ bool QSystemSemaphorePrivate::modifySemaphore(int count)
} }
} }
clearError();
return true; return true;
} }

View File

@ -145,12 +145,19 @@ void tst_QSystemSemaphore::complexacquire()
{ {
QSystemSemaphore sem("QSystemSemaphore_complexacquire", 2, QSystemSemaphore::Create); QSystemSemaphore sem("QSystemSemaphore_complexacquire", 2, QSystemSemaphore::Create);
QVERIFY(sem.acquire()); QVERIFY(sem.acquire());
QCOMPARE(sem.error(), QSystemSemaphore::NoError);
QVERIFY(sem.release()); QVERIFY(sem.release());
QCOMPARE(sem.error(), QSystemSemaphore::NoError);
QVERIFY(sem.acquire()); QVERIFY(sem.acquire());
QCOMPARE(sem.error(), QSystemSemaphore::NoError);
QVERIFY(sem.release()); QVERIFY(sem.release());
QCOMPARE(sem.error(), QSystemSemaphore::NoError);
QVERIFY(sem.acquire()); QVERIFY(sem.acquire());
QCOMPARE(sem.error(), QSystemSemaphore::NoError);
QVERIFY(sem.acquire()); QVERIFY(sem.acquire());
QCOMPARE(sem.error(), QSystemSemaphore::NoError);
QVERIFY(sem.release()); QVERIFY(sem.release());
QCOMPARE(sem.error(), QSystemSemaphore::NoError);
QVERIFY(sem.release()); QVERIFY(sem.release());
QCOMPARE(sem.error(), QSystemSemaphore::NoError); QCOMPARE(sem.error(), QSystemSemaphore::NoError);
QCOMPARE(sem.errorString(), QString()); QCOMPARE(sem.errorString(), QString());