(main): Use exit, not pthread_exit.
[kopensolaris-gnu/glibc.git] / linuxthreads / spinlock.h
1 /* Linuxthreads - a simple clone()-based implementation of Posix        */
2 /* threads for Linux.                                                   */
3 /* Copyright (C) 1998 Xavier Leroy (Xavier.Leroy@inria.fr)              */
4 /*                                                                      */
5 /* This program is free software; you can redistribute it and/or        */
6 /* modify it under the terms of the GNU Library General Public License  */
7 /* as published by the Free Software Foundation; either version 2       */
8 /* of the License, or (at your option) any later version.               */
9 /*                                                                      */
10 /* This program 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        */
13 /* GNU Library General Public License for more details.                 */
14
15 /* Internal locks */
16
17 extern void __pthread_lock(struct _pthread_fastlock * lock);
18 extern int __pthread_trylock(struct _pthread_fastlock * lock);
19 extern void __pthread_unlock(struct _pthread_fastlock * lock);
20
21 static inline void __pthread_init_lock(struct _pthread_fastlock * lock)
22 {
23   lock->status = 0;
24   lock->spinlock = 0;
25 }
26
27 #define LOCK_INITIALIZER {0, 0}
28
29 #if defined(TEST_FOR_COMPARE_AND_SWAP)
30
31 extern int __pthread_has_cas;
32 extern int __pthread_compare_and_swap(long * ptr, long oldval, long newval,
33                                       int * spinlock);
34
35 static inline int compare_and_swap(long * ptr, long oldval, long newval,
36                                    int * spinlock)
37 {
38   if (__pthread_has_cas)
39     return __compare_and_swap(ptr, oldval, newval);
40   else
41     return __pthread_compare_and_swap(ptr, oldval, newval, spinlock);
42 }
43
44 #elif defined(HAS_COMPARE_AND_SWAP)
45
46 static inline int compare_and_swap(long * ptr, long oldval, long newval,
47                                    int * spinlock)
48 {
49   return __compare_and_swap(ptr, oldval, newval);
50 }
51
52 #else
53
54 extern int __pthread_compare_and_swap(long * ptr, long oldval, long newval,
55                                       int * spinlock);
56
57 static inline int compare_and_swap(long * ptr, long oldval, long newval,
58                                    int * spinlock)
59 {
60   return __pthread_compare_and_swap(ptr, oldval, newval, spinlock);
61 }
62
63 #endif