(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / linuxthreads / sysdeps / ia64 / pspinlock.c
blob14c7f3a18115b2acee11eee58f426f2eb338c643
1 /* POSIX spinlock implementation. ia64 version.
2 Copyright (C) 2000, 2003 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jes Sorensen <jes@linuxcare.com>
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"
24 #include <ia64intrin.h>
26 /* This implementation is inspired by the implementation used in the
27 Linux kernel. */
29 int
30 __pthread_spin_lock (pthread_spinlock_t *lock)
32 int *p = (int *) lock;
34 while (__builtin_expect (__sync_val_compare_and_swap_si (p, 0, 1), 0))
36 /* Spin without using the atomic instruction. */
38 __asm __volatile ("" : : : "memory");
39 while (*p);
41 return 0;
43 weak_alias (__pthread_spin_lock, pthread_spin_lock)
46 int
47 __pthread_spin_trylock (pthread_spinlock_t *lock)
49 return __sync_val_compare_and_swap_si ((int *) lock, 0, 1) == 0 ? 0 : EBUSY;
51 weak_alias (__pthread_spin_trylock, pthread_spin_trylock)
54 int
55 __pthread_spin_unlock (pthread_spinlock_t *lock)
57 return *lock = 0;
59 weak_alias (__pthread_spin_unlock, pthread_spin_unlock)
62 int
63 __pthread_spin_init (pthread_spinlock_t *lock, int pshared)
65 /* We can ignore the `pshared' parameter. Since we are busy-waiting
66 all processes which can access the memory location `lock' points
67 to can use the spinlock. */
68 return *lock = 0;
70 weak_alias (__pthread_spin_init, pthread_spin_init)
73 int
74 __pthread_spin_destroy (pthread_spinlock_t *lock)
76 /* Nothing to do. */
77 return 0;
79 weak_alias (__pthread_spin_destroy, pthread_spin_destroy)