Commit 7c6037ce authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Windows : CloseHandle() returned by CreateThread().

Don't wait until os_thread_exit to close it.
Remove code from innodb_shutdown to close handles on Windows.
parent bc526a55
...@@ -42,7 +42,7 @@ can wait inside InnoDB */ ...@@ -42,7 +42,7 @@ can wait inside InnoDB */
#define OS_THREAD_PRIORITY_ABOVE_NORMAL 3 #define OS_THREAD_PRIORITY_ABOVE_NORMAL 3
#ifdef _WIN32 #ifdef _WIN32
typedef void* os_thread_t; typedef DWORD os_thread_t;
typedef DWORD os_thread_id_t; /*!< In Windows the thread id typedef DWORD os_thread_id_t; /*!< In Windows the thread id
is an unsigned long int */ is an unsigned long int */
extern "C" { extern "C" {
......
...@@ -45,16 +45,6 @@ SysMutex thread_mutex; ...@@ -45,16 +45,6 @@ SysMutex thread_mutex;
/** Number of threads active. */ /** Number of threads active. */
ulint os_thread_count; ulint os_thread_count;
#ifdef _WIN32
typedef std::map<
DWORD,
HANDLE,
std::less<DWORD>,
ut_allocator<std::pair<const DWORD, HANDLE> > > WinThreadMap;
/** This STL map remembers the initial handle returned by CreateThread
so that it can be closed when the thread exits. */
static WinThreadMap win_thread_map;
#endif /* _WIN32 */
/***************************************************************//** /***************************************************************//**
Compares two thread ids for equality. Compares two thread ids for equality.
...@@ -145,22 +135,15 @@ os_thread_create_func( ...@@ -145,22 +135,15 @@ os_thread_create_func(
ib::fatal() << "CreateThread returned " << GetLastError(); ib::fatal() << "CreateThread returned " << GetLastError();
} }
mutex_enter(&thread_mutex); CloseHandle(handle);
std::pair<WinThreadMap::iterator, bool> ret;
ret = win_thread_map.insert(
std::pair<DWORD, HANDLE>(new_thread_id, handle));
ut_ad((*ret.first).first == new_thread_id); mutex_enter(&thread_mutex);
ut_ad((*ret.first).second == handle);
ut_a(ret.second == true); /* true means thread_id was new */
os_thread_count++; os_thread_count++;
mutex_exit(&thread_mutex); mutex_exit(&thread_mutex);
return((os_thread_t)handle); return((os_thread_t)new_thread_id);
#else /* _WIN32 else */ #else /* _WIN32 else */
pthread_attr_t attr; pthread_attr_t attr;
...@@ -208,12 +191,6 @@ os_thread_exit() ...@@ -208,12 +191,6 @@ os_thread_exit()
os_thread_count--; os_thread_count--;
#ifdef _WIN32 #ifdef _WIN32
DWORD win_thread_id = GetCurrentThreadId();
HANDLE handle = win_thread_map[win_thread_id];
CloseHandle(handle);
size_t ret = win_thread_map.erase(win_thread_id);
ut_a(ret == 1);
mutex_exit(&thread_mutex); mutex_exit(&thread_mutex);
ExitThread(0); ExitThread(0);
......
...@@ -2857,34 +2857,6 @@ innobase_shutdown_for_mysql(void) ...@@ -2857,34 +2857,6 @@ innobase_shutdown_for_mysql(void)
/* Cleanup data for datafile scrubbing */ /* Cleanup data for datafile scrubbing */
btr_scrub_cleanup(); btr_scrub_cleanup();
#ifdef __WIN__
/* MDEV-361: ha_innodb.dll leaks handles on Windows
MDEV-7403: should not pass recv_writer_thread_handle to
CloseHandle().
On Windows we should call CloseHandle() for all
open thread handles. */
if (os_thread_count == 0) {
for (int i = 0; i < SRV_MAX_N_IO_THREADS + 6 + 32; ++i) {
if (thread_started[i]) {
CloseHandle(thread_handles[i]);
}
}
if (buf_flush_page_cleaner_thread_started) {
CloseHandle(buf_flush_page_cleaner_thread_handle);
}
if (buf_dump_thread_started) {
CloseHandle(buf_dump_thread_handle);
}
if (dict_stats_thread_started) {
CloseHandle(dict_stats_thread_handle);
}
}
#endif /* __WIN __ */
/* This must be disabled before closing the buffer pool /* This must be disabled before closing the buffer pool
and closing the data dictionary. */ and closing the data dictionary. */
btr_search_disable(true); btr_search_disable(true);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment