summaryrefslogtreecommitdiffstats
path: root/src/lib/kStuff/kProfiler2/prfcorepre.cpp.h
blob: 50f6b6a523bc9ede42c2170492fdf6dad6c59de8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/* $Id: prfcorepre.cpp.h 29 2009-07-01 20:30:29Z bird $ */
/** @file
 * kProfiler Mark 2 - Core Pre-Code Template.
 */

/*
 * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */


/** @def KPRF_OFF2PTR
 * Internal helper for converting a offset to a pointer.
 * @internal
 */
#define KPRF_OFF2PTR(TypePrefix, TypeName, off, pHdr) \
    ( (KPRF_TYPE(TypePrefix, TypeName)) ((off) + (KPRF_TYPE(,UPTR))pHdr) )

/** @def KPRF_PTR2OFF
 * Internal helper for converting a pointer to a offset.
 * @internal
 */
#define KPRF_PTR2OFF(ptr, pHdr) \
    ( (KPRF_TYPE(,UPTR))(ptr) - (KPRF_TYPE(,UPTR))(pHdr) )

/** @def KPRF_ALIGN
 * The usual align macro.
 * @internal
 */
#define KPRF_ALIGN(n, align) ( ((n) + ( (align) - 1)) & ~((align) - 1) )

/** @def KPRF_SETMIN_ALIGN
 * Ensures a minimum and aligned value.
 * @internal
 */
#define KPRF_SETMIN_ALIGN(n, min, align) \
    do { \
        if ((n) < (min)) \
            (n) = (min); \
        else { \
            const KU32 u32 = ((n) + ( (align) - 1)) & ~((align) - 1); \
            if (u32 >= (n)) \
                (n) = u32; \
        } \
    } while (0)

/** @def KPRF_OFFSETOF
 * My usual extended OFFSETOF macro, except this returns KU32 and mangles the type name.
 * @internal
 */
#define KPRF_OFFSETOF(kPrfType, Member) ( (KU32)(KUPTR)&((KPRF_TYPE(P,kPrfType))0)->Member )

/** @def PRF_SIZEOF
 * Size of a kPrf type.
 * @internal
 */
#define KPRF_SIZEOF(kPrfType)       sizeof(KPRF_TYPE(,kPrfType))


/** @def KPRF_NOW
 * Gets the current timestamp.
 */
#ifndef KPRF_NOW
# error "KPRF_NOW isn't defined!"
#endif

/** @def KRPF_IS_ACTIVE
 * Checks if profiling is activated or not.
 * The idea is to use some global variable for disabling and enabling
 * profiling in order to deal with init/term issues.
 */
#ifndef KPRF_IS_ACTIVE
# define KPRF_IS_ACTIVE()           1
#endif

/** @def KPRF_GET_HDR
 * Gets the pointer to the profiler data header.
 */
#ifndef KPRF_GET_HDR
# error "KPRF_GET_HDR isn't defined!"
#endif

/** @def KPRF_GET_THREADID
 * Gets native thread id. This must be unique.
 */
#ifndef KPRF_GET_THREADID
# error "KPRF_GET_THREADID isn't defined!"
#endif

/** @def KPRF_SET_THREAD
 * Sets the pointer to the current thread so we can get to it
 * without doing a linear search by thread id.
 */
#ifndef KPRF_SET_THREAD
# error "KPRF_SET_THREAD isn't defined!"
#endif

/** @def KPRF_GET_THREAD
 * Gets the pointer to the current thread as set by KPRF_SET_THREAD.
 */
#ifndef KPRF_GET_THREAD
# error "KPRF_GET_THREAD isn't defined!"
#endif

/** @def KPRF_MODSEGS_LOCK
 * Lock the module segment for updating.
 */
#ifndef KPRF_MODSEGS_LOCK
# define KPRF_MODSEGS_LOCK()            do { } while (0)
#endif

/** @def KPRF_MODSEGS_UNLOCK
 * Unlock the module segments.
 */
#ifndef KPRF_MODSEGS_UNLOCK
# define KPRF_MODSEGS_UNLOCK()          do { } while (0)
#endif

/** @def KPRF_THREADS_LOCK
 * Lock the threads for updating.
 */
#ifndef KPRF_THREADS_LOCK
# define KPRF_THREADS_LOCK()            do { } while (0)
#endif

/** @def KPRF_THREADS_UNLOCK
 * Unlock the threads.
 */
#ifndef KPRF_THREADS_UNLOCK
# define KPRF_THREADS_UNLOCK()          do { } while (0)
#endif

/** @def KPRF_FUNCS_READ_LOCK
 * Lock the functions for reading.
 */
#ifndef KPRF_FUNCS_READ_LOCK
# define KPRF_FUNCS_READ_LOCK()         do { } while (0)
#endif

/** @def KPRF_FUNCS_READ_UNLOCK
 * Releases a read lock on the functions.
 */
#ifndef KPRF_FUNCS_READ_UNLOCK
# define KPRF_FUNCS_READ_UNLOCK()       do { } while (0)
#endif

/** @def KPRF_FUNCS_WRITE_LOCK
 * Lock the functions for updating.
 */
#ifndef KPRF_FUNCS_WRITE_LOCK
# define KPRF_FUNCS_WRITE_LOCK()        do { } while (0)
#endif

/** @def KPRF_FUNCS_WRITE_UNLOCK
 * Releases a write lock on the functions.
 */
#ifndef KPRF_FUNCS_WRITE_UNLOCK
# define KPRF_FUNCS_WRITE_UNLOCK()      do { } while (0)
#endif


/** @def KPRF_ATOMIC_SET32
 * Atomically set a 32-bit value.
 */
#ifndef KPRF_ATOMIC_SET32
# define KPRF_ATOMIC_SET32(pu32, u32)   do { *(pu32) = (u32); } while (0)
#endif

/** @def KPRF_ATOMIC_SET64
 * Atomically (well, in a safe way) adds to a 64-bit value.
 */
#ifndef KPRF_ATOMIC_ADD64
# define KPRF_ATOMIC_ADD64(pu64, u64)   do { *(pu64) += (u64); } while (0)
#endif

/** @def KPRF_ATOMIC_SET64
 * Atomically (well, in a safe way) increments a 64-bit value.
 */
#ifndef KPRF_ATOMIC_INC64
# define KPRF_ATOMIC_INC64(pu64)        KPRF_ATOMIC_ADD64(pu64, 1)
#endif