diff --git a/src/libCom/Makefile b/src/libCom/Makefile index 830debf44..9dd6cb907 100644 --- a/src/libCom/Makefile +++ b/src/libCom/Makefile @@ -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 diff --git a/src/libCom/osi/os/WIN32/osdThread.c b/src/libCom/osi/os/WIN32/osdThread.c index edea368b0..93fd7c816 100644 --- a/src/libCom/osi/os/WIN32/osdThread.c +++ b/src/libCom/osi/os/WIN32/osdThread.c @@ -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 ) { diff --git a/src/libCom/osi/os/WIN32/setThreadName.cpp b/src/libCom/osi/os/WIN32/setThreadName.cpp new file mode 100644 index 000000000..c9e1d5158 --- /dev/null +++ b/src/libCom/osi/os/WIN32/setThreadName.cpp @@ -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 + +/* + * 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 ( ... ) + { + } +} \ No newline at end of file