Skip to content

Commit 767e75d

Browse files
committed
Merge.
2 parents 978cf12 + 45e8d40 commit 767e75d

File tree

1 file changed

+53
-11
lines changed

1 file changed

+53
-11
lines changed

src/global-init.cxx

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,10 @@ threadCleanup ()
385385
}
386386

387387

388-
} // namespace log4cplus
389-
390-
391-
#if defined (_WIN32) && defined (LOG4CPLUS_BUILD_DLL)
392-
393-
extern "C"
394-
BOOL
395-
WINAPI
396-
DllMain (LOG4CPLUS_DLLMAIN_HINSTANCE /*hinstDLL*/, DWORD fdwReason,
397-
LPVOID /*lpReserved*/)
388+
#if defined (_WIN32)
389+
static
390+
void NTAPI
391+
thread_callback (LPVOID /*hinstDLL*/, DWORD fdwReason, LPVOID /*lpReserved*/)
398392
{
399393
// Perform actions based on the reason for calling.
400394
switch( fdwReason )
@@ -438,13 +432,60 @@ DllMain (LOG4CPLUS_DLLMAIN_HINSTANCE /*hinstDLL*/, DWORD fdwReason,
438432
break;
439433
}
440434

441-
}
435+
} // switch
436+
}
437+
438+
#endif
439+
440+
441+
} // namespace log4cplus
442+
443+
444+
#if defined (_WIN32) && defined (LOG4CPLUS_BUILD_DLL)
445+
446+
extern "C"
447+
BOOL
448+
WINAPI
449+
DllMain (LOG4CPLUS_DLLMAIN_HINSTANCE hinstDLL, DWORD fdwReason,
450+
LPVOID lpReserved)
451+
{
452+
log4cplus::thread_callback (hinstDLL, fdwReason, lpReserved);
442453

443454
return TRUE; // Successful DLL_PROCESS_ATTACH.
444455
}
445456

446457
#else
447458

459+
#if defined (_MSC_VER) && _MSC_VER >= 1400
460+
461+
extern "C"
462+
{
463+
464+
// This magic has been pieced together from several sources:
465+
// - <http://www.nynaeve.net/?p=183>
466+
// - <http://lists.cs.uiuc.edu/pipermail/cfe-dev/2011-November/018818.html>
467+
468+
#pragma data_seg (push, old_seg)
469+
#ifdef _WIN64
470+
#pragma const_seg (".CRT$XLX")
471+
extern const
472+
#else
473+
#pragma data_seg (".CRT$XLX")
474+
#endif
475+
PIMAGE_TLS_CALLBACK p_thread_callback = log4cplus::thread_callback;
476+
#pragma data_seg (pop, old_seg)
477+
#ifdef _WIN64
478+
#pragma comment (linker, "/INCLUDE:_tls_used")
479+
#pragma comment (linker, "/INCLUDE:p_thread_callback")
480+
#else
481+
#pragma comment (linker, "/INCLUDE:__tls_used")
482+
#pragma comment (linker, "/INCLUDE:_p_thread_callback")
483+
#endif
484+
485+
} // extern "C"
486+
487+
#else
488+
448489
namespace {
449490

450491
struct _static_log4cplus_initializer
@@ -462,5 +503,6 @@ namespace {
462503
} static initializer;
463504
}
464505

506+
#endif
465507

466508
#endif

0 commit comments

Comments
 (0)