Shadowrun: Awakened 29 September 2011 - Build 871
tbb_profiling.h
Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2010 Intel Corporation.  All Rights Reserved.
00003 
00004     This file is part of Threading Building Blocks.
00005 
00006     Threading Building Blocks is free software; you can redistribute it
00007     and/or modify it under the terms of the GNU General Public License
00008     version 2 as published by the Free Software Foundation.
00009 
00010     Threading Building Blocks is distributed in the hope that it will be
00011     useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00012     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with Threading Building Blocks; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019     As a special exception, you may use this file as part of a free software
00020     library without restriction.  Specifically, if other files instantiate
00021     templates or use macros or inline functions from this file, or you compile
00022     this file and link it with other files to produce an executable, this
00023     file does not by itself cause the resulting executable to be covered by
00024     the GNU General Public License.  This exception does not however
00025     invalidate any other reasons why the executable file might be covered by
00026     the GNU General Public License.
00027 */
00028 
00029 #ifndef __TBB_profiling_H
00030 #define __TBB_profiling_H
00031 
00032 // Check if the tools support is enabled
00033 #if (_WIN32||_WIN64||__linux__) && !__MINGW32__ && TBB_USE_THREADING_TOOLS
00034 
00035 #if _WIN32||_WIN64
00036 #include <stdlib.h>  /* mbstowcs_s */
00037 #endif
00038 #include "tbb_stddef.h"
00039 
00040 namespace tbb {
00041     namespace internal {
00042 #if _WIN32||_WIN64
00043         void __TBB_EXPORTED_FUNC itt_set_sync_name_v3( void *obj, const wchar_t* name ); 
00044         inline size_t multibyte_to_widechar( wchar_t* wcs, const char* mbs, size_t bufsize) {
00045 #if _MSC_VER>=1400
00046             size_t len;
00047             mbstowcs_s( &len, wcs, bufsize, mbs, _TRUNCATE );
00048             return len;   // mbstowcs_s counts null terminator
00049 #else
00050             size_t len = mbstowcs( wcs, mbs, bufsize );
00051             if(wcs && len!=size_t(-1) )
00052                 wcs[len<bufsize-1? len: bufsize-1] = wchar_t('\0');
00053             return len+1; // mbstowcs does not count null terminator
00054 #endif
00055         }
00056 #else
00057         void __TBB_EXPORTED_FUNC itt_set_sync_name_v3( void *obj, const char* name ); 
00058 #endif
00059     } // namespace internal
00060 } // namespace tbb
00061 
00063 
00065 #if _WIN32||_WIN64
00066     #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type)    \
00067         namespace profiling {                                                       \
00068             inline void set_name( sync_object_type& obj, const wchar_t* name ) {    \
00069                 tbb::internal::itt_set_sync_name_v3( &obj, name );                  \
00070             }                                                                       \
00071             inline void set_name( sync_object_type& obj, const char* name ) {       \
00072                 size_t len = tbb::internal::multibyte_to_widechar(NULL, name, 0);   \
00073                 wchar_t *wname = new wchar_t[len];                                  \
00074                 tbb::internal::multibyte_to_widechar(wname, name, len);             \
00075                 set_name( obj, wname );                                             \
00076                 delete[] wname;                                                     \
00077             }                                                                       \
00078         }
00079 #else /* !WIN */
00080     #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type)    \
00081         namespace profiling {                                                       \
00082             inline void set_name( sync_object_type& obj, const char* name ) {       \
00083                 tbb::internal::itt_set_sync_name_v3( &obj, name );                  \
00084             }                                                                       \
00085         }
00086 #endif /* !WIN */
00087 
00088 #else /* no tools support */
00089 
00090 #if _WIN32||_WIN64
00091     #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type)    \
00092         namespace profiling {                                               \
00093             inline void set_name( sync_object_type&, const wchar_t* ) {}    \
00094             inline void set_name( sync_object_type&, const char* ) {}       \
00095         }
00096 #else /* !WIN */
00097     #define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type)    \
00098         namespace profiling {                                               \
00099             inline void set_name( sync_object_type&, const char* ) {}       \
00100         }
00101 #endif /* !WIN */
00102 
00103 #endif /* no tools support */
00104 
00105 #endif /* __TBB_profiling_H */

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net