xref: /oneTBB/src/tbb/tools_api/ittnotify_config.h (revision 0a2b3987)
1 /*
2     Copyright (c) 2005-2021 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 
20 /** @cond exclude_from_documentation */
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 ITTAPI_CDECL
92 #  if ITT_PLATFORM==ITT_PLATFORM_WIN
93 #    define ITTAPI_CDECL __cdecl
94 #  else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
95 #    if defined _M_IX86 || defined __i386__
96 #      define ITTAPI_CDECL __attribute__ ((cdecl))
97 #    else  /* _M_IX86 || __i386__ */
98 #      define ITTAPI_CDECL /* actual only on x86 platform */
99 #    endif /* _M_IX86 || __i386__ */
100 #  endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
101 #endif /* ITTAPI_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    ITTAPI_CDECL
116 #define LIBITTAPI ITTAPI_CDECL
117 
118 /* TODO: Temporary for compatibility! */
119 #define ITTAPI_CALL    ITTAPI_CDECL
120 #define LIBITTAPI_CALL ITTAPI_CDECL
121 
122 #if ITT_PLATFORM==ITT_PLATFORM_WIN
123 /* use __forceinline (VC++ specific) */
124 #define ITT_INLINE           static __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 /** @endcond */
141 
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_ARM64
159 #  define ITT_ARCH_ARM64  6
160 #endif /* ITT_ARCH_ARM64 */
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 || defined __arm__
170 #    define ITT_ARCH ITT_ARCH_ARM
171 #  elif defined __aarch64__
172 #    define ITT_ARCH ITT_ARCH_ARM64
173 #  elif defined __powerpc64__
174 #    define ITT_ARCH ITT_ARCH_PPC64
175 #  endif
176 #endif
177 
178 #ifdef __cplusplus
179 #  define ITT_EXTERN_C extern "C"
180 #  define ITT_EXTERN_C_BEGIN extern "C" {
181 #  define ITT_EXTERN_C_END }
182 #else
183 #  define ITT_EXTERN_C /* nothing */
184 #  define ITT_EXTERN_C_BEGIN /* nothing */
185 #  define ITT_EXTERN_C_END /* nothing */
186 #endif /* __cplusplus */
187 
188 #define ITT_TO_STR_AUX(x) #x
189 #define ITT_TO_STR(x)     ITT_TO_STR_AUX(x)
190 
191 #define __ITT_BUILD_ASSERT(expr, suffix) do { \
192     static char __itt_build_check_##suffix[(expr) ? 1 : -1]; \
193     __itt_build_check_##suffix[0] = 0; \
194 } while(0)
195 #define _ITT_BUILD_ASSERT(expr, suffix)  __ITT_BUILD_ASSERT((expr), suffix)
196 #define ITT_BUILD_ASSERT(expr)           _ITT_BUILD_ASSERT((expr), __LINE__)
197 
198 #define ITT_MAGIC { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 }
199 
200 /* Replace with snapshot date YYYYMMDD for promotion build. */
201 #define API_VERSION_BUILD    20180723
202 
203 #ifndef API_VERSION_NUM
204 #define API_VERSION_NUM 3.18.6
205 #endif /* API_VERSION_NUM */
206 
207 #define API_VERSION "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) \
208                                 " (" ITT_TO_STR(API_VERSION_BUILD) ")"
209 
210 /* OS communication functions */
211 #if ITT_PLATFORM==ITT_PLATFORM_WIN
212 #include <windows.h>
213 typedef HMODULE           lib_t;
214 typedef DWORD             TIDT;
215 typedef CRITICAL_SECTION  mutex_t;
216 #ifdef __cplusplus
217 #define MUTEX_INITIALIZER {}
218 #else
219 #define MUTEX_INITIALIZER { 0 }
220 #endif
221 #define strong_alias(name, aliasname) /* empty for Windows */
222 #else  /* ITT_PLATFORM==ITT_PLATFORM_WIN */
223 #include <dlfcn.h>
224 #if defined(UNICODE) || defined(_UNICODE)
225 #include <wchar.h>
226 #endif /* UNICODE */
227 #ifndef _GNU_SOURCE
228 #define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */
229 #endif /* _GNU_SOURCE */
230 #ifndef __USE_UNIX98
231 #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 */
232 #endif /*__USE_UNIX98*/
233 #include <pthread.h>
234 typedef void*             lib_t;
235 typedef pthread_t         TIDT;
236 typedef pthread_mutex_t   mutex_t;
237 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
238 #define _strong_alias(name, aliasname) \
239             extern __typeof (name) aliasname __attribute__ ((alias (#name)));
240 #define strong_alias(name, aliasname) _strong_alias(name, aliasname)
241 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
242 
243 #if ITT_PLATFORM==ITT_PLATFORM_WIN
244 #define __itt_get_proc(lib, name) GetProcAddress(lib, name)
245 #define __itt_mutex_init(mutex)   InitializeCriticalSection(mutex)
246 #define __itt_mutex_lock(mutex)   EnterCriticalSection(mutex)
247 #define __itt_mutex_unlock(mutex) LeaveCriticalSection(mutex)
248 #define __itt_load_lib(name)      LoadLibraryA(name)
249 #define __itt_unload_lib(handle)  FreeLibrary(handle)
250 #define __itt_system_error()      (int)GetLastError()
251 #define __itt_fstrcmp(s1, s2)     lstrcmpA(s1, s2)
252 #define __itt_fstrnlen(s, l)      strnlen_s(s, l)
253 #define __itt_fstrcpyn(s1, b, s2, l) strncpy_s(s1, b, s2, l)
254 #define __itt_fstrdup(s)          _strdup(s)
255 #define __itt_thread_id()         GetCurrentThreadId()
256 #define __itt_thread_yield()      SwitchToThread()
257 #ifndef ITT_SIMPLE_INIT
258 ITT_INLINE long
259 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
260 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
261 {
262     return InterlockedIncrement(ptr);
263 }
264 #endif /* ITT_SIMPLE_INIT */
265 
266 #define DL_SYMBOLS (1)
267 #define PTHREAD_SYMBOLS (1)
268 
269 #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
270 #define __itt_get_proc(lib, name) dlsym(lib, name)
271 #define __itt_mutex_init(mutex)   {\
272     pthread_mutexattr_t mutex_attr;                                         \
273     int error_code = pthread_mutexattr_init(&mutex_attr);                   \
274     if (error_code)                                                         \
275         __itt_report_error(__itt_error_system, "pthread_mutexattr_init",    \
276                            error_code);                                     \
277     error_code = pthread_mutexattr_settype(&mutex_attr,                     \
278                                            PTHREAD_MUTEX_RECURSIVE);        \
279     if (error_code)                                                         \
280         __itt_report_error(__itt_error_system, "pthread_mutexattr_settype", \
281                            error_code);                                     \
282     error_code = pthread_mutex_init(mutex, &mutex_attr);                    \
283     if (error_code)                                                         \
284         __itt_report_error(__itt_error_system, "pthread_mutex_init",        \
285                            error_code);                                     \
286     error_code = pthread_mutexattr_destroy(&mutex_attr);                    \
287     if (error_code)                                                         \
288         __itt_report_error(__itt_error_system, "pthread_mutexattr_destroy", \
289                            error_code);                                     \
290 }
291 #define __itt_mutex_lock(mutex)   pthread_mutex_lock(mutex)
292 #define __itt_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
293 #define __itt_load_lib(name)      dlopen(name, RTLD_LAZY)
294 #define __itt_unload_lib(handle)  dlclose(handle)
295 #define __itt_system_error()      errno
296 #define __itt_fstrcmp(s1, s2)     strcmp(s1, s2)
297 
298 /* makes customer code define safe APIs for SDL_STRNLEN_S and SDL_STRNCPY_S */
299 #ifdef SDL_STRNLEN_S
300 #define __itt_fstrnlen(s, l)      SDL_STRNLEN_S(s, l)
301 #else
302 #define __itt_fstrnlen(s, l)      strlen(s)
303 #endif /* SDL_STRNLEN_S */
304 #ifdef SDL_STRNCPY_S
305 #define __itt_fstrcpyn(s1, b, s2, l) SDL_STRNCPY_S(s1, b, s2, l)
306 #else
307 #define __itt_fstrcpyn(s1, b, s2, l) {                                      \
308     if (b > 0) {                                                            \
309         /* 'volatile' is used to suppress the warning that a destination */ \
310         /*  bound depends on the length of the source.                   */ \
311         volatile size_t num_to_copy = (size_t)(b - 1) < (size_t)(l) ?       \
312                 (size_t)(b - 1) : (size_t)(l);                              \
313         strncpy(s1, s2, num_to_copy);                                       \
314         s1[num_to_copy] = 0;                                                \
315     }                                                                       \
316 }
317 #endif /* SDL_STRNCPY_S */
318 
319 #define __itt_fstrdup(s)          strdup(s)
320 #define __itt_thread_id()         pthread_self()
321 #define __itt_thread_yield()      sched_yield()
322 #if ITT_ARCH==ITT_ARCH_IA64
323 #ifdef __INTEL_COMPILER
324 #define __TBB_machine_fetchadd4(addr, val) __fetchadd4_acq((void *)addr, val)
325 #else  /* __INTEL_COMPILER */
326 /* TODO: Add Support for not Intel compilers for IA-64 architecture */
327 #endif /* __INTEL_COMPILER */
328 #elif ITT_ARCH==ITT_ARCH_IA32 || ITT_ARCH==ITT_ARCH_IA32E /* ITT_ARCH!=ITT_ARCH_IA64 */
329 ITT_INLINE long
330 __TBB_machine_fetchadd4(volatile void* ptr, long addend) ITT_INLINE_ATTRIBUTE;
331 ITT_INLINE long __TBB_machine_fetchadd4(volatile void* ptr, long addend)
332 {
333     long result;
334     __asm__ __volatile__("lock\nxadd %0,%1"
335                           : "=r"(result),"=m"(*(volatile int*)ptr)
336                           : "0"(addend), "m"(*(volatile int*)ptr)
337                           : "memory");
338     return result;
339 }
340 #else
341 #define __TBB_machine_fetchadd4(addr, val) __sync_fetch_and_add(addr, val)
342 #endif /* ITT_ARCH==ITT_ARCH_IA64 */
343 #ifndef ITT_SIMPLE_INIT
344 ITT_INLINE long
345 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
346 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
347 {
348     return __TBB_machine_fetchadd4(ptr, 1) + 1L;
349 }
350 #endif /* ITT_SIMPLE_INIT */
351 
352 void* dlopen(const char*, int) __attribute__((weak));
353 void* dlsym(void*, const char*) __attribute__((weak));
354 int dlclose(void*) __attribute__((weak));
355 #define DL_SYMBOLS (dlopen && dlsym && dlclose)
356 
357 int pthread_mutex_init(pthread_mutex_t*, const pthread_mutexattr_t*) __attribute__((weak));
358 int pthread_mutex_lock(pthread_mutex_t*) __attribute__((weak));
359 int pthread_mutex_unlock(pthread_mutex_t*) __attribute__((weak));
360 int pthread_mutex_destroy(pthread_mutex_t*) __attribute__((weak));
361 int pthread_mutexattr_init(pthread_mutexattr_t*) __attribute__((weak));
362 int pthread_mutexattr_settype(pthread_mutexattr_t*, int) __attribute__((weak));
363 int pthread_mutexattr_destroy(pthread_mutexattr_t*) __attribute__((weak));
364 pthread_t pthread_self(void) __attribute__((weak));
365 #define PTHREAD_SYMBOLS (pthread_mutex_init && pthread_mutex_lock && pthread_mutex_unlock && pthread_mutex_destroy && pthread_mutexattr_init && pthread_mutexattr_settype && pthread_mutexattr_destroy && pthread_self)
366 
367 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
368 
369 typedef enum {
370     __itt_collection_normal = 0,
371     __itt_collection_paused = 1
372 } __itt_collection_state;
373 
374 typedef enum {
375     __itt_thread_normal  = 0,
376     __itt_thread_ignored = 1
377 } __itt_thread_state;
378 
379 #pragma pack(push, 8)
380 
381 typedef struct ___itt_thread_info
382 {
383     const char* nameA; /*!< Copy of original name in ASCII. */
384 #if defined(UNICODE) || defined(_UNICODE)
385     const wchar_t* nameW; /*!< Copy of original name in UNICODE. */
386 #else  /* UNICODE || _UNICODE */
387     void* nameW;
388 #endif /* UNICODE || _UNICODE */
389     TIDT               tid;
390     __itt_thread_state state;   /*!< Thread state (paused or normal) */
391     int                extra1;  /*!< Reserved to the runtime */
392     void*              extra2;  /*!< Reserved to the runtime */
393     struct ___itt_thread_info* next;
394 } __itt_thread_info;
395 
396 #include "ittnotify_types.h" /* For __itt_group_id definition */
397 
398 typedef struct ___itt_api_info_20101001
399 {
400     const char*    name;
401     void**         func_ptr;
402     void*          init_func;
403     __itt_group_id group;
404 }  __itt_api_info_20101001;
405 
406 typedef struct ___itt_api_info
407 {
408     const char*    name;
409     void**         func_ptr;
410     void*          init_func;
411     void*          null_func;
412     __itt_group_id group;
413 }  __itt_api_info;
414 
415 typedef struct __itt_counter_info
416 {
417     const char* nameA;  /*!< Copy of original name in ASCII. */
418 #if defined(UNICODE) || defined(_UNICODE)
419     const wchar_t* nameW; /*!< Copy of original name in UNICODE. */
420 #else  /* UNICODE || _UNICODE */
421     void* nameW;
422 #endif /* UNICODE || _UNICODE */
423     const char* domainA;  /*!< Copy of original name in ASCII. */
424 #if defined(UNICODE) || defined(_UNICODE)
425     const wchar_t* domainW; /*!< Copy of original name in UNICODE. */
426 #else  /* UNICODE || _UNICODE */
427     void* domainW;
428 #endif /* UNICODE || _UNICODE */
429     int type;
430     long index;
431     int   extra1; /*!< Reserved to the runtime */
432     void* extra2; /*!< Reserved to the runtime */
433     struct __itt_counter_info* next;
434 }  __itt_counter_info_t;
435 
436 struct ___itt_domain;
437 struct ___itt_string_handle;
438 
439 typedef struct ___itt_global
440 {
441     unsigned char          magic[8];
442     unsigned long          version_major;
443     unsigned long          version_minor;
444     unsigned long          version_build;
445     volatile long          api_initialized;
446     volatile long          mutex_initialized;
447     volatile long          atomic_counter;
448     mutex_t                mutex;
449     lib_t                  lib;
450     void*                  error_handler;
451     const char**           dll_path_ptr;
452     __itt_api_info*        api_list_ptr;
453     struct ___itt_global*  next;
454     /* Joinable structures below */
455     __itt_thread_info*     thread_list;
456     struct ___itt_domain*  domain_list;
457     struct ___itt_string_handle* string_list;
458     __itt_collection_state state;
459     __itt_counter_info_t* counter_list;
460     unsigned int           ipt_collect_events;
461 } __itt_global;
462 
463 #pragma pack(pop)
464 
465 #define NEW_THREAD_INFO_W(gptr,h,h_tail,t,s,n) { \
466     h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
467     if (h != NULL) { \
468         h->tid    = t; \
469         h->nameA  = NULL; \
470         h->nameW  = n ? _wcsdup(n) : NULL; \
471         h->state  = s; \
472         h->extra1 = 0;    /* reserved */ \
473         h->extra2 = NULL; /* reserved */ \
474         h->next   = NULL; \
475         if (h_tail == NULL) \
476             (gptr)->thread_list = h; \
477         else \
478             h_tail->next = h; \
479     } \
480 }
481 
482 #define NEW_THREAD_INFO_A(gptr,h,h_tail,t,s,n) { \
483     h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
484     if (h != NULL) { \
485         h->tid    = t; \
486         h->nameA  = n ? __itt_fstrdup(n) : NULL; \
487         h->nameW  = NULL; \
488         h->state  = s; \
489         h->extra1 = 0;    /* reserved */ \
490         h->extra2 = NULL; /* reserved */ \
491         h->next   = NULL; \
492         if (h_tail == NULL) \
493             (gptr)->thread_list = h; \
494         else \
495             h_tail->next = h; \
496     } \
497 }
498 
499 #define NEW_DOMAIN_W(gptr,h,h_tail,name) { \
500     h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
501     if (h != NULL) { \
502         h->flags  = 1;    /* domain is enabled by default */ \
503         h->nameA  = NULL; \
504         h->nameW  = name ? _wcsdup(name) : NULL; \
505         h->extra1 = 0;    /* reserved */ \
506         h->extra2 = NULL; /* reserved */ \
507         h->next   = NULL; \
508         if (h_tail == NULL) \
509             (gptr)->domain_list = h; \
510         else \
511             h_tail->next = h; \
512     } \
513 }
514 
515 #define NEW_DOMAIN_A(gptr,h,h_tail,name) { \
516     h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
517     if (h != NULL) { \
518         h->flags  = 1;    /* domain is enabled by default */ \
519         h->nameA  = name ? __itt_fstrdup(name) : NULL; \
520         h->nameW  = NULL; \
521         h->extra1 = 0;    /* reserved */ \
522         h->extra2 = NULL; /* reserved */ \
523         h->next   = NULL; \
524         if (h_tail == NULL) \
525             (gptr)->domain_list = h; \
526         else \
527             h_tail->next = h; \
528     } \
529 }
530 
531 #define NEW_STRING_HANDLE_W(gptr,h,h_tail,name) { \
532     h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
533     if (h != NULL) { \
534         h->strA   = NULL; \
535         h->strW   = name ? _wcsdup(name) : NULL; \
536         h->extra1 = 0;    /* reserved */ \
537         h->extra2 = NULL; /* reserved */ \
538         h->next   = NULL; \
539         if (h_tail == NULL) \
540             (gptr)->string_list = h; \
541         else \
542             h_tail->next = h; \
543     } \
544 }
545 
546 #define NEW_STRING_HANDLE_A(gptr,h,h_tail,name) { \
547     h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
548     if (h != NULL) { \
549         h->strA   = name ? __itt_fstrdup(name) : NULL; \
550         h->strW   = NULL; \
551         h->extra1 = 0;    /* reserved */ \
552         h->extra2 = NULL; /* reserved */ \
553         h->next   = NULL; \
554         if (h_tail == NULL) \
555             (gptr)->string_list = h; \
556         else \
557             h_tail->next = h; \
558     } \
559 }
560 
561 #define NEW_COUNTER_W(gptr,h,h_tail,name,domain,type) { \
562     h = (__itt_counter_info_t*)malloc(sizeof(__itt_counter_info_t)); \
563     if (h != NULL) { \
564         h->nameA   = NULL; \
565         h->nameW   = name ? _wcsdup(name) : NULL; \
566         h->domainA   = NULL; \
567         h->domainW   = name ? _wcsdup(domain) : NULL; \
568         h->type = type; \
569         h->index = 0; \
570         h->next   = NULL; \
571         if (h_tail == NULL) \
572             (gptr)->counter_list = h; \
573         else \
574             h_tail->next = h; \
575     } \
576 }
577 
578 #define NEW_COUNTER_A(gptr,h,h_tail,name,domain,type) { \
579     h = (__itt_counter_info_t*)malloc(sizeof(__itt_counter_info_t)); \
580     if (h != NULL) { \
581         h->nameA   = name ? __itt_fstrdup(name) : NULL; \
582         h->nameW   = NULL; \
583         h->domainA   = domain ? __itt_fstrdup(domain) : NULL; \
584         h->domainW   = NULL; \
585         h->type = type; \
586         h->index = 0; \
587         h->next   = NULL; \
588         if (h_tail == NULL) \
589             (gptr)->counter_list = h; \
590         else \
591             h_tail->next = h; \
592     } \
593 }
594 
595 #endif /* _ITTNOTIFY_CONFIG_H_ */
596