tbb_profiling.h

00001 /*
00002     Copyright 2005-2009 Intel Corporation.  All Rights Reserved.
00003 
00004     The source code contained or described herein and all documents related
00005     to the source code ("Material") are owned by Intel Corporation or its
00006     suppliers or licensors.  Title to the Material remains with Intel
00007     Corporation or its suppliers and licensors.  The Material is protected
00008     by worldwide copyright laws and treaty provisions.  No part of the
00009     Material may be used, copied, reproduced, modified, published, uploaded,
00010     posted, transmitted, distributed, or disclosed in any way without
00011     Intel's prior express written permission.
00012 
00013     No license under any patent, copyright, trade secret or other
00014     intellectual property right is granted to or conferred upon you by
00015     disclosure or delivery of the Materials, either expressly, by
00016     implication, inducement, estoppel or otherwise.  Any license under such
00017     intellectual property rights must be express and approved by Intel in
00018     writing.
00019 */
00020 
00021 #ifndef __TBB_profiling_H
00022 #define __TBB_profiling_H
00023 
00024 // Check if the tools support is enabled
00025 #if (_WIN32||_WIN64||__linux__) && TBB_USE_THREADING_TOOLS
00026 
00027 #if _WIN32||_WIN64
00028 #include <stdlib.h>  /* mbstowcs_s */
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;   // mbstowcs_s counts null terminator
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; // mbstowcs does not count null terminator
00046 #endif
00047         }
00048 #else
00049         void __TBB_EXPORTED_FUNC itt_set_sync_name_v3( void *obj, const char* name ); 
00050 #endif
00051     } // namespace internal
00052 } // namespace tbb
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 /* !WIN */
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 /* !WIN */
00079 
00080 #else /* no tools support */
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 /* !WIN */
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 /* !WIN */
00094 
00095 #endif /* no tools support */
00096 
00097 #endif /* __TBB_profiling_H */

Copyright © 2005-2009 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.