2 Copyright (c) 2003, Keir Fraser All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
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.
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.
31 #ifndef __SPARC_DEFNS_H__
32 #define __SPARC_DEFNS_H__
38 #include <sys/types.h>
39 #include <sys/processor.h>
40 #include <sys/procset.h>
44 #define CACHE_LINE_SIZE 64
48 #define pthread_mutex_t mutex_t
49 #define pthread_cond_t cond_t
50 #define pthread_t thread_t
51 #define pthread_key_t thread_key_t
52 #define pthread_create(_a,_b,_c,_d) thr_create(NULL,0,_c,_d,THR_BOUND|THR_NEW_LWP,_a)
53 #define pthread_join(_a,_b) thr_join(_a,NULL,NULL)
54 #define pthread_key_create(_a,_b) thr_keycreate(_a,_b)
55 #define pthread_setspecific(_a,_b) thr_setspecific(_a,_b)
56 static void *pthread_getspecific(pthread_key_t _a
)
59 thr_getspecific(_a
,&__x
);
62 #define pthread_setconcurrency(_x) thr_setconcurrency(_x)
63 #define pthread_mutex_init(_a,_b) mutex_init(_a,USYNC_THREAD,NULL)
64 #define pthread_mutex_lock(_a) mutex_lock(_a)
65 #define pthread_mutex_unlock(_a) mutex_unlock(_a)
66 #define pthread_cond_init(_a,_b) cond_init(_a,USYNC_THREAD,NULL)
67 #define pthread_cond_wait(_a,_b) cond_wait(_a,_b)
68 #define pthread_cond_broadcast(_a) cond_broadcast(_a)
75 * I. Compare-and-swap.
78 typedef unsigned long long _u64
;
80 extern int CASIO_internal(int *, int, int);
81 extern void * CASPO_internal(void *, void *, void *);
82 extern _u64
CAS64O_internal(_u64
*, _u64
, _u64
);
83 #define CASIO(_a,_o,_n) (CASIO_internal((int*)(_a),(int)(_o),(int)(_n)))
84 #define CASPO(_a,_o,_n) (CASPO_internal((void*)(_a),(void*)(_o),(void*)(_n)))
85 #define CAS32O(_a,_o,_n) (_u32)(CASIO_internal((int *)_a,(int)_o,(int)_n))
86 #define CAS64O(_a,_o,_n) (CAS64O_internal((_u64 *)_a,(_u64)_o,(_u64)_n))
88 static int FASIO(int *a
, int n
)
91 while ( (no
= CASIO(a
, o
, n
)) != o
) o
= no
;
95 static void *FASPO(void *a
, void *n
)
97 void *no
, *o
= *(void **)a
;
98 while ( (no
= CASPO(a
, o
, n
)) != o
) o
= no
;
104 * II. Memory barriers.
105 * WMB(): All preceding write operations must commit before any later writes.
106 * RMB(): All preceding read operations must commit before any later reads.
107 * MB(): All preceding memory accesses must commit before any later accesses.
109 * If the compiler does not observe these barriers (but any sane compiler
110 * will!), then VOLATILE should be defined as 'volatile'.
113 extern void MEMBAR_ALL(void);
114 extern void MEMBAR_STORESTORE(void);
115 extern void MEMBAR_LOADLOAD(void);
116 #define MB() MEMBAR_ALL()
117 #define WMB() MEMBAR_STORESTORE()
118 #define RMB() MEMBAR_LOADLOAD()
119 #define VOLATILE /*volatile*/
123 * III. Cycle counter access.
126 typedef unsigned long tick_t
;
127 extern tick_t
RDTICK(void);
134 typedef unsigned char _u8
;
135 typedef unsigned short _u16
;
136 typedef unsigned int _u32
;
138 #endif /* __SPARC_DEFNS_H__ */