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__) && 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 #endif