From f6a7ce04b503695f1a4aaf48fc81b227d0daf052 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Thu, 23 Jan 2003 07:58:29 +0000 Subject: Per patch from Nathan Field at ghs.com, fix the mips __compare_and_swap inline function. Without this fix, pthread_mutex_lock/pthread_mutex_unlock don't work on mips. --- libpthread/linuxthreads/sysdeps/mips/pt-machine.h | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'libpthread') diff --git a/libpthread/linuxthreads/sysdeps/mips/pt-machine.h b/libpthread/linuxthreads/sysdeps/mips/pt-machine.h index 527392308..c40ab9e3e 100644 --- a/libpthread/linuxthreads/sysdeps/mips/pt-machine.h +++ b/libpthread/linuxthreads/sysdeps/mips/pt-machine.h @@ -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. + + */ + } -- cgit v1.2.3