Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
ittnotify_config.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005-2019 Intel Corporation
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16 
17 
18 
19 */
20 
21 #ifndef _ITTNOTIFY_CONFIG_H_
22 #define _ITTNOTIFY_CONFIG_H_
23 
25 #ifndef ITT_OS_WIN
26 # define ITT_OS_WIN 1
27 #endif /* ITT_OS_WIN */
28 
29 #ifndef ITT_OS_LINUX
30 # define ITT_OS_LINUX 2
31 #endif /* ITT_OS_LINUX */
32 
33 #ifndef ITT_OS_MAC
34 # define ITT_OS_MAC 3
35 #endif /* ITT_OS_MAC */
36 
37 #ifndef ITT_OS_FREEBSD
38 # define ITT_OS_FREEBSD 4
39 #endif /* ITT_OS_FREEBSD */
40 
41 #ifndef ITT_OS
42 # if defined WIN32 || defined _WIN32
43 # define ITT_OS ITT_OS_WIN
44 # elif defined( __APPLE__ ) && defined( __MACH__ )
45 # define ITT_OS ITT_OS_MAC
46 # elif defined( __FreeBSD__ )
47 # define ITT_OS ITT_OS_FREEBSD
48 # else
49 # define ITT_OS ITT_OS_LINUX
50 # endif
51 #endif /* ITT_OS */
52 
53 #ifndef ITT_PLATFORM_WIN
54 # define ITT_PLATFORM_WIN 1
55 #endif /* ITT_PLATFORM_WIN */
56 
57 #ifndef ITT_PLATFORM_POSIX
58 # define ITT_PLATFORM_POSIX 2
59 #endif /* ITT_PLATFORM_POSIX */
60 
61 #ifndef ITT_PLATFORM_MAC
62 # define ITT_PLATFORM_MAC 3
63 #endif /* ITT_PLATFORM_MAC */
64 
65 #ifndef ITT_PLATFORM_FREEBSD
66 # define ITT_PLATFORM_FREEBSD 4
67 #endif /* ITT_PLATFORM_FREEBSD */
68 
69 #ifndef ITT_PLATFORM
70 # if ITT_OS==ITT_OS_WIN
71 # define ITT_PLATFORM ITT_PLATFORM_WIN
72 # elif ITT_OS==ITT_OS_MAC
73 # define ITT_PLATFORM ITT_PLATFORM_MAC
74 # elif ITT_OS==ITT_OS_FREEBSD
75 # define ITT_PLATFORM ITT_PLATFORM_FREEBSD
76 # else
77 # define ITT_PLATFORM ITT_PLATFORM_POSIX
78 # endif
79 #endif /* ITT_PLATFORM */
80 
81 #if defined(_UNICODE) && !defined(UNICODE)
82 #define UNICODE
83 #endif
84 
85 #include <stddef.h>
86 #if ITT_PLATFORM==ITT_PLATFORM_WIN
87 #include <tchar.h>
88 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
89 #include <stdint.h>
90 #if defined(UNICODE) || defined(_UNICODE)
91 #include <wchar.h>
92 #endif /* UNICODE || _UNICODE */
93 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
94 
95 #ifndef CDECL
96 # if ITT_PLATFORM==ITT_PLATFORM_WIN
97 # define CDECL __cdecl
98 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
99 # if defined _M_IX86 || defined __i386__
100 # define CDECL __attribute__ ((cdecl))
101 # else /* _M_IX86 || __i386__ */
102 # define CDECL /* actual only on x86 platform */
103 # endif /* _M_IX86 || __i386__ */
104 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
105 #endif /* CDECL */
106 
107 #ifndef STDCALL
108 # if ITT_PLATFORM==ITT_PLATFORM_WIN
109 # define STDCALL __stdcall
110 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
111 # if defined _M_IX86 || defined __i386__
112 # define STDCALL __attribute__ ((stdcall))
113 # else /* _M_IX86 || __i386__ */
114 # define STDCALL /* supported only on x86 platform */
115 # endif /* _M_IX86 || __i386__ */
116 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
117 #endif /* STDCALL */
118 
119 #define ITTAPI CDECL
120 #define LIBITTAPI CDECL
121 
122 /* TODO: Temporary for compatibility! */
123 #define ITTAPI_CALL CDECL
124 #define LIBITTAPI_CALL CDECL
125 
126 #if ITT_PLATFORM==ITT_PLATFORM_WIN
127 /* use __forceinline (VC++ specific) */
128 #define ITT_INLINE __forceinline
129 #define ITT_INLINE_ATTRIBUTE /* nothing */
130 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
131 /*
132  * Generally, functions are not inlined unless optimization is specified.
133  * For functions declared inline, this attribute inlines the function even
134  * if no optimization level was specified.
135  */
136 #ifdef __STRICT_ANSI__
137 #define ITT_INLINE static
138 #define ITT_INLINE_ATTRIBUTE __attribute__((unused))
139 #else /* __STRICT_ANSI__ */
140 #define ITT_INLINE static inline
141 #define ITT_INLINE_ATTRIBUTE __attribute__((always_inline, unused))
142 #endif /* __STRICT_ANSI__ */
143 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
144 
146 #ifndef ITT_ARCH_IA32
147 # define ITT_ARCH_IA32 1
148 #endif /* ITT_ARCH_IA32 */
149 
150 #ifndef ITT_ARCH_IA32E
151 # define ITT_ARCH_IA32E 2
152 #endif /* ITT_ARCH_IA32E */
153 
154 #ifndef ITT_ARCH_ARM
155 # define ITT_ARCH_ARM 4
156 #endif /* ITT_ARCH_ARM */
157 
158 #ifndef ITT_ARCH_PPC64
159 # define ITT_ARCH_PPC64 5
160 #endif /* ITT_ARCH_PPC64 */
161 
162 #ifndef ITT_ARCH
163 # if defined _M_IX86 || defined __i386__
164 # define ITT_ARCH ITT_ARCH_IA32
165 # elif defined _M_X64 || defined _M_AMD64 || defined __x86_64__
166 # define ITT_ARCH ITT_ARCH_IA32E
167 # elif defined _M_IA64 || defined __ia64__
168 # define ITT_ARCH ITT_ARCH_IA64
169 # elif defined _M_ARM || __arm__
170 # define ITT_ARCH ITT_ARCH_ARM
171 # elif defined __powerpc64__
172 # define ITT_ARCH ITT_ARCH_PPC64
173 # endif
174 #endif
175 
176 #ifdef __cplusplus
177 # define ITT_EXTERN_C extern "C"
178 # define ITT_EXTERN_C_BEGIN extern "C" {
179 # define ITT_EXTERN_C_END }
180 #else
181 # define ITT_EXTERN_C /* nothing */
182 # define ITT_EXTERN_C_BEGIN /* nothing */
183 # define ITT_EXTERN_C_END /* nothing */
184 #endif /* __cplusplus */
185 
186 #define ITT_TO_STR_AUX(x) #x
187 #define ITT_TO_STR(x) ITT_TO_STR_AUX(x)
188 
189 #define __ITT_BUILD_ASSERT(expr, suffix) do { \
190  static char __itt_build_check_##suffix[(expr) ? 1 : -1]; \
191  __itt_build_check_##suffix[0] = 0; \
192 } while(0)
193 #define _ITT_BUILD_ASSERT(expr, suffix) __ITT_BUILD_ASSERT((expr), suffix)
194 #define ITT_BUILD_ASSERT(expr) _ITT_BUILD_ASSERT((expr), __LINE__)
195 
196 #define ITT_MAGIC { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 }
197 
198 /* Replace with snapshot date YYYYMMDD for promotion build. */
199 #define API_VERSION_BUILD 20111111
200 
201 #ifndef API_VERSION_NUM
202 #define API_VERSION_NUM 0.0.0
203 #endif /* API_VERSION_NUM */
204 
205 #define API_VERSION "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) \
206  " (" ITT_TO_STR(API_VERSION_BUILD) ")"
207 
208 /* OS communication functions */
209 #if ITT_PLATFORM==ITT_PLATFORM_WIN
210 #include <windows.h>
211 typedef HMODULE lib_t;
212 typedef DWORD TIDT;
213 typedef CRITICAL_SECTION mutex_t;
214 #define MUTEX_INITIALIZER { 0 }
215 #define strong_alias(name, aliasname) /* empty for Windows */
216 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
217 #include <dlfcn.h>
218 #if defined(UNICODE) || defined(_UNICODE)
219 #include <wchar.h>
220 #endif /* UNICODE */
221 #ifndef _GNU_SOURCE
222 #define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */
223 #endif /* _GNU_SOURCE */
224 #ifndef __USE_UNIX98
225 #define __USE_UNIX98 1 /* need for PTHREAD_MUTEX_RECURSIVE, on SLES11.1 with gcc 4.3.4 wherein pthread.h missing dependency on __USE_XOPEN2K8 */
226 #endif /*__USE_UNIX98*/
227 #include <pthread.h>
228 typedef void* lib_t;
229 typedef pthread_t TIDT;
230 typedef pthread_mutex_t mutex_t;
231 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
232 #define _strong_alias(name, aliasname) \
233  extern __typeof (name) aliasname __attribute__ ((alias (#name)));
234 #define strong_alias(name, aliasname) _strong_alias(name, aliasname)
235 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
236 
237 #if ITT_PLATFORM==ITT_PLATFORM_WIN
238 #define __itt_get_proc(lib, name) GetProcAddress(lib, name)
239 #define __itt_mutex_init(mutex) InitializeCriticalSection(mutex)
240 #define __itt_mutex_lock(mutex) EnterCriticalSection(mutex)
241 #define __itt_mutex_unlock(mutex) LeaveCriticalSection(mutex)
242 #define __itt_load_lib(name) LoadLibraryA(name)
243 #define __itt_unload_lib(handle) FreeLibrary(handle)
244 #define __itt_system_error() (int)GetLastError()
245 #define __itt_fstrcmp(s1, s2) lstrcmpA(s1, s2)
246 #define __itt_fstrnlen(s, l) strnlen_s(s, l)
247 #define __itt_fstrcpyn(s1, b, s2, l) strncpy_s(s1, b, s2, l)
248 #define __itt_fstrdup(s) _strdup(s)
249 #define __itt_thread_id() GetCurrentThreadId()
250 #define __itt_thread_yield() SwitchToThread()
251 #ifndef ITT_SIMPLE_INIT
252 ITT_INLINE long
253 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
254 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
255 {
256  return InterlockedIncrement(ptr);
257 }
258 #endif /* ITT_SIMPLE_INIT */
259 #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
260 #define __itt_get_proc(lib, name) dlsym(lib, name)
261 #define __itt_mutex_init(mutex) {\
262  pthread_mutexattr_t mutex_attr; \
263  int error_code = pthread_mutexattr_init(&mutex_attr); \
264  if (error_code) \
265  __itt_report_error(__itt_error_system, "pthread_mutexattr_init", \
266  error_code); \
267  error_code = pthread_mutexattr_settype(&mutex_attr, \
268  PTHREAD_MUTEX_RECURSIVE); \
269  if (error_code) \
270  __itt_report_error(__itt_error_system, "pthread_mutexattr_settype", \
271  error_code); \
272  error_code = pthread_mutex_init(mutex, &mutex_attr); \
273  if (error_code) \
274  __itt_report_error(__itt_error_system, "pthread_mutex_init", \
275  error_code); \
276  error_code = pthread_mutexattr_destroy(&mutex_attr); \
277  if (error_code) \
278  __itt_report_error(__itt_error_system, "pthread_mutexattr_destroy", \
279  error_code); \
280 }
281 #define __itt_mutex_lock(mutex) pthread_mutex_lock(mutex)
282 #define __itt_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
283 #define __itt_load_lib(name) dlopen(name, RTLD_LAZY)
284 #define __itt_unload_lib(handle) dlclose(handle)
285 #define __itt_system_error() errno
286 #define __itt_fstrcmp(s1, s2) strcmp(s1, s2)
287 
288 /* makes customer code define safe APIs for SDL_STRNLEN_S and SDL_STRNCPY_S */
289 #ifdef SDL_STRNLEN_S
290 #define __itt_fstrnlen(s, l) SDL_STRNLEN_S(s, l)
291 #else
292 #define __itt_fstrnlen(s, l) strlen(s)
293 #endif /* SDL_STRNLEN_S */
294 #ifdef SDL_STRNCPY_S
295 #define __itt_fstrcpyn(s1, b, s2, l) SDL_STRNCPY_S(s1, b, s2, l)
296 #else
297 #define __itt_fstrcpyn(s1, b, s2, l) { \
298  if (b > 0) { \
299  /* 'volatile' is used to suppress the warning that a destination */ \
300  /* bound depends on the length of the source. */ \
301  volatile size_t num_to_copy = (size_t)(b - 1) < (size_t)(l) ? \
302  (size_t)(b - 1) : (size_t)(l); \
303  strncpy(s1, s2, num_to_copy); \
304  s1[num_to_copy] = 0; \
305  } \
306 }
307 #endif /* SDL_STRNCPY_S */
308 
309 #define __itt_fstrdup(s) strdup(s)
310 #define __itt_thread_id() pthread_self()
311 #define __itt_thread_yield() sched_yield()
312 #if ITT_ARCH==ITT_ARCH_IA64
313 #ifdef __INTEL_COMPILER
314 #define __TBB_machine_fetchadd4(addr, val) __fetchadd4_acq((void *)addr, val)
315 #else /* __INTEL_COMPILER */
316 /* TODO: Add Support for not Intel compilers for IA-64 architecture */
317 #endif /* __INTEL_COMPILER */
318 #elif ITT_ARCH==ITT_ARCH_IA32 || ITT_ARCH==ITT_ARCH_IA32E /* ITT_ARCH!=ITT_ARCH_IA64 */
319 ITT_INLINE long
320 __TBB_machine_fetchadd4(volatile void* ptr, long addend) ITT_INLINE_ATTRIBUTE;
321 ITT_INLINE long __TBB_machine_fetchadd4(volatile void* ptr, long addend)
322 {
323  long result;
324  __asm__ __volatile__("lock\nxadd %0,%1"
325  : "=r"(result),"=m"(*(int*)ptr)
326  : "0"(addend), "m"(*(int*)ptr)
327  : "memory");
328  return result;
329 }
330 #elif ITT_ARCH==ITT_ARCH_ARM || ITT_ARCH==ITT_ARCH_PPC64
331 #define __TBB_machine_fetchadd4(addr, val) __sync_fetch_and_add(addr, val)
332 #endif /* ITT_ARCH==ITT_ARCH_IA64 */
333 #ifndef ITT_SIMPLE_INIT
334 ITT_INLINE long
335 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
336 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
337 {
338  return __TBB_machine_fetchadd4(ptr, 1) + 1L;
339 }
340 #endif /* ITT_SIMPLE_INIT */
341 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
342 
343 typedef enum {
347 
348 typedef enum {
352 
353 #pragma pack(push, 8)
354 
355 typedef struct ___itt_thread_info
356 {
357  const char* nameA;
358 #if defined(UNICODE) || defined(_UNICODE)
359  const wchar_t* nameW;
360 #else /* UNICODE || _UNICODE */
361  void* nameW;
362 #endif /* UNICODE || _UNICODE */
365  int extra1;
366  void* extra2;
369 
370 #include "ittnotify_types.h" /* For __itt_group_id definition */
371 
373 {
374  const char* name;
375  void** func_ptr;
376  void* init_func;
379 
380 typedef struct ___itt_api_info
381 {
382  const char* name;
383  void** func_ptr;
384  void* init_func;
385  void* null_func;
388 
389 struct ___itt_domain;
390 struct ___itt_string_handle;
391 
392 typedef struct ___itt_global
393 {
394  unsigned char magic[8];
395  unsigned long version_major;
396  unsigned long version_minor;
397  unsigned long version_build;
398  volatile long api_initialized;
399  volatile long mutex_initialized;
400  volatile long atomic_counter;
404  const char** dll_path_ptr;
407  /* Joinable structures below */
409  struct ___itt_domain* domain_list;
410  struct ___itt_string_handle* string_list;
412 } __itt_global;
413 
414 #pragma pack(pop)
415 
416 #define NEW_THREAD_INFO_W(gptr,h,h_tail,t,s,n) { \
417  h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
418  if (h != NULL) { \
419  h->tid = t; \
420  h->nameA = NULL; \
421  h->nameW = n ? _wcsdup(n) : NULL; \
422  h->state = s; \
423  h->extra1 = 0; /* reserved */ \
424  h->extra2 = NULL; /* reserved */ \
425  h->next = NULL; \
426  if (h_tail == NULL) \
427  (gptr)->thread_list = h; \
428  else \
429  h_tail->next = h; \
430  } \
431 }
432 
433 #define NEW_THREAD_INFO_A(gptr,h,h_tail,t,s,n) { \
434  h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
435  if (h != NULL) { \
436  h->tid = t; \
437  h->nameA = n ? __itt_fstrdup(n) : NULL; \
438  h->nameW = NULL; \
439  h->state = s; \
440  h->extra1 = 0; /* reserved */ \
441  h->extra2 = NULL; /* reserved */ \
442  h->next = NULL; \
443  if (h_tail == NULL) \
444  (gptr)->thread_list = h; \
445  else \
446  h_tail->next = h; \
447  } \
448 }
449 
450 #define NEW_DOMAIN_W(gptr,h,h_tail,name) { \
451  h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
452  if (h != NULL) { \
453  h->flags = 1; /* domain is enabled by default */ \
454  h->nameA = NULL; \
455  h->nameW = name ? _wcsdup(name) : NULL; \
456  h->extra1 = 0; /* reserved */ \
457  h->extra2 = NULL; /* reserved */ \
458  h->next = NULL; \
459  if (h_tail == NULL) \
460  (gptr)->domain_list = h; \
461  else \
462  h_tail->next = h; \
463  } \
464 }
465 
466 #define NEW_DOMAIN_A(gptr,h,h_tail,name) { \
467  h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
468  if (h != NULL) { \
469  h->flags = 1; /* domain is enabled by default */ \
470  h->nameA = name ? __itt_fstrdup(name) : NULL; \
471  h->nameW = NULL; \
472  h->extra1 = 0; /* reserved */ \
473  h->extra2 = NULL; /* reserved */ \
474  h->next = NULL; \
475  if (h_tail == NULL) \
476  (gptr)->domain_list = h; \
477  else \
478  h_tail->next = h; \
479  } \
480 }
481 
482 #define NEW_STRING_HANDLE_W(gptr,h,h_tail,name) { \
483  h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
484  if (h != NULL) { \
485  h->strA = NULL; \
486  h->strW = name ? _wcsdup(name) : NULL; \
487  h->extra1 = 0; /* reserved */ \
488  h->extra2 = NULL; /* reserved */ \
489  h->next = NULL; \
490  if (h_tail == NULL) \
491  (gptr)->string_list = h; \
492  else \
493  h_tail->next = h; \
494  } \
495 }
496 
497 #define NEW_STRING_HANDLE_A(gptr,h,h_tail,name) { \
498  h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
499  if (h != NULL) { \
500  h->strA = name ? __itt_fstrdup(name) : NULL; \
501  h->strW = NULL; \
502  h->extra1 = 0; /* reserved */ \
503  h->extra2 = NULL; /* reserved */ \
504  h->next = NULL; \
505  if (h_tail == NULL) \
506  (gptr)->string_list = h; \
507  else \
508  h_tail->next = h; \
509  } \
510 }
511 
512 #endif /* _ITTNOTIFY_CONFIG_H_ */
struct ___itt_global * next
__itt_api_info * api_list_ptr
HMODULE lib_t
struct ___itt_domain * domain_list
DWORD TIDT
__itt_thread_info * thread_list
__itt_thread_state state
unsigned long version_major
__itt_thread_state
ITT_INLINE long __itt_interlocked_increment(volatile long *ptr) ITT_INLINE_ATTRIBUTE
volatile long api_initialized
struct ___itt_api_info __itt_api_info
volatile long atomic_counter
unsigned char magic[8]
unsigned long version_build
volatile long mutex_initialized
unsigned long version_minor
long __TBB_machine_fetchadd4(volatile void *ptr, __int32 addend)
const char * name
__itt_collection_state
__itt_collection_state state
__itt_group_id group
CRITICAL_SECTION mutex_t
struct ___itt_string_handle * string_list
const char ** dll_path_ptr
struct ___itt_thread_info __itt_thread_info
struct ___itt_global __itt_global
enum ___itt_group_id __itt_group_id
struct ___itt_thread_info * next
struct ___itt_api_info_20101001 __itt_api_info_20101001

Copyright © 2005-2019 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.