1 /* <copyright>
2   This file is provided under a dual BSD/GPLv2 license.  When using or
3   redistributing this file, you may do so under either license.
4 
5   GPL LICENSE SUMMARY
6 
7   Copyright (c) 2005-2014 Intel Corporation. All rights reserved.
8 
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of version 2 of the GNU General Public License as
11   published by the Free Software Foundation.
12 
13   This program is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16   General Public License for more details.
17 
18   You should have received a copy of the GNU General Public License
19   along with this program; if not, write to the Free Software
20   Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21   The full GNU General Public License is included in this distribution
22   in the file called LICENSE.GPL.
23 
24   Contact Information:
25   http://software.intel.com/en-us/articles/intel-vtune-amplifier-xe/
26 
27   BSD LICENSE
28 
29   Copyright (c) 2005-2014 Intel Corporation. All rights reserved.
30   All rights reserved.
31 
32   Redistribution and use in source and binary forms, with or without
33   modification, are permitted provided that the following conditions
34   are met:
35 
36     * Redistributions of source code must retain the above copyright
37       notice, this list of conditions and the following disclaimer.
38     * Redistributions in binary form must reproduce the above copyright
39       notice, this list of conditions and the following disclaimer in
40       the documentation and/or other materials provided with the
41       distribution.
42     * Neither the name of Intel Corporation nor the names of its
43       contributors may be used to endorse or promote products derived
44       from this software without specific prior written permission.
45 
46   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
47   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
48   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
49   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
50   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
51   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
52   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
56   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 </copyright> */
58 #ifndef _ITTNOTIFY_CONFIG_H_
59 #define _ITTNOTIFY_CONFIG_H_
60 
61 /** @cond exclude_from_documentation */
62 #ifndef ITT_OS_WIN
63 #  define ITT_OS_WIN   1
64 #endif /* ITT_OS_WIN */
65 
66 #ifndef ITT_OS_LINUX
67 #  define ITT_OS_LINUX 2
68 #endif /* ITT_OS_LINUX */
69 
70 #ifndef ITT_OS_MAC
71 #  define ITT_OS_MAC   3
72 #endif /* ITT_OS_MAC */
73 
74 #ifndef ITT_OS_FREEBSD
75 #  define ITT_OS_FREEBSD   4
76 #endif /* ITT_OS_FREEBSD */
77 
78 #ifndef ITT_OS
79 #  if defined WIN32 || defined _WIN32
80 #    define ITT_OS ITT_OS_WIN
81 #  elif defined( __APPLE__ ) && defined( __MACH__ )
82 #    define ITT_OS ITT_OS_MAC
83 #  elif defined( __FreeBSD__ )
84 #    define ITT_OS ITT_OS_FREEBSD
85 #  else
86 #    define ITT_OS ITT_OS_LINUX
87 #  endif
88 #endif /* ITT_OS */
89 
90 #ifndef ITT_PLATFORM_WIN
91 #  define ITT_PLATFORM_WIN 1
92 #endif /* ITT_PLATFORM_WIN */
93 
94 #ifndef ITT_PLATFORM_POSIX
95 #  define ITT_PLATFORM_POSIX 2
96 #endif /* ITT_PLATFORM_POSIX */
97 
98 #ifndef ITT_PLATFORM_MAC
99 #  define ITT_PLATFORM_MAC 3
100 #endif /* ITT_PLATFORM_MAC */
101 
102 #ifndef ITT_PLATFORM_FREEBSD
103 #  define ITT_PLATFORM_FREEBSD 4
104 #endif /* ITT_PLATFORM_FREEBSD */
105 
106 #ifndef ITT_PLATFORM
107 #  if ITT_OS==ITT_OS_WIN
108 #    define ITT_PLATFORM ITT_PLATFORM_WIN
109 #  elif ITT_OS==ITT_OS_MAC
110 #    define ITT_PLATFORM ITT_PLATFORM_MAC
111 #  elif ITT_OS==ITT_OS_FREEBSD
112 #    define ITT_PLATFORM ITT_PLATFORM_FREEBSD
113 #  else
114 #    define ITT_PLATFORM ITT_PLATFORM_POSIX
115 #  endif
116 #endif /* ITT_PLATFORM */
117 
118 #if defined(_UNICODE) && !defined(UNICODE)
119 #define UNICODE
120 #endif
121 
122 #include <stddef.h>
123 #if ITT_PLATFORM==ITT_PLATFORM_WIN
124 #include <tchar.h>
125 #else  /* ITT_PLATFORM==ITT_PLATFORM_WIN */
126 #include <stdint.h>
127 #if defined(UNICODE) || defined(_UNICODE)
128 #include <wchar.h>
129 #endif /* UNICODE || _UNICODE */
130 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
131 
132 #ifndef ITTAPI_CDECL
133 #  if ITT_PLATFORM==ITT_PLATFORM_WIN
134 #    define ITTAPI_CDECL __cdecl
135 #  else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
136 #    if defined _M_IX86 || defined __i386__
137 #      define ITTAPI_CDECL __attribute__ ((cdecl))
138 #    else  /* _M_IX86 || __i386__ */
139 #      define ITTAPI_CDECL /* actual only on x86 platform */
140 #    endif /* _M_IX86 || __i386__ */
141 #  endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
142 #endif /* ITTAPI_CDECL */
143 
144 #ifndef STDCALL
145 #  if ITT_PLATFORM==ITT_PLATFORM_WIN
146 #    define STDCALL __stdcall
147 #  else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
148 #    if defined _M_IX86 || defined __i386__
149 #      define STDCALL __attribute__ ((stdcall))
150 #    else  /* _M_IX86 || __i386__ */
151 #      define STDCALL /* supported only on x86 platform */
152 #    endif /* _M_IX86 || __i386__ */
153 #  endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
154 #endif /* STDCALL */
155 
156 #define ITTAPI    ITTAPI_CDECL
157 #define LIBITTAPI ITTAPI_CDECL
158 
159 /* TODO: Temporary for compatibility! */
160 #define ITTAPI_CALL    ITTAPI_CDECL
161 #define LIBITTAPI_CALL ITTAPI_CDECL
162 
163 #if ITT_PLATFORM==ITT_PLATFORM_WIN
164 /* use __forceinline (VC++ specific) */
165 #define ITT_INLINE           __forceinline
166 #define ITT_INLINE_ATTRIBUTE /* nothing */
167 #else  /* ITT_PLATFORM==ITT_PLATFORM_WIN */
168 /*
169  * Generally, functions are not inlined unless optimization is specified.
170  * For functions declared inline, this attribute inlines the function even
171  * if no optimization level was specified.
172  */
173 #ifdef __STRICT_ANSI__
174 #define ITT_INLINE           static
175 #define ITT_INLINE_ATTRIBUTE __attribute__((unused))
176 #else  /* __STRICT_ANSI__ */
177 #define ITT_INLINE           static inline
178 #define ITT_INLINE_ATTRIBUTE __attribute__((always_inline, unused))
179 #endif /* __STRICT_ANSI__ */
180 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
181 /** @endcond */
182 
183 #ifndef ITT_ARCH_IA32
184 #  define ITT_ARCH_IA32  1
185 #endif /* ITT_ARCH_IA32 */
186 
187 #ifndef ITT_ARCH_IA32E
188 #  define ITT_ARCH_IA32E 2
189 #endif /* ITT_ARCH_IA32E */
190 
191 #ifndef ITT_ARCH_ARM
192 #  define ITT_ARCH_ARM  4
193 #endif /* ITT_ARCH_ARM */
194 
195 #ifndef ITT_ARCH_PPC64
196 #  define ITT_ARCH_PPC64  5
197 #endif /* ITT_ARCH_PPC64 */
198 
199 #ifndef ITT_ARCH
200 #  if defined _M_IX86 || defined __i386__
201 #    define ITT_ARCH ITT_ARCH_IA32
202 #  elif defined _M_X64 || defined _M_AMD64 || defined __x86_64__
203 #    define ITT_ARCH ITT_ARCH_IA32E
204 #  elif defined _M_IA64 || defined __ia64__
205 #    define ITT_ARCH ITT_ARCH_IA64
206 #  elif defined _M_ARM || defined __arm__
207 #    define ITT_ARCH ITT_ARCH_ARM
208 #  elif defined __powerpc64__
209 #    define ITT_ARCH ITT_ARCH_PPC64
210 #  endif
211 #endif
212 
213 #ifdef __cplusplus
214 #  define ITT_EXTERN_C extern "C"
215 #  define ITT_EXTERN_C_BEGIN extern "C" {
216 #  define ITT_EXTERN_C_END }
217 #else
218 #  define ITT_EXTERN_C /* nothing */
219 #  define ITT_EXTERN_C_BEGIN /* nothing */
220 #  define ITT_EXTERN_C_END /* nothing */
221 #endif /* __cplusplus */
222 
223 #define ITT_TO_STR_AUX(x) #x
224 #define ITT_TO_STR(x)     ITT_TO_STR_AUX(x)
225 
226 #define __ITT_BUILD_ASSERT(expr, suffix) do { \
227     static char __itt_build_check_##suffix[(expr) ? 1 : -1]; \
228     __itt_build_check_##suffix[0] = 0; \
229 } while(0)
230 #define _ITT_BUILD_ASSERT(expr, suffix)  __ITT_BUILD_ASSERT((expr), suffix)
231 #define ITT_BUILD_ASSERT(expr)           _ITT_BUILD_ASSERT((expr), __LINE__)
232 
233 #define ITT_MAGIC { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 }
234 
235 /* Replace with snapshot date YYYYMMDD for promotion build. */
236 #define API_VERSION_BUILD    20151119
237 
238 #ifndef API_VERSION_NUM
239 #define API_VERSION_NUM 0.0.0
240 #endif /* API_VERSION_NUM */
241 
242 #define API_VERSION "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) \
243                                 " (" ITT_TO_STR(API_VERSION_BUILD) ")"
244 
245 /* OS communication functions */
246 #if ITT_PLATFORM==ITT_PLATFORM_WIN
247 #include <windows.h>
248 typedef HMODULE           lib_t;
249 typedef DWORD             TIDT;
250 typedef CRITICAL_SECTION  mutex_t;
251 #define MUTEX_INITIALIZER { 0 }
252 #define strong_alias(name, aliasname) /* empty for Windows */
253 #else  /* ITT_PLATFORM==ITT_PLATFORM_WIN */
254 #include <dlfcn.h>
255 #if defined(UNICODE) || defined(_UNICODE)
256 #include <wchar.h>
257 #endif /* UNICODE */
258 #ifndef _GNU_SOURCE
259 #define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */
260 #endif /* _GNU_SOURCE */
261 #ifndef __USE_UNIX98
262 #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 */
263 #endif /*__USE_UNIX98*/
264 #include <pthread.h>
265 typedef void*             lib_t;
266 typedef pthread_t         TIDT;
267 typedef pthread_mutex_t   mutex_t;
268 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
269 #define _strong_alias(name, aliasname) \
270             extern __typeof (name) aliasname __attribute__ ((alias (#name)));
271 #define strong_alias(name, aliasname) _strong_alias(name, aliasname)
272 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
273 
274 #if ITT_PLATFORM==ITT_PLATFORM_WIN
275 #define __itt_get_proc(lib, name) GetProcAddress(lib, name)
276 #define __itt_mutex_init(mutex)   InitializeCriticalSection(mutex)
277 #define __itt_mutex_lock(mutex)   EnterCriticalSection(mutex)
278 #define __itt_mutex_unlock(mutex) LeaveCriticalSection(mutex)
279 #define __itt_load_lib(name)      LoadLibraryA(name)
280 #define __itt_unload_lib(handle)  FreeLibrary(handle)
281 #define __itt_system_error()      (int)GetLastError()
282 #define __itt_fstrcmp(s1, s2)     lstrcmpA(s1, s2)
283 #define __itt_fstrnlen(s, l)      strnlen_s(s, l)
284 #define __itt_fstrcpyn(s1, b, s2, l) strncpy_s(s1, b, s2, l)
285 #define __itt_fstrdup(s)          _strdup(s)
286 #define __itt_thread_id()         GetCurrentThreadId()
287 #define __itt_thread_yield()      SwitchToThread()
288 #ifndef ITT_SIMPLE_INIT
289 ITT_INLINE long
290 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
__itt_interlocked_increment(volatile long * ptr)291 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
292 {
293     return InterlockedIncrement(ptr);
294 }
295 #endif /* ITT_SIMPLE_INIT */
296 #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
297 #define __itt_get_proc(lib, name) dlsym(lib, name)
298 #define __itt_mutex_init(mutex)   {\
299     pthread_mutexattr_t mutex_attr;                                         \
300     int error_code = pthread_mutexattr_init(&mutex_attr);                   \
301     if (error_code)                                                         \
302         __itt_report_error(__itt_error_system, "pthread_mutexattr_init",    \
303                            error_code);                                     \
304     error_code = pthread_mutexattr_settype(&mutex_attr,                     \
305                                            PTHREAD_MUTEX_RECURSIVE);        \
306     if (error_code)                                                         \
307         __itt_report_error(__itt_error_system, "pthread_mutexattr_settype", \
308                            error_code);                                     \
309     error_code = pthread_mutex_init(mutex, &mutex_attr);                    \
310     if (error_code)                                                         \
311         __itt_report_error(__itt_error_system, "pthread_mutex_init",        \
312                            error_code);                                     \
313     error_code = pthread_mutexattr_destroy(&mutex_attr);                    \
314     if (error_code)                                                         \
315         __itt_report_error(__itt_error_system, "pthread_mutexattr_destroy", \
316                            error_code);                                     \
317 }
318 #define __itt_mutex_lock(mutex)   pthread_mutex_lock(mutex)
319 #define __itt_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
320 #define __itt_load_lib(name)      dlopen(name, RTLD_LAZY)
321 #define __itt_unload_lib(handle)  dlclose(handle)
322 #define __itt_system_error()      errno
323 #define __itt_fstrcmp(s1, s2)     strcmp(s1, s2)
324 
325 /* makes customer code define safe APIs for SDL_STRNLEN_S and SDL_STRNCPY_S */
326 #ifdef SDL_STRNLEN_S
327 #define __itt_fstrnlen(s, l)      SDL_STRNLEN_S(s, l)
328 #else
329 #define __itt_fstrnlen(s, l)      strlen(s)
330 #endif /* SDL_STRNLEN_S */
331 #ifdef SDL_STRNCPY_S
332 #define __itt_fstrcpyn(s1, b, s2, l) SDL_STRNCPY_S(s1, b, s2, l)
333 #else
334 #define __itt_fstrcpyn(s1, b, s2, l) strncpy(s1, s2, l)
335 #endif /* SDL_STRNCPY_S */
336 
337 #define __itt_fstrdup(s)          strdup(s)
338 #define __itt_thread_id()         pthread_self()
339 #define __itt_thread_yield()      sched_yield()
340 #if ITT_ARCH==ITT_ARCH_IA64
341 #ifdef __INTEL_COMPILER
342 #define __TBB_machine_fetchadd4(addr, val) __fetchadd4_acq((void *)addr, val)
343 #else  /* __INTEL_COMPILER */
344 /* TODO: Add Support for not Intel compilers for IA-64 architecture */
345 #endif /* __INTEL_COMPILER */
346 #elif ITT_ARCH==ITT_ARCH_IA32 || ITT_ARCH==ITT_ARCH_IA32E /* ITT_ARCH!=ITT_ARCH_IA64 */
347 ITT_INLINE long
348 __TBB_machine_fetchadd4(volatile void* ptr, long addend) ITT_INLINE_ATTRIBUTE;
__TBB_machine_fetchadd4(volatile void * ptr,long addend)349 ITT_INLINE long __TBB_machine_fetchadd4(volatile void* ptr, long addend)
350 {
351     long result;
352     __asm__ __volatile__("lock\nxadd %0,%1"
353                           : "=r"(result),"=m"(*(int*)ptr)
354                           : "0"(addend), "m"(*(int*)ptr)
355                           : "memory");
356     return result;
357 }
358 #elif ITT_ARCH==ITT_ARCH_ARM || ITT_ARCH==ITT_ARCH_PPC64
359 #define __TBB_machine_fetchadd4(addr, val) __sync_fetch_and_add(addr, val)
360 #endif /* ITT_ARCH==ITT_ARCH_IA64 */
361 #ifndef ITT_SIMPLE_INIT
362 ITT_INLINE long
363 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
__itt_interlocked_increment(volatile long * ptr)364 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
365 {
366     return __TBB_machine_fetchadd4(ptr, 1) + 1L;
367 }
368 #endif /* ITT_SIMPLE_INIT */
369 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
370 
371 typedef enum {
372     __itt_collection_normal = 0,
373     __itt_collection_paused = 1
374 } __itt_collection_state;
375 
376 typedef enum {
377     __itt_thread_normal  = 0,
378     __itt_thread_ignored = 1
379 } __itt_thread_state;
380 
381 #pragma pack(push, 8)
382 
383 typedef struct ___itt_thread_info
384 {
385     const char* nameA; /*!< Copy of original name in ASCII. */
386 #if defined(UNICODE) || defined(_UNICODE)
387     const wchar_t* nameW; /*!< Copy of original name in UNICODE. */
388 #else  /* UNICODE || _UNICODE */
389     void* nameW;
390 #endif /* UNICODE || _UNICODE */
391     TIDT               tid;
392     __itt_thread_state state;   /*!< Thread state (paused or normal) */
393     int                extra1;  /*!< Reserved to the runtime */
394     void*              extra2;  /*!< Reserved to the runtime */
395     struct ___itt_thread_info* next;
396 } __itt_thread_info;
397 
398 #include "ittnotify_types.h" /* For __itt_group_id definition */
399 
400 typedef struct ___itt_api_info_20101001
401 {
402     const char*    name;
403     void**         func_ptr;
404     void*          init_func;
405     __itt_group_id group;
406 }  __itt_api_info_20101001;
407 
408 typedef struct ___itt_api_info
409 {
410     const char*    name;
411     void**         func_ptr;
412     void*          init_func;
413     void*          null_func;
414     __itt_group_id group;
415 }  __itt_api_info;
416 
417 typedef struct __itt_counter_info
418 {
419     const char* nameA;  /*!< Copy of original name in ASCII. */
420 #if defined(UNICODE) || defined(_UNICODE)
421     const wchar_t* nameW; /*!< Copy of original name in UNICODE. */
422 #else  /* UNICODE || _UNICODE */
423     void* nameW;
424 #endif /* UNICODE || _UNICODE */
425     const char* domainA;  /*!< Copy of original name in ASCII. */
426 #if defined(UNICODE) || defined(_UNICODE)
427     const wchar_t* domainW; /*!< Copy of original name in UNICODE. */
428 #else  /* UNICODE || _UNICODE */
429     void* domainW;
430 #endif /* UNICODE || _UNICODE */
431     int type;
432     long index;
433     int   extra1; /*!< Reserved to the runtime */
434     void* extra2; /*!< Reserved to the runtime */
435     struct __itt_counter_info* next;
436 }  __itt_counter_info_t;
437 
438 struct ___itt_domain;
439 struct ___itt_string_handle;
440 
441 typedef struct ___itt_global
442 {
443     unsigned char          magic[8];
444     unsigned long          version_major;
445     unsigned long          version_minor;
446     unsigned long          version_build;
447     volatile long          api_initialized;
448     volatile long          mutex_initialized;
449     volatile long          atomic_counter;
450     mutex_t                mutex;
451     lib_t                  lib;
452     void*                  error_handler;
453     const char**           dll_path_ptr;
454     __itt_api_info*        api_list_ptr;
455     struct ___itt_global*  next;
456     /* Joinable structures below */
457     __itt_thread_info*     thread_list;
458     struct ___itt_domain*  domain_list;
459     struct ___itt_string_handle* string_list;
460     __itt_collection_state state;
461     __itt_counter_info_t* counter_list;
462 } __itt_global;
463 
464 #pragma pack(pop)
465 
466 #define NEW_THREAD_INFO_W(gptr,h,h_tail,t,s,n) { \
467     h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
468     if (h != NULL) { \
469         h->tid    = t; \
470         h->nameA  = NULL; \
471         h->nameW  = n ? _wcsdup(n) : NULL; \
472         h->state  = s; \
473         h->extra1 = 0;    /* reserved */ \
474         h->extra2 = NULL; /* reserved */ \
475         h->next   = NULL; \
476         if (h_tail == NULL) \
477             (gptr)->thread_list = h; \
478         else \
479             h_tail->next = h; \
480     } \
481 }
482 
483 #define NEW_THREAD_INFO_A(gptr,h,h_tail,t,s,n) { \
484     h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
485     if (h != NULL) { \
486         h->tid    = t; \
487         h->nameA  = n ? __itt_fstrdup(n) : NULL; \
488         h->nameW  = NULL; \
489         h->state  = s; \
490         h->extra1 = 0;    /* reserved */ \
491         h->extra2 = NULL; /* reserved */ \
492         h->next   = NULL; \
493         if (h_tail == NULL) \
494             (gptr)->thread_list = h; \
495         else \
496             h_tail->next = h; \
497     } \
498 }
499 
500 #define NEW_DOMAIN_W(gptr,h,h_tail,name) { \
501     h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
502     if (h != NULL) { \
503         h->flags  = 1;    /* domain is enabled by default */ \
504         h->nameA  = NULL; \
505         h->nameW  = name ? _wcsdup(name) : NULL; \
506         h->extra1 = 0;    /* reserved */ \
507         h->extra2 = NULL; /* reserved */ \
508         h->next   = NULL; \
509         if (h_tail == NULL) \
510             (gptr)->domain_list = h; \
511         else \
512             h_tail->next = h; \
513     } \
514 }
515 
516 #define NEW_DOMAIN_A(gptr,h,h_tail,name) { \
517     h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
518     if (h != NULL) { \
519         h->flags  = 1;    /* domain is enabled by default */ \
520         h->nameA  = name ? __itt_fstrdup(name) : NULL; \
521         h->nameW  = NULL; \
522         h->extra1 = 0;    /* reserved */ \
523         h->extra2 = NULL; /* reserved */ \
524         h->next   = NULL; \
525         if (h_tail == NULL) \
526             (gptr)->domain_list = h; \
527         else \
528             h_tail->next = h; \
529     } \
530 }
531 
532 #define NEW_STRING_HANDLE_W(gptr,h,h_tail,name) { \
533     h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
534     if (h != NULL) { \
535         h->strA   = NULL; \
536         h->strW   = name ? _wcsdup(name) : NULL; \
537         h->extra1 = 0;    /* reserved */ \
538         h->extra2 = NULL; /* reserved */ \
539         h->next   = NULL; \
540         if (h_tail == NULL) \
541             (gptr)->string_list = h; \
542         else \
543             h_tail->next = h; \
544     } \
545 }
546 
547 #define NEW_STRING_HANDLE_A(gptr,h,h_tail,name) { \
548     h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
549     if (h != NULL) { \
550         h->strA   = name ? __itt_fstrdup(name) : NULL; \
551         h->strW   = NULL; \
552         h->extra1 = 0;    /* reserved */ \
553         h->extra2 = NULL; /* reserved */ \
554         h->next   = NULL; \
555         if (h_tail == NULL) \
556             (gptr)->string_list = h; \
557         else \
558             h_tail->next = h; \
559     } \
560 }
561 
562 #define NEW_COUNTER_W(gptr,h,h_tail,name,domain,type) { \
563     h = (__itt_counter_info_t*)malloc(sizeof(__itt_counter_info_t)); \
564     if (h != NULL) { \
565         h->nameA   = NULL; \
566         h->nameW   = name ? _wcsdup(name) : NULL; \
567         h->domainA   = NULL; \
568         h->domainW   = name ? _wcsdup(domain) : NULL; \
569         h->type = type; \
570         h->index = 0; \
571         h->next   = NULL; \
572         if (h_tail == NULL) \
573             (gptr)->counter_list = h; \
574         else \
575             h_tail->next = h; \
576     } \
577 }
578 
579 #define NEW_COUNTER_A(gptr,h,h_tail,name,domain,type) { \
580     h = (__itt_counter_info_t*)malloc(sizeof(__itt_counter_info_t)); \
581     if (h != NULL) { \
582         h->nameA   = name ? __itt_fstrdup(name) : NULL; \
583         h->nameW   = NULL; \
584         h->domainA   = domain ? __itt_fstrdup(domain) : NULL; \
585         h->domainW   = NULL; \
586         h->type = type; \
587         h->index = 0; \
588         h->next   = NULL; \
589         if (h_tail == NULL) \
590             (gptr)->counter_list = h; \
591         else \
592             h_tail->next = h; \
593     } \
594 }
595 
596 #endif /* _ITTNOTIFY_CONFIG_H_ */
597