]> git.ipfire.org Git - thirdparty/glibc.git/blame - linuxthreads/sysdeps/ia64/pspinlock.c
Test for stack alignment.
[thirdparty/glibc.git] / linuxthreads / sysdeps / ia64 / pspinlock.c
CommitLineData
37d33038 1/* POSIX spinlock implementation. ia64 version.
35457070 2 Copyright (C) 2000, 2003 Free Software Foundation, Inc.
37d33038
UD
3 This file is part of the GNU C Library.
4 Contributed by Jes Sorensen <jes@linuxcare.com>
5
6 The GNU C Library is free software; you can redistribute it and/or
cc7375ce
RM
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
37d33038
UD
9 License, or (at your option) any later version.
10
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
cc7375ce 14 Lesser General Public License for more details.
37d33038 15
cc7375ce 16 You should have received a copy of the GNU Lesser General Public
37d33038
UD
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. */
20
21#include <errno.h>
22#include <pthread.h>
27ee0a55 23#include "internals.h"
35457070 24#include <ia64intrin.h>
37d33038
UD
25
26/* This implementation is inspired by the implementation used in the
27 Linux kernel. */
28
29int
30__pthread_spin_lock (pthread_spinlock_t *lock)
31{
35457070
UD
32 int *p = (int *) lock;
33
34 while (__builtin_expect (__sync_val_compare_and_swap_si (p, 0, 1), 0))
35 {
36 /* Spin without using the atomic instruction. */
37 do
38 __asm __volatile ("" : : : "memory");
39 while (*p);
40 }
37d33038
UD
41 return 0;
42}
43weak_alias (__pthread_spin_lock, pthread_spin_lock)
44
45
46int
47__pthread_spin_trylock (pthread_spinlock_t *lock)
48{
35457070 49 return __sync_val_compare_and_swap_si ((int *) lock, 0, 1) == 0 ? 0 : EBUSY;
37d33038
UD
50}
51weak_alias (__pthread_spin_trylock, pthread_spin_trylock)
52
53
54int
55__pthread_spin_unlock (pthread_spinlock_t *lock)
56{
57 return *lock = 0;
58}
59weak_alias (__pthread_spin_unlock, pthread_spin_unlock)
60
61
62int
63__pthread_spin_init (pthread_spinlock_t *lock, int pshared)
64{
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;
69}
70weak_alias (__pthread_spin_init, pthread_spin_init)
71
72
73int
74__pthread_spin_destroy (pthread_spinlock_t *lock)
75{
76 /* Nothing to do. */
77 return 0;
78}
79weak_alias (__pthread_spin_destroy, pthread_spin_destroy)