00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __TBB_profiling_H
00030 #define __TBB_profiling_H
00031
00032
00033 #if (_WIN32||_WIN64||__linux__) && !__MINGW32__ && TBB_USE_THREADING_TOOLS
00034
00035 #if _WIN32||_WIN64
00036 #include <stdlib.h>
00037 #endif
00038 #include "tbb_stddef.h"
00039
00040 namespace tbb {
00041 namespace internal {
00042 #if _WIN32||_WIN64
00043 void __TBB_EXPORTED_FUNC itt_set_sync_name_v3( void *obj, const wchar_t* name );
00044 inline size_t multibyte_to_widechar( wchar_t* wcs, const char* mbs, size_t bufsize) {
00045 #if _MSC_VER>=1400
00046 size_t len;
00047 mbstowcs_s( &len, wcs, bufsize, mbs, _TRUNCATE );
00048 return len;
00049 #else
00050 size_t len = mbstowcs( wcs, mbs, bufsize );
00051 if(wcs && len!=size_t(-1) )
00052 wcs[len<bufsize-1? len: bufsize-1] = wchar_t('\0');
00053 return len+1;
00054 #endif
00055 }
00056 #else
00057 void __TBB_EXPORTED_FUNC itt_set_sync_name_v3( void *obj, const char* name );
00058 #endif
00059 }
00060 }
00061
00063
00065 #if _WIN32||_WIN64
00066 #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type) \
00067 namespace profiling { \
00068 inline void set_name( sync_object_type& obj, const wchar_t* name ) { \
00069 tbb::internal::itt_set_sync_name_v3( &obj, name ); \
00070 } \
00071 inline void set_name( sync_object_type& obj, const char* name ) { \
00072 size_t len = tbb::internal::multibyte_to_widechar(NULL, name, 0); \
00073 wchar_t *wname = new wchar_t[len]; \
00074 tbb::internal::multibyte_to_widechar(wname, name, len); \
00075 set_name( obj, wname ); \
00076 delete[] wname; \
00077 } \
00078 }
00079 #else
00080 #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type) \
00081 namespace profiling { \
00082 inline void set_name( sync_object_type& obj, const char* name ) { \
00083 tbb::internal::itt_set_sync_name_v3( &obj, name ); \
00084 } \
00085 }
00086 #endif
00087
00088 #else
00089
00090 #if _WIN32||_WIN64
00091 #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type) \
00092 namespace profiling { \
00093 inline void set_name( sync_object_type&, const wchar_t* ) {} \
00094 inline void set_name( sync_object_type&, const char* ) {} \
00095 }
00096 #else
00097 #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type) \
00098 namespace profiling { \
00099 inline void set_name( sync_object_type&, const char* ) {} \
00100 }
00101 #endif
00102
00103 #endif
00104
00105 #include "atomic.h"
00106
00107 namespace tbb {
00108 namespace internal {
00109
00110 enum notify_type {prepare=0, cancel, acquired, releasing};
00111 const uintptr_t NUM_NOTIFY_TYPES = 4;
00112
00113 void __TBB_EXPORTED_FUNC call_itt_notify_v5(int t, void *ptr);
00114 void __TBB_EXPORTED_FUNC itt_store_pointer_with_release_v3(void *dst, void *src);
00115 void* __TBB_EXPORTED_FUNC itt_load_pointer_with_acquire_v3(const void *src);
00116 void* __TBB_EXPORTED_FUNC itt_load_pointer_v3( const void* src );
00117
00118
00119 template <typename T, typename U>
00120 inline void itt_store_word_with_release(tbb::atomic<T>& dst, U src) {
00121 #if TBB_USE_THREADING_TOOLS
00122
00123 __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized.");
00124 itt_store_pointer_with_release_v3(&dst, (void *)uintptr_t(src));
00125 #else
00126 dst = src;
00127 #endif // TBB_USE_THREADING_TOOLS
00128 }
00129
00130 template <typename T>
00131 inline T itt_load_word_with_acquire(const tbb::atomic<T>& src) {
00132 #if TBB_USE_THREADING_TOOLS
00133
00134 __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized.");
00135 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
00136
00137 #pragma warning (push)
00138 #pragma warning (disable: 4311)
00139 #endif
00140 T result = (T)itt_load_pointer_with_acquire_v3(&src);
00141 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
00142 #pragma warning (pop)
00143 #endif
00144 return result;
00145 #else
00146 return src;
00147 #endif // TBB_USE_THREADING_TOOLS
00148 }
00149
00150 template <typename T>
00151 inline void itt_store_word_with_release(T& dst, T src) {
00152 #if TBB_USE_THREADING_TOOLS
00153
00154 __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized.");
00155 itt_store_pointer_with_release_v3(&dst, (void *)src);
00156 #else
00157 __TBB_store_with_release(dst, src);
00158 #endif // TBB_USE_THREADING_TOOLS
00159 }
00160
00161 template <typename T>
00162 inline T itt_load_word_with_acquire(const T& src) {
00163 #if TBB_USE_THREADING_TOOLS
00164
00165 __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized");
00166 return (T)itt_load_pointer_with_acquire_v3(&src);
00167 #else
00168 return __TBB_load_with_acquire(src);
00169 #endif // TBB_USE_THREADING_TOOLS
00170 }
00171
00172 template <typename T>
00173 inline void itt_hide_store_word(T& dst, T src) {
00174 #if TBB_USE_THREADING_TOOLS
00175
00176 __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized");
00177 itt_store_pointer_with_release_v3(&dst, (void *)src);
00178 #else
00179 dst = src;
00180 #endif
00181 }
00182
00183 template <typename T>
00184 inline T itt_hide_load_word(const T& src) {
00185 #if TBB_USE_THREADING_TOOLS
00186
00187 __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized.");
00188 return (T)itt_load_pointer_v3(&src);
00189 #else
00190 return src;
00191 #endif
00192 }
00193
00194 #if TBB_USE_THREADING_TOOLS
00195 inline void call_itt_notify(notify_type t, void *ptr) {
00196 call_itt_notify_v5((int)t, ptr);
00197 }
00198 #else
00199 inline void call_itt_notify(notify_type , void * ) {}
00200 #endif // TBB_USE_THREADING_TOOLS
00201
00202 }
00203 }
00204
00205 #endif