/**************************************************************************** ** TAU Portable Profiling Package ** ** http://www.cs.uoregon.edu/research/tau ** ***************************************************************************** ** Copyright 1997 ** ** Department of Computer and Information Science, University of Oregon ** ** Advanced Computing Laboratory, Los Alamos National Laboratory ** ****************************************************************************/ /*************************************************************************** ** File : WindowsThreadLayer.cpp ** ** Description : RTS Layer definitions ** ** for supporting Microsoft Windows' Threads ** ** Contact : tau-team@cs.uoregon.edu ** ** Documentation : See http://www.cs.uoregon.edu/research/tau ** ***************************************************************************/ #ifdef TAU_WINDOWS ////////////////////////////////////////////////////////////////////// // Include Files ////////////////////////////////////////////////////////////////////// #include using namespace std; #include "Profile/Profiler.h" ///////////////////////////////////////////////////////////////////////// // Member Function Definitions For class WindowsThreadLayer // This allows us to get thread ids from 0..N-1 instead of long nos // as generated by built-in threadid calls. ///////////////////////////////////////////////////////////////////////// DWORD WindowsThreadLayer::tauWindowsthreadId; HANDLE WindowsThreadLayer::tauThreadcountMutex; HANDLE WindowsThreadLayer::tauDBMutex; HANDLE WindowsThreadLayer::tauEnvMutex; int WindowsThreadLayer::tauThreadCount = 0; //////////////////////////////////////////////////////////////////////// // RegisterThread() should be called before any profiling routines are // invoked. This routine sets the thread id that is used by the code in // FunctionInfo and Profiler classes. This should be the first routine a // thread should invoke from its wrapper. Note: main() thread shouldn't // call this routine. //////////////////////////////////////////////////////////////////////// int WindowsThreadLayer::RegisterThread(void) { int *threadId = new int; DWORD WaitCheck; WaitCheck = WaitForSingleObject(tauThreadcountMutex, INFINITE); if(WaitCheck == WAIT_OBJECT_0) { tauThreadCount ++; // A thread should call this routine exactly once. *threadId = tauThreadCount; DEBUGPROFMSG("Thread id "<< tauThreadCount<< " Created! "<