blob: fa10c7b37e71fca3438abb3ccc2ae71896138e02 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* 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>
5
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.
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
14 Lesser General Public License for more details.
15
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. */
20
21#include <errno.h>
22#include <pthread.h>
23#include "internals.h"
24#include <ia64intrin.h>
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{
32 int *p = (int *) lock;
33
34 while (__builtin_expect (__sync_val_compare_and_swap (p, 0, 1), 0))
35 {
36 /* Spin without using the atomic instruction. */
37 do
38 __asm__ __volatile__ ("" : : : "memory");
39 while (*p);
40 }
41 return 0;
42}
43weak_alias (__pthread_spin_lock, pthread_spin_lock)
44
45
46int
47__pthread_spin_trylock (pthread_spinlock_t *lock)
48{
49 return __sync_val_compare_and_swap ((int *) lock, 0, 1) == 0 ? 0 : EBUSY;
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)