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

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.