summaryrefslogtreecommitdiff
path: root/qmake/tools/qsemaphore_unix.cpp
Side-by-side diff
Diffstat (limited to 'qmake/tools/qsemaphore_unix.cpp') (more/less context) (show whitespace changes)
-rw-r--r--qmake/tools/qsemaphore_unix.cpp26
1 files changed, 12 insertions, 14 deletions
diff --git a/qmake/tools/qsemaphore_unix.cpp b/qmake/tools/qsemaphore_unix.cpp
index fcf28da..4516049 100644
--- a/qmake/tools/qsemaphore_unix.cpp
+++ b/qmake/tools/qsemaphore_unix.cpp
@@ -162,86 +162,84 @@ int QSemaphore::operator--(int)
d->mutex.lock();
--(d->value);
if (d->value < 0) d->value = 0;
ret = d->value;
d->cond.wakeAll();
d->mutex.unlock();
return ret;
}
/*!
Try to get access to the semaphore. If \l available() \< \a n, this
call will block until it can get all the accesses it wants, i.e.
until available() \>= \a n.
*/
int QSemaphore::operator+=(int n)
{
int ret;
d->mutex.lock();
+ if ( n < 0 || n > d->max ) {
+#ifdef QT_CHECK_RANGE
+ qWarning( "QSemaphore::operator+=: paramter %d out of range", n );
+#endif // QT_CHECK_RANGE
+ n = n < 0 ? 0 : d->max;
+ }
+
while (d->value + n > d->max)
d->cond.wait(&(d->mutex));
d->value += n;
-
-#ifdef QT_CHECK_RANGE
- if (d->value > d->max) {
- qWarning("QSemaphore::operator+=: attempt to allocate more resources than available");
- d->value = d->max;
- }
-#endif
-
ret = d->value;
d->mutex.unlock();
return ret;
}
/*!
Release \a n accesses to the semaphore.
*/
int QSemaphore::operator-=(int n)
{
int ret;
d->mutex.lock();
- d->value -= n;
-
+ if ( n < 0 || n > d->value ) {
#ifdef QT_CHECK_RANGE
- if (d->value < 0) {
- qWarning("QSemaphore::operator-=: attempt to deallocate more resources than taken");
- d->value = 0;
+ qWarning( "QSemaphore::operator-=: paramter %d out of range", n );
+#endif // QT_CHECK_RANGE
+ n = n < 0 ? 0 : d->value;
}
-#endif
+ d->value -= n;
ret = d->value;
d->cond.wakeOne();
d->mutex.unlock();
return ret;
}
/*!
Returns the number of accesses currently available to the
semaphore.
*/
int QSemaphore::available() const {
int ret;
d->mutex.lock();
ret = d->max - d->value;
d->mutex.unlock();
return ret;
}