(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / linuxthreads / sysdeps / alpha / pspinlock.c
blob79b7836293392895f52f1510e4e5912aee5654f8
1 /* POSIX spinlock implementation. Alpha version.
2 Copyright (C) 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <errno.h>
21 #include <pthread.h>
22 #include "internals.h"
25 /* This implementation is similar to the one used in the Linux kernel.
26 But the kernel is byte instructions for the memory access. This is
27 faster but unusable here. The problem is that only 128
28 threads/processes could use the spinlock at the same time. If (by
29 a design error in the program) a thread/process would hold the
30 spinlock for a time long enough to accumulate 128 waiting
31 processes, the next one will find a positive value in the spinlock
32 and assume it is unlocked. We cannot accept that. */
34 int
35 __pthread_spin_lock (pthread_spinlock_t *lock)
37 unsigned int tmp;
38 asm volatile
39 ("1: ldl_l %0,%1\n"
40 " blbs %0,2f\n"
41 " or %0,1,%0\n"
42 " stl_c %0,%1\n"
43 " beq %0,2f\n"
44 " mb\n"
45 ".subsection 2\n"
46 "2: ldl %0,%1\n"
47 " blbs %0,2b\n"
48 " br 1b\n"
49 ".previous"
50 : "=r" (tmp), "=m" (lock)
51 : "m" (lock));
52 return 0;
54 weak_alias (__pthread_spin_lock, pthread_spin_lock)
57 int
58 __pthread_spin_trylock (pthread_spinlock_t *lock)
60 unsigned long int oldval;
61 unsigned long int temp;
63 asm volatile
64 ("1: ldl_l %0,%1\n"
65 " and %0,%3,%2\n"
66 " bne %2,2f\n"
67 " xor %0,%3,%0\n"
68 " stl_c %0,%1\n"
69 " beq %0,3f\n"
70 " mb\n"
71 "2:\n"
72 ".subsection 2\n"
73 "3: br 1b\n"
74 ".previous"
75 : "=&r" (temp), "=m" (*lock), "=&r" (oldval)
76 : "Ir" (1UL), "m" (*lock));
78 return oldval == 0 ? 0 : EBUSY;
80 weak_alias (__pthread_spin_trylock, pthread_spin_trylock)
83 int
84 __pthread_spin_unlock (pthread_spinlock_t *lock)
86 asm volatile ("mb");
87 return *lock = 0;
89 weak_alias (__pthread_spin_unlock, pthread_spin_unlock)
92 int
93 __pthread_spin_init (pthread_spinlock_t *lock, int pshared)
95 /* We can ignore the `pshared' parameter. Since we are busy-waiting
96 all processes which can access the memory location `lock' points
97 to can use the spinlock. */
98 *lock = 0;
99 return 0;
101 weak_alias (__pthread_spin_init, pthread_spin_init)
105 __pthread_spin_destroy (pthread_spinlock_t *lock)
107 /* Nothing to do. */
108 return 0;
110 weak_alias (__pthread_spin_destroy, pthread_spin_destroy)