2 Copyright 2005-2010 Intel Corporation. All Rights Reserved.
4 This file is part of Threading Building Blocks.
6 Threading Building Blocks is free software; you can redistribute it
7 and/or modify it under the terms of the GNU General Public License
8 version 2 as published by the Free Software Foundation.
10 Threading Building Blocks is distributed in the hope that it will be
11 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with Threading Building Blocks; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 As a special exception, you may use this file as part of a free software
20 library without restriction. Specifically, if other files instantiate
21 templates or use macros or inline functions from this file, or you compile
22 this file and link it with other files to produce an executable, this
23 file does not by itself cause the resulting executable to be covered by
24 the GNU General Public License. This exception does not however
25 invalidate any other reasons why the executable file might be covered by
26 the GNU General Public License.
29 #ifndef __TBB_profiling_H
30 #define __TBB_profiling_H
32 // Check if the tools support is enabled
33 #if (_WIN32||_WIN64||__linux__) && !__MINGW32__ && TBB_USE_THREADING_TOOLS
36 #include <stdlib.h> /* mbstowcs_s */
38 #include "tbb_stddef.h"
43 void __TBB_EXPORTED_FUNC itt_set_sync_name_v3( void *obj, const wchar_t* name );
44 inline size_t multibyte_to_widechar( wchar_t* wcs, const char* mbs, size_t bufsize) {
47 mbstowcs_s( &len, wcs, bufsize, mbs, _TRUNCATE );
48 return len; // mbstowcs_s counts null terminator
50 size_t len = mbstowcs( wcs, mbs, bufsize );
51 if(wcs && len!=size_t(-1) )
52 wcs[len<bufsize-1? len: bufsize-1] = wchar_t('\0');
53 return len+1; // mbstowcs does not count null terminator
57 void __TBB_EXPORTED_FUNC itt_set_sync_name_v3( void *obj, const char* name );
59 } // namespace internal
62 //! Macro __TBB_DEFINE_PROFILING_SET_NAME(T) defines "set_name" methods for sync objects of type T
63 /** Should be used in the "tbb" namespace only.
64 Don't place semicolon after it to avoid compiler warnings. **/
66 #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type) \
67 namespace profiling { \
68 inline void set_name( sync_object_type& obj, const wchar_t* name ) { \
69 tbb::internal::itt_set_sync_name_v3( &obj, name ); \
71 inline void set_name( sync_object_type& obj, const char* name ) { \
72 size_t len = tbb::internal::multibyte_to_widechar(NULL, name, 0); \
73 wchar_t *wname = new wchar_t[len]; \
74 tbb::internal::multibyte_to_widechar(wname, name, len); \
75 set_name( obj, wname ); \
80 #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type) \
81 namespace profiling { \
82 inline void set_name( sync_object_type& obj, const char* name ) { \
83 tbb::internal::itt_set_sync_name_v3( &obj, name ); \
88 #else /* no tools support */
91 #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type) \
92 namespace profiling { \
93 inline void set_name( sync_object_type&, const wchar_t* ) {} \
94 inline void set_name( sync_object_type&, const char* ) {} \
97 #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type) \
98 namespace profiling { \
99 inline void set_name( sync_object_type&, const char* ) {} \
103 #endif /* no tools support */
105 #endif /* __TBB_profiling_H */