mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-30 22:47:16 +08:00
mdbx-windows: remove MDBX_CONFIG_MANUAL_TLS_CALLBACK
build option and add MDBX_MANUAL_MODULE_HANDLER
macro.
Briefly: - Now constructor/destructor of "Thread Local Storage" handled automatically when possible. - Otherwise the MDBX_CONFIG_MANUAL_TLS_CALLBACK macro defined to 1 to indicate that mdbx_module_handle() should be called manually. - Corresponding build option MDBX_CONFIG_MANUAL_TLS_CALLBACK was removed. Related to https://github.com/erthink/libmdbx/issues/155 Change-Id: Ic4e6a34b44f874676f0ab212ff473460e3d80559
This commit is contained in:
parent
3aa8701c6d
commit
ecd3c06932
@ -445,9 +445,6 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
|||||||
if(MDBX_NTDLL_EXTRA_IMPLIB)
|
if(MDBX_NTDLL_EXTRA_IMPLIB)
|
||||||
add_mdbx_option(MDBX_WITHOUT_MSVC_CRT "Avoid dependence from MSVC CRT and use ntdll.dll instead" OFF)
|
add_mdbx_option(MDBX_WITHOUT_MSVC_CRT "Avoid dependence from MSVC CRT and use ntdll.dll instead" OFF)
|
||||||
endif()
|
endif()
|
||||||
add_mdbx_option(MDBX_CONFIG_MANUAL_TLS_CALLBACK
|
|
||||||
"Provide mdbx_dll_handler() for manual initialization" OFF)
|
|
||||||
mark_as_advanced(MDBX_CONFIG_MANUAL_TLS_CALLBACK)
|
|
||||||
else()
|
else()
|
||||||
add_mdbx_option(MDBX_USE_OFDLOCKS "Use Open file description locks (aka OFD locks, non-POSIX)" AUTO)
|
add_mdbx_option(MDBX_USE_OFDLOCKS "Use Open file description locks (aka OFD locks, non-POSIX)" AUTO)
|
||||||
mark_as_advanced(MDBX_USE_OFDLOCKS)
|
mark_as_advanced(MDBX_USE_OFDLOCKS)
|
||||||
|
53
mdbx.h
53
mdbx.h
@ -587,9 +587,7 @@ extern LIBMDBX_VERINFO_API const struct MDBX_build_info {
|
|||||||
const char *flags; /**< CFLAGS and CXXFLAGS */
|
const char *flags; /**< CFLAGS and CXXFLAGS */
|
||||||
} /** \brief libmdbx build information */ mdbx_build;
|
} /** \brief libmdbx build information */ mdbx_build;
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if (defined(_WIN32) || defined(_WIN64)) && !MDBX_BUILD_SHARED_LIBRARY
|
||||||
#if !MDBX_BUILD_SHARED_LIBRARY
|
|
||||||
|
|
||||||
/* MDBX internally uses global and thread local storage destructors to
|
/* MDBX internally uses global and thread local storage destructors to
|
||||||
* automatically (de)initialization, releasing reader lock table slots
|
* automatically (de)initialization, releasing reader lock table slots
|
||||||
* and so on.
|
* and so on.
|
||||||
@ -600,44 +598,41 @@ extern LIBMDBX_VERINFO_API const struct MDBX_build_info {
|
|||||||
*
|
*
|
||||||
* Otherwise, if MDBX was builded not as a DLL, some black magic
|
* Otherwise, if MDBX was builded not as a DLL, some black magic
|
||||||
* may be required depending of Windows version:
|
* may be required depending of Windows version:
|
||||||
|
*
|
||||||
* - Modern Windows versions, including Windows Vista and later, provides
|
* - Modern Windows versions, including Windows Vista and later, provides
|
||||||
* support for "TLS Directory" (e.g .CRT$XL[A-Z] sections in executable
|
* support for "TLS Directory" (e.g .CRT$XL[A-Z] sections in executable
|
||||||
* or dll file). In this case, MDBX capable of doing all automatically,
|
* or dll file). In this case, MDBX capable of doing all automatically,
|
||||||
* and you do not need to call mdbx_dll_handler().
|
* therefore you DON'T NEED to call mdbx_module_handler()
|
||||||
|
* so the MDBX_MANUAL_MODULE_HANDLER defined as 0.
|
||||||
|
*
|
||||||
* - Obsolete versions of Windows, prior to Windows Vista, REQUIRES calling
|
* - Obsolete versions of Windows, prior to Windows Vista, REQUIRES calling
|
||||||
* mdbx_dll_handler() manually from corresponding DllMain() or WinMain()
|
* mdbx_module_handler() manually from corresponding DllMain() or WinMain()
|
||||||
* of your DLL or application.
|
* of your DLL or application,
|
||||||
* - This behavior is under control of the MODX_CONFIG_MANUAL_TLS_CALLBACK
|
* so the MDBX_MANUAL_MODULE_HANDLER defined as 1.
|
||||||
* option, which is determined by default according to the target version
|
|
||||||
* of Windows at build time.
|
|
||||||
* But you may override MODX_CONFIG_MANUAL_TLS_CALLBACK in special cases.
|
|
||||||
*
|
*
|
||||||
* Therefore, building MDBX as a DLL is recommended for all version of Windows.
|
* Therefore, building MDBX as a DLL is recommended for all version of Windows.
|
||||||
* So, if you doubt, just build MDBX as the separate DLL and don't worry. */
|
* So, if you doubt, just build MDBX as the separate DLL and don't care about
|
||||||
|
* the MDBX_MANUAL_MODULE_HANDLER. */
|
||||||
|
|
||||||
#ifndef MDBX_CONFIG_MANUAL_TLS_CALLBACK
|
|
||||||
#ifndef _WIN32_WINNT
|
#ifndef _WIN32_WINNT
|
||||||
#error Non-dll build libmdbx requires target Windows version \
|
#error Non-dll build libmdbx requires target Windows version \
|
||||||
to be explicitly defined via _WIN32_WINNT for properly \
|
to be explicitly defined via _WIN32_WINNT for properly \
|
||||||
handling thread local storage destructors.
|
handling thread local storage destructors.
|
||||||
#endif
|
#endif /* _WIN32_WINNT */
|
||||||
#if _WIN32_WINNT >= 0x0600 /* Windows Vista */
|
|
||||||
/* As described above mdbx_dll_handler() is NOT needed forWindows Vista
|
|
||||||
* and later. */
|
|
||||||
#define MDBX_CONFIG_MANUAL_TLS_CALLBACK 0
|
|
||||||
#else
|
|
||||||
/* As described above mdbx_dll_handler() IS REQUIRED for Windows versions
|
|
||||||
* prior to Windows Vista. */
|
|
||||||
#define MDBX_CONFIG_MANUAL_TLS_CALLBACK 1
|
|
||||||
#endif
|
|
||||||
#endif /* MDBX_CONFIG_MANUAL_TLS_CALLBACK */
|
|
||||||
|
|
||||||
#if MDBX_CONFIG_MANUAL_TLS_CALLBACK
|
#if _WIN32_WINNT >= 0x0600 /* Windows Vista */
|
||||||
void LIBMDBX_API NTAPI mdbx_dll_handler(PVOID module, DWORD reason,
|
/* As described above mdbx_module_handler() is NOT needed for Windows Vista
|
||||||
PVOID reserved);
|
* and later. */
|
||||||
#endif /* MDBX_CONFIG_MANUAL_TLS_CALLBACK */
|
#define MDBX_MANUAL_MODULE_HANDLER 0
|
||||||
#endif /* !MDBX_BUILD_SHARED_LIBRARY */
|
#else
|
||||||
#endif /* Windows */
|
/* As described above mdbx_module_handler() IS REQUIRED for Windows versions
|
||||||
|
* prior to Windows Vista. */
|
||||||
|
#define MDBX_MANUAL_MODULE_HANDLER 1
|
||||||
|
void LIBMDBX_API NTAPI mdbx_module_handler(PVOID module, DWORD reason,
|
||||||
|
PVOID reserved);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* Windows && !DLL && MDBX_MANUAL_MODULE_HANDLER */
|
||||||
|
|
||||||
/* OPACITY STRUCTURES *********************************************************/
|
/* OPACITY STRUCTURES *********************************************************/
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
#cmakedefine01 MDBX_DISABLE_PAGECHECKS
|
#cmakedefine01 MDBX_DISABLE_PAGECHECKS
|
||||||
|
|
||||||
/* Windows */
|
/* Windows */
|
||||||
#cmakedefine01 MDBX_CONFIG_MANUAL_TLS_CALLBACK
|
|
||||||
#cmakedefine01 MDBX_WITHOUT_MSVC_CRT
|
#cmakedefine01 MDBX_WITHOUT_MSVC_CRT
|
||||||
|
|
||||||
/* MacOS & iOS */
|
/* MacOS & iOS */
|
||||||
|
@ -22068,8 +22068,10 @@ __dll_export
|
|||||||
#endif /* MacOS */
|
#endif /* MacOS */
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
" MDBX_WITHOUT_MSVC_CRT=" STRINGIFY(MDBX_AVOID_CRT)
|
" MDBX_WITHOUT_MSVC_CRT=" STRINGIFY(MDBX_AVOID_CRT)
|
||||||
" MDBX_CONFIG_MANUAL_TLS_CALLBACK=" STRINGIFY(MDBX_CONFIG_MANUAL_TLS_CALLBACK)
|
|
||||||
" MDBX_BUILD_SHARED_LIBRARY=" STRINGIFY(MDBX_BUILD_SHARED_LIBRARY)
|
" MDBX_BUILD_SHARED_LIBRARY=" STRINGIFY(MDBX_BUILD_SHARED_LIBRARY)
|
||||||
|
#if !MDBX_BUILD_SHARED_LIBRARY
|
||||||
|
" MDBX_MANUAL_MODULE_HANDLER=" STRINGIFY(MDBX_MANUAL_MODULE_HANDLER)
|
||||||
|
#endif
|
||||||
" WINVER=" STRINGIFY(WINVER)
|
" WINVER=" STRINGIFY(WINVER)
|
||||||
#else /* Windows */
|
#else /* Windows */
|
||||||
" MDBX_LOCKING=" MDBX_LOCKING_CONFIG
|
" MDBX_LOCKING=" MDBX_LOCKING_CONFIG
|
||||||
|
@ -37,11 +37,11 @@ static void mdbx_winnt_import(void);
|
|||||||
|
|
||||||
BOOL APIENTRY DllMain(HANDLE module, DWORD reason, LPVOID reserved)
|
BOOL APIENTRY DllMain(HANDLE module, DWORD reason, LPVOID reserved)
|
||||||
#else
|
#else
|
||||||
#if !MDBX_CONFIG_MANUAL_TLS_CALLBACK
|
#if !MDBX_MANUAL_MODULE_HANDLER
|
||||||
static
|
static
|
||||||
#endif /* !MDBX_CONFIG_MANUAL_TLS_CALLBACK */
|
#endif /* !MDBX_MANUAL_MODULE_HANDLER */
|
||||||
void NTAPI
|
void NTAPI
|
||||||
mdbx_dll_handler(PVOID module, DWORD reason, PVOID reserved)
|
mdbx_module_handler(PVOID module, DWORD reason, PVOID reserved)
|
||||||
#endif /* MDBX_BUILD_SHARED_LIBRARY */
|
#endif /* MDBX_BUILD_SHARED_LIBRARY */
|
||||||
{
|
{
|
||||||
(void)reserved;
|
(void)reserved;
|
||||||
@ -65,7 +65,7 @@ static
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !MDBX_BUILD_SHARED_LIBRARY && !MDBX_CONFIG_MANUAL_TLS_CALLBACK
|
#if !MDBX_BUILD_SHARED_LIBRARY && !MDBX_MANUAL_MODULE_HANDLER
|
||||||
/* *INDENT-OFF* */
|
/* *INDENT-OFF* */
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
@ -89,7 +89,7 @@ static
|
|||||||
# pragma data_seg(".CRT$XLB")
|
# pragma data_seg(".CRT$XLB")
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
__declspec(allocate(".CRT$XLB")) PIMAGE_TLS_CALLBACK mdbx_tls_anchor = mdbx_dll_handler;
|
__declspec(allocate(".CRT$XLB")) PIMAGE_TLS_CALLBACK mdbx_tls_anchor = mdbx_module_handler;
|
||||||
# pragma data_seg(pop)
|
# pragma data_seg(pop)
|
||||||
# pragma const_seg(pop)
|
# pragma const_seg(pop)
|
||||||
|
|
||||||
@ -97,13 +97,13 @@ static
|
|||||||
# ifdef _WIN64
|
# ifdef _WIN64
|
||||||
const
|
const
|
||||||
# endif
|
# endif
|
||||||
PIMAGE_TLS_CALLBACK mdbx_tls_anchor __attribute__((__section__(".CRT$XLB"), used)) = mdbx_dll_handler;
|
PIMAGE_TLS_CALLBACK mdbx_tls_anchor __attribute__((__section__(".CRT$XLB"), used)) = mdbx_module_handler;
|
||||||
#else
|
#else
|
||||||
# error FIXME
|
# error FIXME
|
||||||
#endif
|
#endif
|
||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
#endif /* !MDBX_BUILD_SHARED_LIBRARY && !MDBX_CONFIG_MANUAL_TLS_CALLBACK */
|
#endif /* !MDBX_BUILD_SHARED_LIBRARY && !MDBX_MANUAL_MODULE_HANDLER */
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user