[PATCH 3/4] cr_tests: futex: pu: Fix potential livelock

Matt Helsley matthltc at us.ibm.com
Tue Apr 13 15:25:14 PDT 2010


Fixup flow of release_pi_futex to truly break out of the loop during
an error.

Also, since it's not used, remove the retries parameter from
do_unlock_contended_futex.

Signed-off-by: Matt Helsley <matthltc at us.ibm.com>
---
 futex/pi.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/futex/pi.c b/futex/pi.c
index 53d4c5d..a39964d 100644
--- a/futex/pi.c
+++ b/futex/pi.c
@@ -330,7 +330,7 @@ again:
 	return -1;
 }
 
-int do_unlock_contended_pi_futex(int retries)
+int do_unlock_contended_pi_futex(void)
 {
 	if (futex(&pi_futex->counter, FUTEX_UNLOCK_PI, 1, NULL, NULL, 0) == 0)
 		return 0;
@@ -400,12 +400,12 @@ void release_pi_futex(int *retries, int *retval, pid_t tid)
 		/* Release the futex */
 		pi_val = atomic_cmpxchg(pi_futex, tid, 0);
 		if (pi_val != tid) {
-		    switch (do_unlock_contended_pi_futex(*retries)) {
+		    switch (do_unlock_contended_pi_futex(void)) {
 		    case -1: /* error -- we already logged the details */
 			    *retval = -100;
-			    break;
+			    retries--;
 		    case 0: /* ok */
-			    break;
+			    goto released;
 		    case 1: /* try again */
 			    if (retries) {
 				    retries--;
@@ -416,6 +416,7 @@ void release_pi_futex(int *retries, int *retval, pid_t tid)
 		    }
 		} /* else we were the last to hold the futex */
 	} while(retries);
+released:
 
 	log("INFO", "exited the critical section\n");
 }
-- 
1.6.3.3



More information about the Containers mailing list