diff options
author | Ritt Konstantin <ritt.ks@gmail.com> | 2011-06-01 14:49:41 (GMT) |
---|---|---|
committer | Harald Fernengel <harald.fernengel@nokia.com> | 2011-06-01 14:49:41 (GMT) |
commit | 4134cb7dfc04ca7721277772c41b678bac6b33a0 (patch) | |
tree | a6574aa57d531d934ede1d70cd62220511ee14ca /src/gui/embedded | |
parent | b840d8255196241fa7c2684c0443471330f94046 (diff) | |
download | Qt-4134cb7dfc04ca7721277772c41b678bac6b33a0.zip Qt-4134cb7dfc04ca7721277772c41b678bac6b33a0.tar.gz Qt-4134cb7dfc04ca7721277772c41b678bac6b33a0.tar.bz2 |
simplify the code by using the EINTR_LOOP macro
the sembuf structure now initializes out of the loop (nano-opt)
Merge-request: 1237
Reviewed-by: Harald Fernengel <harald.fernengel@nokia.com>
Diffstat (limited to 'src/gui/embedded')
-rw-r--r-- | src/gui/embedded/qwslock.cpp | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/src/gui/embedded/qwslock.cpp b/src/gui/embedded/qwslock.cpp index ae168df..d8996d6 100644 --- a/src/gui/embedded/qwslock.cpp +++ b/src/gui/embedded/qwslock.cpp @@ -116,59 +116,59 @@ QWSLock::~QWSLock() static bool forceLock(int semId, unsigned short semNum, int) { int ret; - do { - sembuf sops = { semNum, -1, 0 }; - // As the BackingStore lock is a mutex, and only one process may own - // the lock, it's safe to use SEM_UNDO. On the other hand, the - // Communication lock is locked by the client but unlocked by the - // server and therefore can't use SEM_UNDO. - if (semNum == QWSLock::BackingStore) - sops.sem_flg |= SEM_UNDO; - - ret = semop(semId, &sops, 1); - if (ret == -1 && errno != EINTR) - qDebug("QWSLock::lock: %s", strerror(errno)); - } while (ret == -1 && errno == EINTR); + sembuf sops = { semNum, -1, 0 }; + // As the BackingStore lock is a mutex, and only one process may own + // the lock, it's safe to use SEM_UNDO. On the other hand, the + // Communication lock is locked by the client but unlocked by the + // server and therefore can't use SEM_UNDO. + if (semNum == QWSLock::BackingStore) + sops.sem_flg |= SEM_UNDO; + + EINTR_LOOP(ret, semop(semId, &sops, 1)); + if (ret == -1) { + qDebug("QWSLock::lock(): %s", strerror(errno)); + return false; + } - return (ret != -1); + return true; } static bool up(int semId, unsigned short semNum) { int ret; - do { - sembuf sops = { semNum, 1, 0 }; - ret = semop(semId, &sops, 1); - if (ret == -1 && errno != EINTR) - qDebug("QWSLock::up: %s", strerror(errno)); - } while (ret == -1 && errno == EINTR); - return (ret != -1); + sembuf sops = { semNum, 1, 0 }; + + EINTR_LOOP(ret, semop(semId, &sops, 1)); + if (ret == -1) { + qDebug("QWSLock::up(): %s", strerror(errno)); + return false; + } + + return true; } static bool down(int semId, unsigned short semNum) { int ret; - do { - sembuf sops = { semNum, -1, 0 }; - ret = semop(semId, &sops, 1); - if (ret == -1 && errno != EINTR) - qDebug("QWSLock::down: %s", strerror(errno)); - } while (ret == -1 && errno == EINTR); - return (ret != -1); + sembuf sops = { semNum, -1, 0 }; + + EINTR_LOOP(ret, semop(semId, &sops, 1)); + if (ret == -1) { + qDebug("QWSLock::down(): %s", strerror(errno)); + return false; + } + + return true; } static int getValue(int semId, unsigned short semNum) { - int ret; - do { - ret = semctl(semId, semNum, GETVAL, 0); - if (ret == -1 && errno != EINTR) - qDebug("QWSLock::getValue: %s", strerror(errno)); - } while (ret == -1 && errno == EINTR); - + int ret = semctl(semId, semNum, GETVAL, 0); + if (ret == -1) + qDebug("QWSLock::getValue(): %s", strerror(errno)); return ret; } @@ -218,7 +218,7 @@ void QWSLock::unlock(LockType type) ret = semop(semId, &sops, 1); if (ret == -1 && errno != EINTR) - qDebug("QWSLock::unlock: %s", strerror(errno)); + qDebug("QWSLock::unlock(): %s", strerror(errno)); } while (ret == -1 && errno == EINTR); } |