1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
|
////////////////////////////////////////////////////////////////////////////////////
// fishhang.h verify/debug proper Hercules LOCK handling...
////////////////////////////////////////////////////////////////////////////////////
// (c) Copyright "Fish" (David B. Trout), 2002-2009. Released under the Q Public License
// (http://www.hercules-390.org/herclic.html) as modifications to Hercules.
////////////////////////////////////////////////////////////////////////////////////
// $Id: fishhang.h 5125 2009-01-23 12:01:44Z bernard $
//
// $Log$
// Revision 1.16 2008/11/29 21:22:09 rbowler
// Fix win64 warning C4267 conversion from size_t to unsigned int in fthreads.c
//
// Revision 1.15 2007/11/30 14:54:32 jmaynard
// Changed conmicro.cx to hercules-390.org or conmicro.com, as needed.
//
// Revision 1.14 2007/06/23 00:04:09 ivan
// Update copyright notices to include current year (2007)
//
// Revision 1.13 2006/12/31 12:25:26 fish
// Fix "undefined reference to _beginthreadex" issue for non-MSVC (i.e. Cygwin) builds.
//
// Revision 1.12 2006/12/28 15:49:35 fish
// Use _beginthreadex/_endthreadex instead of CreateThread/ExitThread in continuing effort to try and resolve our still existing long-standing 'errno' issue...
//
// Revision 1.11 2006/12/08 09:43:21 jj
// Add CVS message log
//
#ifndef _FISHHANG_H_
#define _FISHHANG_H_
#ifndef _FISHHANG_C_
#ifndef _HUTIL_DLL_
#define FH_DLL_IMPORT DLL_IMPORT
#else /* _HUTIL_DLL_ */
#define FH_DLL_IMPORT extern
#endif /* _HUTIL_DLL_ */
#else
#define FH_DLL_IMPORT DLL_EXPORT
#endif
#include <windows.h>
/////////////////////////////////////////////////////////////////////////////
// The pttrace facility cannot be used if FISH_HANG is enabled...
#if (defined(DEBUG) || defined(_DEBUG)) && !defined(FISH_HANG)
#define FT_ENABLE_DEBUG_VIA_PTTRACE
#endif
#ifdef FT_ENABLE_DEBUG_VIA_PTTRACE
#ifdef FISH_HANG
#error OPTION_PTTRACE incompatible with (mutually exclusive to) FISH_HANG
#endif
#endif
/////////////////////////////////////////////////////////////////////////////
#if defined(FISH_HANG)
#ifdef FT_ENABLE_DEBUG_VIA_PTTRACE
#error FISH_HANG incompatible with (mutually exclusive to) OPTION_PTTRACE
#endif
// fthreads makes Win32 calls on behalf of the caller and thus passes
// the CALLER'S file and line# value to FishHang, whereas other Win32
// modules (such as 'w32chan.c' for example) call Win32 function on
// behalf of themselves.
// Thus we need two different sets of macros: one for 'fthreads.c' to
// use, and another for all other Win32 modules to use, thus allowing
// FishHang to accurately report the responsible party...
#if defined( _FTHREADS_C_ )
#define MyInitializeCriticalSection(pCS) (FishHang_InitializeCriticalSection(pszFile,nLine,(CRITICAL_SECTION*)(pCS)))
#define MyEnterCriticalSection(pCS) (FishHang_EnterCriticalSection(pszFile,nLine,(CRITICAL_SECTION*)(pCS)))
#define MyTryEnterCriticalSection(pCS) (FishHang_TryEnterCriticalSection(pszFile,nLine,(CRITICAL_SECTION*)(pCS)))
#define MyLeaveCriticalSection(pCS) (FishHang_LeaveCriticalSection(pszFile,nLine,(CRITICAL_SECTION*)(pCS)))
#define MyDeleteCriticalSection(pCS) (FishHang_DeleteCriticalSection(pszFile,nLine,(CRITICAL_SECTION*)(pCS)))
#define MyCreateThread(sec,stack,start,parm,flags,tid) (FishHang_CreateThread(pszFile,nLine,(sec),(stack),(start),(parm),(flags),(tid)))
#define MyExitThread(code) (FishHang_ExitThread((code)))
#define MyCreateEvent(sec,man,set,name) (FishHang_CreateEvent(pszFile,nLine,(sec),(man),(set),(name)))
#define MySetEvent(h) (FishHang_SetEvent(pszFile,nLine,(h)))
#define MyResetEvent(h) (FishHang_ResetEvent(pszFile,nLine,(h)))
#define MyDeleteEvent(h) (FishHang_CloseHandle(pszFile,nLine,(h)))
#define MyCloseHandle(h) (FishHang_CloseHandle(pszFile,nLine,(h)))
#define MyWaitForSingleObject(h,millsecs) (FishHang_WaitForSingleObject(pszFile,nLine,(h),(millsecs)))
#else
#define MyInitializeCriticalSection(pCS) (FishHang_InitializeCriticalSection(__FILE__,__LINE__,(CRITICAL_SECTION*)(pCS)))
#define MyEnterCriticalSection(pCS) (FishHang_EnterCriticalSection(__FILE__,__LINE__,(CRITICAL_SECTION*)(pCS)))
#define MyTryEnterCriticalSection(pCS) (FishHang_TryEnterCriticalSection(__FILE__,__LINE__,(CRITICAL_SECTION*)(pCS)))
#define MyLeaveCriticalSection(pCS) (FishHang_LeaveCriticalSection(__FILE__,__LINE__,(CRITICAL_SECTION*)(pCS)))
#define MyDeleteCriticalSection(pCS) (FishHang_DeleteCriticalSection(__FILE__,__LINE__,(CRITICAL_SECTION*)(pCS)))
#define MyCreateThread(sec,stack,start,parm,flags,tid) (FishHang_CreateThread(__FILE__,__LINE__,(sec),(stack),(start),(parm),(flags),(tid)))
#define MyExitThread(code) (FishHang_ExitThread((code)))
#define MyCreateEvent(sec,man,set,name) (FishHang_CreateEvent(__FILE__,__LINE__,(sec),(man),(set),(name)))
#define MySetEvent(h) (FishHang_SetEvent(__FILE__,__LINE__,(h)))
#define MyResetEvent(h) (FishHang_ResetEvent(__FILE__,__LINE__,(h)))
#define MyDeleteEvent(h) (FishHang_CloseHandle(__FILE__,__LINE__,(h)))
#define MyCloseHandle(h) (FishHang_CloseHandle(__FILE__,__LINE__,(h)))
#define MyWaitForSingleObject(h,millsecs) (FishHang_WaitForSingleObject(__FILE__,__LINE__,(h),(millsecs)))
#endif
#else // !defined(FISH_HANG)
#define MyInitializeCriticalSection(pCS) (InitializeCriticalSectionAndSpinCount((CRITICAL_SECTION*)(pCS),3000))
#define MyEnterCriticalSection(pCS) (EnterCriticalSection((CRITICAL_SECTION*)(pCS)))
#define MyTryEnterCriticalSection(pCS) (TryEnterCriticalSection((CRITICAL_SECTION*)(pCS)))
#define MyLeaveCriticalSection(pCS) (LeaveCriticalSection((CRITICAL_SECTION*)(pCS)))
#define MyDeleteCriticalSection(pCS) (DeleteCriticalSection((CRITICAL_SECTION*)(pCS)))
#ifdef _MSVC_
#define MyCreateThread(sec,stack,start,parm,flags,tid) ((HANDLE) _beginthreadex((sec),(unsigned)(stack),(start),(parm),(flags),(tid)))
#define MyExitThread(code) (_endthreadex((code)))
#else // (Cygwin)
#define MyCreateThread(sec,stack,start,parm,flags,tid) (CreateThread((sec),(stack),(start),(parm),(flags),(tid)))
#define MyExitThread(code) (ExitThread((code)))
#endif
#define MyCreateEvent(sec,man,set,name) (CreateEvent((sec),(man),(set),(name)))
#define MySetEvent(h) (SetEvent((h)))
#define MyResetEvent(h) (ResetEvent((h)))
#define MyDeleteEvent(h) (CloseHandle((h)))
#define MyCloseHandle(h) (CloseHandle((h)))
#define MyWaitForSingleObject(h,millisecs) (WaitForSingleObject((h),(millisecs)))
#endif // defined(FISH_HANG)
/////////////////////////////////////////////////////////////////////////////
FH_DLL_IMPORT
HANDLE FishHang_CreateThread
(
const char* pszFileCreated, // source file that created it
const int nLineCreated, // line number of source file
LPSECURITY_ATTRIBUTES lpThreadAttributes, // pointer to security attributes
DWORD dwStackSize, // initial thread stack size
LPTHREAD_START_ROUTINE lpStartAddress, // pointer to thread function
LPVOID lpParameter, // argument for new thread
DWORD dwCreationFlags, // creation flags
LPDWORD lpThreadId // pointer to receive thread ID
);
/////////////////////////////////////////////////////////////////////////////
FH_DLL_IMPORT
void FishHang_ExitThread
(
DWORD dwExitCode // exit code for this thread
);
/////////////////////////////////////////////////////////////////////////////
FH_DLL_IMPORT
void FishHang_InitializeCriticalSection
(
const char* pszFileCreated, // source file that created it
const int nLineCreated, // line number of source file
LPCRITICAL_SECTION lpCriticalSection // address of critical section object
);
/////////////////////////////////////////////////////////////////////////////
FH_DLL_IMPORT
void FishHang_DeleteCriticalSection
(
const char* pszFileDeleting, // source file that's deleting it
const int nLineDeleting, // line number of source file
LPCRITICAL_SECTION lpCriticalSection // address of critical section object
);
/////////////////////////////////////////////////////////////////////////////
FH_DLL_IMPORT
void FishHang_EnterCriticalSection
(
const char* pszFileWaiting, // source file that attempted it
const int nLineWaiting, // line number of source file
LPCRITICAL_SECTION lpCriticalSection // address of critical section object
);
/////////////////////////////////////////////////////////////////////////////
FH_DLL_IMPORT
BOOL FishHang_TryEnterCriticalSection
(
const char* pszFileWaiting, // source file that attempted it
const int nLineWaiting, // line number of source file
LPCRITICAL_SECTION lpCriticalSection // address of critical section object
);
/////////////////////////////////////////////////////////////////////////////
FH_DLL_IMPORT
void FishHang_LeaveCriticalSection
(
const char* pszFileReleasing, // source file that attempted it
const int nLineReleasing, // line number of source file
LPCRITICAL_SECTION lpCriticalSection // address of critical section object
);
/////////////////////////////////////////////////////////////////////////////
FH_DLL_IMPORT
HANDLE FishHang_CreateEvent
(
const char* pszFileCreated, // source file that created it
const int nLineCreated, // line number of source file
LPSECURITY_ATTRIBUTES lpEventAttributes, // pointer to security attributes
BOOL bManualReset, // flag for manual-reset event
BOOL bInitialState, // flag for initial state
LPCTSTR lpName // pointer to event-object name
);
/////////////////////////////////////////////////////////////////////////////
FH_DLL_IMPORT
BOOL FishHang_SetEvent
(
const char* pszFileSet, // source file that set it
const int nLineSet, // line number of source file
HANDLE hEvent // handle to event object
);
/////////////////////////////////////////////////////////////////////////////
FH_DLL_IMPORT
BOOL FishHang_ResetEvent
(
const char* pszFileReset, // source file that reset it
const int nLineReset, // line number of source file
HANDLE hEvent // handle to event object
);
/////////////////////////////////////////////////////////////////////////////
FH_DLL_IMPORT
BOOL FishHang_PulseEvent
(
const char* pszFilePosted, // source file that signalled it
const int nLinePosted, // line number of source file
HANDLE hEvent // handle to event object
);
/////////////////////////////////////////////////////////////////////////////
FH_DLL_IMPORT
BOOL FishHang_CloseHandle // ** NOTE: only events for right now **
(
const char* pszFileClosed, // source file that closed it
const int nLineClosed, // line number of source file
HANDLE hEvent // handle to event object
);
/////////////////////////////////////////////////////////////////////////////
FH_DLL_IMPORT
DWORD FishHang_WaitForSingleObject // ** NOTE: only events for right now **
(
const char* pszFileWaiting, // source file that's waiting on it
const int nLineWaiting, // line number of source file
HANDLE hEvent, // handle to event to wait for
DWORD dwMilliseconds // time-out interval in milliseconds
);
/////////////////////////////////////////////////////////////////////////////
FH_DLL_IMPORT int bFishHangAtExit; // (set to true when shutting down)
FH_DLL_IMPORT void FishHangInit( const char* pszFileCreated, const int nLineCreated );
FH_DLL_IMPORT void FishHangReport();
FH_DLL_IMPORT void FishHangAtExit();
FH_DLL_IMPORT void FishHang_Printf( const char* pszFormat, ... );
/////////////////////////////////////////////////////////////////////////////
#endif // _FISHHANG_H_
|