(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / linuxthreads / sysdeps / s390 / pspinlock.c
blobf963f35371e80e6b95c3aa05be23115b16b3da10
1 /* POSIX spinlock implementation. S/390 version.
2 Copyright (C) 2000, 2004 Free Software Foundation, Inc.
3 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include <errno.h>
22 #include <pthread.h>
23 #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 asm volatile(" basr 1,0\n"
38 "0: slr 0,0\n"
39 " cs 0,1,%1\n"
40 " jl 0b\n"
41 : "=m" (*lock)
42 : "m" (*lock) : "0", "1", "cc" );
43 return 0;
45 weak_alias (__pthread_spin_lock, pthread_spin_lock)
47 int
48 __pthread_spin_trylock (pthread_spinlock_t *lock)
50 int oldval;
52 asm volatile(" slr %1,%1\n"
53 " basr 1,0\n"
54 "0: cs %1,1,%0"
55 : "=m" (*lock), "=&d" (oldval)
56 : "m" (*lock) : "1", "cc" );
57 return oldval == 0 ? 0 : EBUSY;
59 weak_alias (__pthread_spin_trylock, pthread_spin_trylock)
62 int
63 __pthread_spin_unlock (pthread_spinlock_t *lock)
65 asm volatile(" xc 0(4,%0),0(%0)\n"
66 " bcr 15,0"
67 : : "a" (lock) : "memory" );
68 return 0;
70 weak_alias (__pthread_spin_unlock, pthread_spin_unlock)
73 int
74 __pthread_spin_init (pthread_spinlock_t *lock, int pshared)
76 /* We can ignore the `pshared' parameter. Since we are busy-waiting
77 all processes which can access the memory location `lock' points
78 to can use the spinlock. */
79 *lock = 0;
80 return 0;
82 weak_alias (__pthread_spin_init, pthread_spin_init)
85 int
86 __pthread_spin_destroy (pthread_spinlock_t *lock)
88 /* Nothing to do. */
89 return 0;
91 weak_alias (__pthread_spin_destroy, pthread_spin_destroy)