kDefs.h: Added risc-v to the K_ARCH_XXX defines.
[kstuff-mirror.git] / kProfiler2 / prfcorepre.cpp.h
blob9b05d2e3b3678096e1f9fc8a06eb8203a9611fbc
1 /* $Id$ */
2 /** @file
3 * kProfiler Mark 2 - Core Pre-Code Template.
4 */
6 /*
7 * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without
12 * restriction, including without limitation the rights to use,
13 * copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following
16 * conditions:
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
32 /** @def KPRF_OFF2PTR
33 * Internal helper for converting a offset to a pointer.
34 * @internal
36 #define KPRF_OFF2PTR(TypePrefix, TypeName, off, pHdr) \
37 ( (KPRF_TYPE(TypePrefix, TypeName)) ((off) + (KPRF_TYPE(,UPTR))pHdr) )
39 /** @def KPRF_PTR2OFF
40 * Internal helper for converting a pointer to a offset.
41 * @internal
43 #define KPRF_PTR2OFF(ptr, pHdr) \
44 ( (KPRF_TYPE(,UPTR))(ptr) - (KPRF_TYPE(,UPTR))(pHdr) )
46 /** @def KPRF_ALIGN
47 * The usual align macro.
48 * @internal
50 #define KPRF_ALIGN(n, align) ( ((n) + ( (align) - 1)) & ~((align) - 1) )
52 /** @def KPRF_SETMIN_ALIGN
53 * Ensures a minimum and aligned value.
54 * @internal
56 #define KPRF_SETMIN_ALIGN(n, min, align) \
57 do { \
58 if ((n) < (min)) \
59 (n) = (min); \
60 else { \
61 const KU32 u32 = ((n) + ( (align) - 1)) & ~((align) - 1); \
62 if (u32 >= (n)) \
63 (n) = u32; \
64 } \
65 } while (0)
67 /** @def KPRF_OFFSETOF
68 * My usual extended OFFSETOF macro, except this returns KU32 and mangles the type name.
69 * @internal
71 #define KPRF_OFFSETOF(kPrfType, Member) ( (KU32)(KUPTR)&((KPRF_TYPE(P,kPrfType))0)->Member )
73 /** @def PRF_SIZEOF
74 * Size of a kPrf type.
75 * @internal
77 #define KPRF_SIZEOF(kPrfType) sizeof(KPRF_TYPE(,kPrfType))
80 /** @def KPRF_NOW
81 * Gets the current timestamp.
83 #ifndef KPRF_NOW
84 # error "KPRF_NOW isn't defined!"
85 #endif
87 /** @def KRPF_IS_ACTIVE
88 * Checks if profiling is activated or not.
89 * The idea is to use some global variable for disabling and enabling
90 * profiling in order to deal with init/term issues.
92 #ifndef KPRF_IS_ACTIVE
93 # define KPRF_IS_ACTIVE() 1
94 #endif
96 /** @def KPRF_GET_HDR
97 * Gets the pointer to the profiler data header.
99 #ifndef KPRF_GET_HDR
100 # error "KPRF_GET_HDR isn't defined!"
101 #endif
103 /** @def KPRF_GET_THREADID
104 * Gets native thread id. This must be unique.
106 #ifndef KPRF_GET_THREADID
107 # error "KPRF_GET_THREADID isn't defined!"
108 #endif
110 /** @def KPRF_SET_THREAD
111 * Sets the pointer to the current thread so we can get to it
112 * without doing a linear search by thread id.
114 #ifndef KPRF_SET_THREAD
115 # error "KPRF_SET_THREAD isn't defined!"
116 #endif
118 /** @def KPRF_GET_THREAD
119 * Gets the pointer to the current thread as set by KPRF_SET_THREAD.
121 #ifndef KPRF_GET_THREAD
122 # error "KPRF_GET_THREAD isn't defined!"
123 #endif
125 /** @def KPRF_MODSEGS_LOCK
126 * Lock the module segment for updating.
128 #ifndef KPRF_MODSEGS_LOCK
129 # define KPRF_MODSEGS_LOCK() do { } while (0)
130 #endif
132 /** @def KPRF_MODSEGS_UNLOCK
133 * Unlock the module segments.
135 #ifndef KPRF_MODSEGS_UNLOCK
136 # define KPRF_MODSEGS_UNLOCK() do { } while (0)
137 #endif
139 /** @def KPRF_THREADS_LOCK
140 * Lock the threads for updating.
142 #ifndef KPRF_THREADS_LOCK
143 # define KPRF_THREADS_LOCK() do { } while (0)
144 #endif
146 /** @def KPRF_THREADS_UNLOCK
147 * Unlock the threads.
149 #ifndef KPRF_THREADS_UNLOCK
150 # define KPRF_THREADS_UNLOCK() do { } while (0)
151 #endif
153 /** @def KPRF_FUNCS_READ_LOCK
154 * Lock the functions for reading.
156 #ifndef KPRF_FUNCS_READ_LOCK
157 # define KPRF_FUNCS_READ_LOCK() do { } while (0)
158 #endif
160 /** @def KPRF_FUNCS_READ_UNLOCK
161 * Releases a read lock on the functions.
163 #ifndef KPRF_FUNCS_READ_UNLOCK
164 # define KPRF_FUNCS_READ_UNLOCK() do { } while (0)
165 #endif
167 /** @def KPRF_FUNCS_WRITE_LOCK
168 * Lock the functions for updating.
170 #ifndef KPRF_FUNCS_WRITE_LOCK
171 # define KPRF_FUNCS_WRITE_LOCK() do { } while (0)
172 #endif
174 /** @def KPRF_FUNCS_WRITE_UNLOCK
175 * Releases a write lock on the functions.
177 #ifndef KPRF_FUNCS_WRITE_UNLOCK
178 # define KPRF_FUNCS_WRITE_UNLOCK() do { } while (0)
179 #endif
182 /** @def KPRF_ATOMIC_SET32
183 * Atomically set a 32-bit value.
185 #ifndef KPRF_ATOMIC_SET32
186 # define KPRF_ATOMIC_SET32(pu32, u32) do { *(pu32) = (u32); } while (0)
187 #endif
189 /** @def KPRF_ATOMIC_SET64
190 * Atomically (well, in a safe way) adds to a 64-bit value.
192 #ifndef KPRF_ATOMIC_ADD64
193 # define KPRF_ATOMIC_ADD64(pu64, u64) do { *(pu64) += (u64); } while (0)
194 #endif
196 /** @def KPRF_ATOMIC_SET64
197 * Atomically (well, in a safe way) increments a 64-bit value.
199 #ifndef KPRF_ATOMIC_INC64
200 # define KPRF_ATOMIC_INC64(pu64) KPRF_ATOMIC_ADD64(pu64, 1)
201 #endif