lockref: Limit number of cmpxchg loop retries
[linux-2.6-microblaze.git] / lib / lockref.c
index 3d468b5..5b34bbd 100644 (file)
@@ -9,6 +9,7 @@
  * failure case.
  */
 #define CMPXCHG_LOOP(CODE, SUCCESS) do {                                       \
+       int retry = 100;                                                        \
        struct lockref old;                                                     \
        BUILD_BUG_ON(sizeof(old) != 8);                                         \
        old.lock_count = READ_ONCE(lockref->lock_count);                        \
@@ -21,6 +22,8 @@
                if (likely(old.lock_count == prev.lock_count)) {                \
                        SUCCESS;                                                \
                }                                                               \
+               if (!--retry)                                                   \
+                       break;                                                  \
                cpu_relax();                                                    \
        }                                                                       \
 } while (0)