- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# tbb_profiling.h

    00001 /*
    00002     Copyright 2005-2012 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 #include "atomic.h"
    00106 // Need these to work regardless of tools support
    00107 namespace tbb {
    00108     namespace internal {
    00109
    00110         enum notify_type {prepare=0, cancel, acquired, releasing};
    00111         const uintptr_t NUM_NOTIFY_TYPES = 4; // set to # elements in enum above
    00112
    00113         void __TBB_EXPORTED_FUNC call_itt_notify_v5(int t, void *ptr);
    00114         void __TBB_EXPORTED_FUNC itt_store_pointer_with_release_v3(void *dst, void *src);
    00115         void* __TBB_EXPORTED_FUNC itt_load_pointer_with_acquire_v3(const void *src);
    00116         void* __TBB_EXPORTED_FUNC itt_load_pointer_v3( const void* src );
    00117
    00118         // two template arguments are to workaround /Wp64 warning with tbb::atomic specialized for unsigned type
    00119         template <typename T, typename U>
    00120         inline void itt_store_word_with_release(tbb::atomic<T>& dst, U src) {
    00121 #if TBB_USE_THREADING_TOOLS
    00122             // This assertion should be replaced with static_assert
    00123             __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized.");
    00124             itt_store_pointer_with_release_v3(&dst, (void *)uintptr_t(src));
    00125 #else
    00126             dst = src;
    00127 #endif // TBB_USE_THREADING_TOOLS
    00128         }
    00129
    00130         template <typename T>
    00131         inline T itt_load_word_with_acquire(const tbb::atomic<T>& src) {
    00132 #if TBB_USE_THREADING_TOOLS
    00133             // This assertion should be replaced with static_assert
    00134             __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized.");
    00135 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
    00136             // Workaround for overzealous compiler warnings
    00137             #pragma warning (push)
    00138             #pragma warning (disable: 4311)
    00139 #endif
    00140             T result = (T)itt_load_pointer_with_acquire_v3(&src);
    00141 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
    00142             #pragma warning (pop)
    00143 #endif
    00144             return result;
    00145 #else
    00146             return src;
    00147 #endif // TBB_USE_THREADING_TOOLS
    00148         }
    00149
    00150         template <typename T>
    00151         inline void itt_store_word_with_release(T& dst, T src) {
    00152 #if TBB_USE_THREADING_TOOLS
    00153             // This assertion should be replaced with static_assert
    00154             __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized.");
    00155             itt_store_pointer_with_release_v3(&dst, (void *)src);
    00156 #else
    00157             __TBB_store_with_release(dst, src);
    00158 #endif // TBB_USE_THREADING_TOOLS
    00159         }
    00160
    00161         template <typename T>
    00162         inline T itt_load_word_with_acquire(const T& src) {
    00163 #if TBB_USE_THREADING_TOOLS
    00164             // This assertion should be replaced with static_assert
    00165             __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized");
    00166             return (T)itt_load_pointer_with_acquire_v3(&src);
    00167 #else
    00168             return __TBB_load_with_acquire(src);
    00169 #endif // TBB_USE_THREADING_TOOLS
    00170         }
    00171
    00172         template <typename T>
    00173         inline void itt_hide_store_word(T& dst, T src) {
    00174 #if TBB_USE_THREADING_TOOLS
    00175             // This assertion should be replaced with static_assert
    00176             __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized");
    00177             itt_store_pointer_with_release_v3(&dst, (void *)src);
    00178 #else
    00179             dst = src;
    00180 #endif
    00181         }
    00182
    00183         template <typename T>
    00184         inline T itt_hide_load_word(const T& src) {
    00185 #if TBB_USE_THREADING_TOOLS
    00186             // This assertion should be replaced with static_assert
    00187             __TBB_ASSERT(sizeof(T) == sizeof(void *), "Type must be word-sized.");
    00188             return (T)itt_load_pointer_v3(&src);
    00189 #else
    00190             return src;
    00191 #endif
    00192         }
    00193
    00194 #if TBB_USE_THREADING_TOOLS
    00195         inline void call_itt_notify(notify_type t, void *ptr) {
    00196             call_itt_notify_v5((int)t, ptr);
    00197         }
    00198 #else
    00199         inline void call_itt_notify(notify_type /*t*/, void * /*ptr*/) {}
    00200 #endif // TBB_USE_THREADING_TOOLS
    00201
    00202     } // namespace internal
    00203 } // namespace tbb
    00204
    00205 #endif /* __TBB_profiling_H */

Copyright © 2005-2012 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.