]> git.sesse.net Git - casparcg/blob - tbb30_20100406oss/include/tbb/tbb_profiling.h
c3bbb5125962591ebd7ebff47586b16796f2a95b
[casparcg] / tbb30_20100406oss / include / tbb / tbb_profiling.h
1 /*
2     Copyright 2005-2010 Intel Corporation.  All Rights Reserved.
3
4     This file is part of Threading Building Blocks.
5
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.
9
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.
14
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
18
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.
27 */
28
29 #ifndef __TBB_profiling_H
30 #define __TBB_profiling_H
31
32 // Check if the tools support is enabled
33 #if (_WIN32||_WIN64||__linux__) && !__MINGW32__ && TBB_USE_THREADING_TOOLS
34
35 #if _WIN32||_WIN64
36 #include <stdlib.h>  /* mbstowcs_s */
37 #endif
38 #include "tbb_stddef.h"
39
40 namespace tbb {
41     namespace internal {
42 #if _WIN32||_WIN64
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) {
45 #if _MSC_VER>=1400
46             size_t len;
47             mbstowcs_s( &len, wcs, bufsize, mbs, _TRUNCATE );
48             return len;   // mbstowcs_s counts null terminator
49 #else
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
54 #endif
55         }
56 #else
57         void __TBB_EXPORTED_FUNC itt_set_sync_name_v3( void *obj, const char* name ); 
58 #endif
59     } // namespace internal
60 } // namespace tbb
61
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. **/
65 #if _WIN32||_WIN64
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 );                  \
70             }                                                                       \
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 );                                             \
76                 delete[] wname;                                                     \
77             }                                                                       \
78         }
79 #else /* !WIN */
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 );                  \
84             }                                                                       \
85         }
86 #endif /* !WIN */
87
88 #else /* no tools support */
89
90 #if _WIN32||_WIN64
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* ) {}       \
95         }
96 #else /* !WIN */
97     #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type)    \
98         namespace profiling {                                               \
99             inline void set_name( sync_object_type&, const char* ) {}       \
100         }
101 #endif /* !WIN */
102
103 #endif /* no tools support */
104
105 #endif /* __TBB_profiling_H */