OSDN Git Service

Per patch from Nathan Field at ghs.com, fix the mips __compare_and_swap inline
authorEric Andersen <andersen@codepoet.org>
Thu, 23 Jan 2003 07:58:29 +0000 (07:58 -0000)
committerEric Andersen <andersen@codepoet.org>
Thu, 23 Jan 2003 07:58:29 +0000 (07:58 -0000)
function.  Without this fix, pthread_mutex_lock/pthread_mutex_unlock don't work
on mips.

libpthread/linuxthreads/sysdeps/mips/pt-machine.h

index 5273923..c40ab9e 100644 (file)
@@ -77,6 +77,7 @@ __compare_and_swap (long int *p, long int oldval, long int newval)
        "1:\tll\t%0,%4\n\t"
        ".set\tnoreorder\n\t"
        "bne\t%0,%2,2f\n\t"
+       "move\t%0,$0\n\t" /*[NDF] Failure case. */
        "move\t%0,%3\n\t"
        ".set\treorder\n\t"
        "sc\t%0,%1\n\t"
@@ -87,4 +88,30 @@ __compare_and_swap (long int *p, long int oldval, long int newval)
        : "r"(oldval), "r"(newval), "m"(*p));
 
   return ret;
+
+  /*
+    1:  load locked: into ret(%0), from *p(0(%4))
+        branch to 2 if ret(%0) != oldval(%2)
+         Delay slot: move 0 into ret(%0) // [NDF] Added
+       Don't branch case:
+       move newval(%3) into ret(%0)
+       setcompare ret(%0) into *p(0(%1))
+       branch to 1 if ret(%0) == 0 (sc failed)
+         Delay slot: unknown/none
+       return
+
+    2: Delay slot
+       return
+
+ll a b
+Sets a to the value pointed to by address b, and "locks" b so that if
+any of a number of things are attempted that might access b then the
+next sc will fail.
+
+sc a b
+Sets the memory address pointed to by b to the value in a atomically.
+If it succeeds then a will be set to 1, if it fails a will be set to 0.
+
+  */
+
 }