ipc/sem.c: optimize if semops fail
authorManfred Spraul <manfred@colorfullife.com>
Wed, 16 Dec 2009 00:47:31 +0000 (16:47 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 16 Dec 2009 15:20:09 +0000 (07:20 -0800)
Reduce the amount of scanning of the list of pending semaphore operations:
If try_atomic_semop failed, then no changes were applied.  Thus no need to
restart.

Additionally, this patch correct an incorrect comment: It's possible to
wait for arbitrary semaphore values (do a dec by <x>, wait-for-zero, inc
by <x> in one atomic operation)

Both changes are from Nick Piggin, the patch is the result of a different
split of the individual changes.

Signed-off-by: Manfred Spraul <manfred@colorfullife.com>
Cc: Nick Piggin <npiggin@suse.de>
Cc: Pierre Peiffer <peifferp@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
ipc/sem.c

index 2705fbbc437453a6660f8b7753cc0fe707321558..eac3f46a59686f9b610a5abf430c2cb37fec1459 100644 (file)
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -445,13 +445,13 @@ again:
                 * of the completed operation:
                 * - if the operation modified the array, then restart from the
                 *   head of the queue and check for threads that might be
-                *   waiting for semaphore values to become 0.
+                *   waiting for the new semaphore values.
                 * - if the operation didn't modify the array, then just
                 *   continue.
                 */
                alter = q->alter;
                wake_up_sem_queue(q, error);
-               if (alter)
+               if (alter && !error)
                        goto again;
        }
 }