mirror of
https://github.com/boostorg/thread.git
synced 2026-01-24 06:22:12 +00:00
Updated format (removed tabs) and added missing copyrights
[SVN r17214]
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
// threadmon.cpp : Defines the entry point for the DLL application.
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appear in all copies and
|
||||
// that both that copyright notice and this permission notice appear
|
||||
// in supporting documentation. William E. Kempf makes no representations
|
||||
// about the suitability of this software for any purpose.
|
||||
// It is provided "as is" without express or implied warranty.
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
@@ -26,9 +34,9 @@ typedef std::set<exit_handlers*> registered_handlers;
|
||||
|
||||
namespace
|
||||
{
|
||||
CRITICAL_SECTION cs;
|
||||
DWORD key;
|
||||
registered_handlers registry;
|
||||
CRITICAL_SECTION cs;
|
||||
DWORD key;
|
||||
registered_handlers registry;
|
||||
}
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
@@ -40,66 +48,66 @@ BOOL WINAPI DllMain(HANDLE module, DWORD reason, LPVOID)
|
||||
{
|
||||
switch (reason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
InitializeCriticalSection(&cs);
|
||||
key = TlsAlloc();
|
||||
break;
|
||||
case DLL_THREAD_ATTACH:
|
||||
break;
|
||||
case DLL_THREAD_DETACH:
|
||||
case DLL_PROCESS_ATTACH:
|
||||
InitializeCriticalSection(&cs);
|
||||
key = TlsAlloc();
|
||||
break;
|
||||
case DLL_THREAD_ATTACH:
|
||||
break;
|
||||
case DLL_THREAD_DETACH:
|
||||
{
|
||||
// Call the thread's exit handlers.
|
||||
exit_handlers* handlers =
|
||||
static_cast<exit_handlers*>(TlsGetValue(key));
|
||||
if (handlers)
|
||||
{
|
||||
for (exit_handlers::iterator it = handlers->begin();
|
||||
it != handlers->end(); ++it)
|
||||
{
|
||||
// Call the thread's exit handlers.
|
||||
exit_handlers* handlers =
|
||||
static_cast<exit_handlers*>(TlsGetValue(key));
|
||||
if (handlers)
|
||||
{
|
||||
for (exit_handlers::iterator it = handlers->begin();
|
||||
it != handlers->end(); ++it)
|
||||
{
|
||||
(*it)();
|
||||
}
|
||||
|
||||
// Remove the exit handler list from the registered lists
|
||||
// and then destroy it.
|
||||
EnterCriticalSection(&cs);
|
||||
registry.erase(handlers);
|
||||
LeaveCriticalSection(&cs);
|
||||
delete handlers;
|
||||
}
|
||||
(*it)();
|
||||
}
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
|
||||
// Remove the exit handler list from the registered lists
|
||||
// and then destroy it.
|
||||
EnterCriticalSection(&cs);
|
||||
registry.erase(handlers);
|
||||
LeaveCriticalSection(&cs);
|
||||
delete handlers;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
{
|
||||
// Assume the main thread is ending (call its handlers) and
|
||||
// all other threads have already ended. If this DLL is
|
||||
// loaded and unloaded dynamically at run time
|
||||
// this is a bad assumption, but this is the best we can do.
|
||||
exit_handlers* handlers =
|
||||
static_cast<exit_handlers*>(TlsGetValue(key));
|
||||
if (handlers)
|
||||
{
|
||||
for (exit_handlers::iterator it = handlers->begin();
|
||||
it != handlers->end(); ++it)
|
||||
{
|
||||
// Assume the main thread is ending (call its handlers) and
|
||||
// all other threads have already ended. If this DLL is
|
||||
// loaded and unloaded dynamically at run time
|
||||
// this is a bad assumption, but this is the best we can do.
|
||||
exit_handlers* handlers =
|
||||
static_cast<exit_handlers*>(TlsGetValue(key));
|
||||
if (handlers)
|
||||
{
|
||||
for (exit_handlers::iterator it = handlers->begin();
|
||||
it != handlers->end(); ++it)
|
||||
{
|
||||
(*it)();
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy any remaining exit handlers. Above we assumed
|
||||
// there'd only be the main thread left, but to insure we
|
||||
// don't get memory leaks we won't make that assumption
|
||||
// here.
|
||||
EnterCriticalSection(&cs);
|
||||
for (registered_handlers::iterator it = registry.begin();
|
||||
it != registry.end(); ++it)
|
||||
{
|
||||
delete (*it);
|
||||
}
|
||||
LeaveCriticalSection(&cs);
|
||||
DeleteCriticalSection(&cs);
|
||||
TlsFree(key);
|
||||
(*it)();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Destroy any remaining exit handlers. Above we assumed
|
||||
// there'd only be the main thread left, but to insure we
|
||||
// don't get memory leaks we won't make that assumption
|
||||
// here.
|
||||
EnterCriticalSection(&cs);
|
||||
for (registered_handlers::iterator it = registry.begin();
|
||||
it != registry.end(); ++it)
|
||||
{
|
||||
delete (*it);
|
||||
}
|
||||
LeaveCriticalSection(&cs);
|
||||
DeleteCriticalSection(&cs);
|
||||
TlsFree(key);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user