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 _TBB_ITT_NOTIFY
18 #define _TBB_ITT_NOTIFY
19 
20 #include "oneapi/tbb/detail/_config.h"
21 
22 #if __TBB_USE_ITT_NOTIFY
23 
24 #if _WIN32||_WIN64
25     #ifndef UNICODE
26         #define UNICODE
27     #endif
28 #endif /* WIN */
29 
30 #ifndef INTEL_ITTNOTIFY_API_PRIVATE
31 #define INTEL_ITTNOTIFY_API_PRIVATE
32 #endif
33 
34 #include "tools_api/ittnotify.h"
35 #include "tools_api/legacy/ittnotify.h"
36 extern "C" void __itt_fini_ittlib(void);
37 
38 #if _WIN32||_WIN64
39     #undef _T
40 #endif /* WIN */
41 
42 #endif /* __TBB_USE_ITT_NOTIFY */
43 
44 #if !ITT_CALLER_NULL
45 #define ITT_CALLER_NULL ((__itt_caller)0)
46 #endif
47 
48 namespace tbb {
49 namespace detail {
50 namespace r1 {
51 
52 //! Unicode support
53 #if (_WIN32||_WIN64)
54     //! Unicode character type. Always wchar_t on Windows.
55     /** We do not use typedefs from Windows TCHAR family to keep consistence of TBB coding style. **/
56     using tchar = wchar_t;
57     //! Standard Windows macro to markup the string literals.
58     #define _T(string_literal) L ## string_literal
59 #else /* !WIN */
60     using tchar = char;
61     //! Standard Windows style macro to markup the string literals.
62     #define _T(string_literal) string_literal
63 #endif /* !WIN */
64 
65 //! Display names of internal synchronization types
66 extern const tchar
67     *SyncType_Scheduler;
68 //! Display names of internal synchronization components/scenarios
69 extern const tchar
70     *SyncObj_ContextsList
71     ;
72 
73 #if __TBB_USE_ITT_NOTIFY
74 // const_cast<void*>() is necessary to cast off volatility
75 #define ITT_NOTIFY(name,obj)            __itt_##name(const_cast<void*>(static_cast<volatile void*>(obj)))
76 #define ITT_THREAD_SET_NAME(name)       __itt_thread_set_name(name)
77 #define ITT_FINI_ITTLIB()               __itt_fini_ittlib()
78 #define ITT_SYNC_CREATE(obj, type, name) __itt_sync_create((void*)(obj), type, name, 2)
79 #define ITT_STACK_CREATE(obj)           obj = __itt_stack_caller_create()
80 #define ITT_STACK_DESTROY(obj)          (obj!=nullptr) ? __itt_stack_caller_destroy(static_cast<__itt_caller>(obj)) : ((void)0)
81 #define ITT_CALLEE_ENTER(cond, t, obj)  if(cond) {\
82                                             __itt_stack_callee_enter(static_cast<__itt_caller>(obj));\
83                                             __itt_sync_acquired(t);\
84                                         }
85 #define ITT_CALLEE_LEAVE(cond, obj)     (cond) ? __itt_stack_callee_leave(static_cast<__itt_caller>(obj)) : ((void)0)
86 
87 #define ITT_TASK_GROUP(obj,name,parent)     r1::itt_make_task_group(d1::ITT_DOMAIN_MAIN,(void*)(obj),ALGORITHM,(void*)(parent),(parent!=nullptr) ? ALGORITHM : FLOW_NULL,name)
88 #define ITT_TASK_BEGIN(obj,name,id)         r1::itt_task_begin(d1::ITT_DOMAIN_MAIN,(void*)(id),ALGORITHM,(void*)(obj),ALGORITHM,name)
89 #define ITT_TASK_END                        r1::itt_task_end(d1::ITT_DOMAIN_MAIN)
90 
91 
92 #else /* !__TBB_USE_ITT_NOTIFY */
93 
94 #define ITT_NOTIFY(name,obj)            ((void)0)
95 #define ITT_THREAD_SET_NAME(name)       ((void)0)
96 #define ITT_FINI_ITTLIB()               ((void)0)
97 #define ITT_SYNC_CREATE(obj, type, name) ((void)0)
98 #define ITT_STACK_CREATE(obj)           ((void)0)
99 #define ITT_STACK_DESTROY(obj)          ((void)0)
100 #define ITT_CALLEE_ENTER(cond, t, obj)  ((void)0)
101 #define ITT_CALLEE_LEAVE(cond, obj)     ((void)0)
102 #define ITT_TASK_GROUP(type,name,parent)    ((void)0)
103 #define ITT_TASK_BEGIN(type,name,id)        ((void)0)
104 #define ITT_TASK_END                        ((void)0)
105 
106 #endif /* !__TBB_USE_ITT_NOTIFY */
107 
108 int __TBB_load_ittnotify();
109 
110 } // namespace r1
111 } // namespace detail
112 } // namespace tbb
113 
114 #endif /* _TBB_ITT_NOTIFY */
115