moved setThreadName() out so that it could use C++ exceptions instead of

windows structured exceptions (which are not compiler portable)
This commit is contained in:
Jeff Hill
2004-08-11 00:46:38 +00:00
parent 2d613ba5d0
commit 73dd387f05
3 changed files with 54 additions and 32 deletions
+2 -1
View File
@@ -202,7 +202,8 @@ SRCS += osdProcess.c
SRCS += osdNetIntf.c
SRCS += osdMessageQueue.c
SRCS_WIN32 += epicsGetopt.c
SRCS_WIN32 += epicsGetopt.c
SRCS_WIN32 += setThreadName.cpp
SRCS_vxWorks += devLib.c
SRCS_vxWorks += devLibOSD.c
+3 -31
View File
@@ -37,6 +37,8 @@
#include "epicsAssert.h"
#include "ellLib.h"
void setThreadName ( DWORD dwThreadID, LPCSTR szThreadName );
typedef struct win32ThreadGlobal {
CRITICAL_SECTION mutex;
ELLLIST threadList;
@@ -401,36 +403,6 @@ void epicsThreadCleanupWIN32 ()
epicsParmCleanupWIN32 ( pParm );
}
/*
* this was copied directly from example in visual c++ 7 documentation
*
* Usage: SetThreadName (-1, "MainThread");
*/
void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName )
{
typedef struct tagTHREADNAME_INFO
{
DWORD dwType; // must be 0x1000
LPCSTR szName; // pointer to name (in user addr space)
DWORD dwThreadID; // thread ID (-1=caller thread)
DWORD dwFlags; // reserved for future use, must be zero
} THREADNAME_INFO;
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = szThreadName;
info.dwThreadID = dwThreadID;
info.dwFlags = 0;
__try
{
RaiseException ( 0x406D1388, 0,
sizeof(info)/sizeof(DWORD), (DWORD*)&info );
}
__except ( EXCEPTION_CONTINUE_EXECUTION )
{
}
}
/*
* epicsWin32ThreadEntry()
*/
@@ -442,7 +414,7 @@ static unsigned WINAPI epicsWin32ThreadEntry ( LPVOID lpParameter )
BOOL success;
if ( pGbl ) {
SetThreadName ( pParm->id, pParm->pName );
setThreadName ( pParm->id, pParm->pName );
success = TlsSetValue ( pGbl->tlsIndexThreadLibraryEPICS, pParm );
if ( success ) {
+49
View File
@@ -0,0 +1,49 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
#define VC_EXTRALEAN
#define STRICT
#if _WIN64
# define _WIN32_WINNT 0x400 /* defining this drops support for W95 */
#endif
#include <windows.h>
/*
* this was copied directly from an example in visual c++ 7 documentation,
* except that C++ exceptions were substituted for structured
* exceptions (which are not portable to other compilers)
*
* Usage: setThreadName (-1, "MainThread");
*/
extern "C" void setThreadName ( DWORD dwThreadID, LPCSTR szThreadName )
{
typedef struct tagTHREADNAME_INFO
{
DWORD dwType; // must be 0x1000
LPCSTR szName; // pointer to name (in user addr space)
DWORD dwThreadID; // thread ID (-1=caller thread)
DWORD dwFlags; // reserved for future use, must be zero
} THREADNAME_INFO;
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = szThreadName;
info.dwThreadID = dwThreadID;
info.dwFlags = 0;
try
{
RaiseException ( 0x406D1388, 0,
sizeof(info)/sizeof(DWORD), (DWORD*)&info );
}
catch ( ... )
{
}
}