summaryrefslogtreecommitdiff
path: root/linuxthreads/sysdeps/sparc/sparc32/pspinlock.c
diff options
context:
space:
mode:
Diffstat (limited to 'linuxthreads/sysdeps/sparc/sparc32/pspinlock.c')
-rw-r--r--linuxthreads/sysdeps/sparc/sparc32/pspinlock.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/linuxthreads/sysdeps/sparc/sparc32/pspinlock.c b/linuxthreads/sysdeps/sparc/sparc32/pspinlock.c
index ff72ff0c35..1788d7af33 100644
--- a/linuxthreads/sysdeps/sparc/sparc32/pspinlock.c
+++ b/linuxthreads/sysdeps/sparc/sparc32/pspinlock.c
@@ -21,10 +21,25 @@
#include <pthread.h>
+/* This implementation is similar to the one used in the Linux kernel. */
int
__pthread_spin_lock (pthread_spinlock_t *lock)
{
- XXX
+ asm volatile
+ ("1: ldstub [%0], %%g2\n"
+ " orcc %%g2, 0x0, %%g0\n"
+ " bne,a 2f\n"
+ " ldub [%0], %%g2\n"
+ ".subsection 2\n"
+ "2: orcc %%g2, 0x0, %%g0\n"
+ " bne,a 2b\n"
+ " ldub [%0], %%g2\n"
+ " b,a 1b\n"
+ ".previous"
+ : /* no outputs */
+ : "r" (lock)
+ : "g2", "memory", "cc");
+ return 0;
}
weak_alias (__pthread_spin_lock, pthread_spin_lock)
@@ -32,7 +47,13 @@ weak_alias (__pthread_spin_lock, pthread_spin_lock)
int
__pthread_spin_trylock (pthread_spinlock_t *lock)
{
- XXX
+ int result;
+ asm volatile
+ ("ldstub [%1], %0"
+ : "=r" (result)
+ : "r" (lock)
+ : "memory");
+ return result == 0 ? 0 : EBUSY;
}
weak_alias (__pthread_spin_trylock, pthread_spin_trylock)
@@ -40,7 +61,8 @@ weak_alias (__pthread_spin_trylock, pthread_spin_trylock)
int
__pthread_spin_unlock (pthread_spinlock_t *lock)
{
- XXX
+ *lock = 0;
+ return 0;
}
weak_alias (__pthread_spin_unlock, pthread_spin_unlock)
@@ -51,7 +73,7 @@ __pthread_spin_init (pthread_spinlock_t *lock, int pshared)
/* We can ignore the `pshared' parameter. Since we are busy-waiting
all processes which can access the memory location `lock' points
to can use the spinlock. */
- XXX
+ *lock = 0;
return 0;
}
weak_alias (__pthread_spin_init, pthread_spin_init)