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