author | llornkcor <llornkcor> | 2003-07-10 02:40:10 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-07-10 02:40:10 (UTC) |
commit | 155d68c1e7d7dc0fed2534ac43d6d77ce2781f55 (patch) (side-by-side diff) | |
tree | e6edaa5a7040fe6c224c3943d1094dcf02e4f74c /qmake/tools/qsemaphore_unix.cpp | |
parent | 86703e8a5527ef114facd02c005b6b3a7e62e263 (diff) | |
download | opie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.zip opie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.tar.gz opie-155d68c1e7d7dc0fed2534ac43d6d77ce2781f55.tar.bz2 |
update qmake to 1.05a
Diffstat (limited to 'qmake/tools/qsemaphore_unix.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | qmake/tools/qsemaphore_unix.cpp | 26 |
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 @@ -138,134 +138,132 @@ int QSemaphore::operator++(int) while (d->value >= d->max) d->cond.wait(&(d->mutex)); ++(d->value); if (d->value > d->max) d->value = d->max; ret = d->value; d->mutex.unlock(); return ret; } /*! Postfix -- operator. Release access of the semaphore. This wakes all threads waiting for access to the semaphore. */ int QSemaphore::operator--(int) { int ret; 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; } /*! Returns the total number of accesses to the semaphore. */ int QSemaphore::total() const { int ret; d->mutex.lock(); ret = d->max; d->mutex.unlock(); return ret; } /*! Try to get access to the semaphore. If \l available() \< \a n, this function will return FALSE immediately. If \l available() \>= \a n, this function will take \a n accesses and return TRUE. This function does \e not block. */ bool QSemaphore::tryAccess(int n) { if (! d->mutex.tryLock()) return FALSE; |