afsmonitor: avoid double free on exit
[openafs.git] / src / mcas / solaris_x86_defns.h
1 /*
2 Copyright (c) 2003, Keir Fraser All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7
8     * Redistributions of source code must retain the above copyright
9     * notice, this list of conditions and the following disclaimer.
10     * Redistributions in binary form must reproduce the above
11     * copyright notice, this list of conditions and the following
12     * disclaimer in the documentation and/or other materials provided
13     * with the distribution.  Neither the name of the Keir Fraser
14     * nor the names of its contributors may be used to endorse or
15     * promote products derived from this software without specific
16     * prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef __SOLARIS_X86_DEFNS_H__
32 #define __SOLARIS_X86_DEFNS_H__
33
34 #ifndef SOLARIS_X86_686
35 #define SOLARIS_X86_686
36 #endif
37
38 #include <sys/types.h>
39 #include <sys/processor.h>
40 #include <sys/procset.h>
41 #include <sys/atomic.h>
42 #include <sched.h>
43 #include <alloca.h>
44
45 #define CACHE_LINE_SIZE 64
46
47 #if 0
48 #include <thread.h>
49 #define pthread_mutex_t mutex_t
50 #define pthread_cond_t  cond_t
51 #define pthread_t       thread_t
52 #define pthread_key_t   thread_key_t
53 #define pthread_create(_a,_b,_c,_d) thr_create(NULL,0,_c,_d,THR_BOUND|THR_NEW_LWP,_a)
54 #define pthread_join(_a,_b) thr_join(_a,NULL,NULL)
55 #define pthread_key_create(_a,_b) thr_keycreate(_a,_b)
56 #define pthread_setspecific(_a,_b) thr_setspecific(_a,_b)
57 static void *
58 pthread_getspecific(pthread_key_t _a)
59 {
60     void *__x;
61     thr_getspecific(_a, &__x);
62     return __x;
63 }
64
65 #define pthread_setconcurrency(_x) thr_setconcurrency(_x)
66 #define pthread_mutex_init(_a,_b) mutex_init(_a,USYNC_THREAD,NULL)
67 #define pthread_mutex_lock(_a) mutex_lock(_a)
68 #define pthread_mutex_unlock(_a) mutex_unlock(_a)
69 #define pthread_cond_init(_a,_b) cond_init(_a,USYNC_THREAD,NULL)
70 #define pthread_cond_wait(_a,_b) cond_wait(_a,_b)
71 #define pthread_cond_broadcast(_a) cond_broadcast(_a)
72 #else
73 #include <pthread.h>
74 #endif
75
76
77 /*
78  * I. Compare-and-swap.
79  */
80
81 #define CAS(_a, _o, _n)\
82 atomic_cas_32((_a), (_o), (_n))
83
84 #define FAS(_a, _n)\
85 atomic_swap_32((_a), (uint32_t)(_n))
86
87 /* Update Pointer location, return Old value. */
88 #define FASPO(_a, _n)\
89 atomic_swap_ptr((_a), (_n))
90
91 #define CASPO(_a, _o, _n)\
92 atomic_cas_ptr((_a), (void *) (_o), (void *) (_n))
93
94 #define CAS64(_a, _o, _n)\
95 (_u64) atomic_cas_64((volatile uint64_t *)(_a), (_o), (_n))
96
97 /* Update Integer location, return Old value. */
98 #define CASIO(_a, _o, _n)\
99 atomic_cas_32((volatile uint32_t *)(_a), (_o), (_n))
100
101 #define FASIO(_a, _n)\
102 atomic_swap_32((volatile uint32_t *)(_a), (_n))
103
104 /* Update 32/64-bit location, return Old value. */
105 #define CAS32O CAS
106 #define CAS64O CAS64
107
108
109 /*
110  * II. Memory barriers.
111  *  WMB(): All preceding write operations must commit before any later writes.
112  *  RMB(): All preceding read operations must commit before any later reads.
113  *  MB():  All preceding memory accesses must commit before any later accesses.
114  *
115  *  If the compiler does not observe these barriers (but any sane compiler
116  *  will!), then VOLATILE should be defined as 'volatile'.
117  */
118
119 #define WMB() membar_producer
120 #define RMB() membar_consumer
121 #define MB()\
122 (membar_enter(),membar_exit(),membar_producer(),membar_consumer())
123
124 #define VOLATILE                volatile
125
126 /* On Intel, CAS is a strong barrier, but not a compile barrier. */
127 #define RMB_NEAR_CAS() WMB()
128 #define WMB_NEAR_CAS() WMB()
129 #define MB_NEAR_CAS()  WMB()
130
131 /*
132  * III. Cycle counter access.
133  */
134
135 #if 1 /* Sun Studio 12 */
136 typedef unsigned long long tick_t;
137 #define RDTICK() \
138     ({ tick_t __t; __asm__ __volatile__ ("rdtsc" : "=A" (__t)); __t; })
139 #else
140 typedef unsigned long tick_t;
141 extern tick_t RDTICK(void);
142 #endif
143
144
145 /*
146  * IV. Types.
147  */
148
149 typedef unsigned char _u8;
150 typedef unsigned short _u16;
151 typedef unsigned int _u32;
152 typedef unsigned long long _u64;
153
154 #endif /* __SOLARIS_X86_DEFNS_H__ */