Skip to content

Commit

Permalink
Windows : CloseHandle() returned by CreateThread().
Browse files Browse the repository at this point in the history
Don't wait until os_thread_exit to close it.
Remove code from innodb_shutdown to close handles on Windows.
  • Loading branch information
vaintroub committed Sep 13, 2016
1 parent bc526a5 commit 7c6037c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 55 deletions.
2 changes: 1 addition & 1 deletion storage/innobase/include/os0thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ can wait inside InnoDB */
#define OS_THREAD_PRIORITY_ABOVE_NORMAL 3

#ifdef _WIN32
typedef void* os_thread_t;
typedef DWORD os_thread_t;
typedef DWORD os_thread_id_t; /*!< In Windows the thread id
is an unsigned long int */
extern "C" {
Expand Down
29 changes: 3 additions & 26 deletions storage/innobase/os/os0thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ SysMutex thread_mutex;
/** Number of threads active. */
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.
Expand Down Expand Up @@ -145,22 +135,15 @@ os_thread_create_func(
ib::fatal() << "CreateThread returned " << GetLastError();
}

mutex_enter(&thread_mutex);

std::pair<WinThreadMap::iterator, bool> ret;

ret = win_thread_map.insert(
std::pair<DWORD, HANDLE>(new_thread_id, handle));
CloseHandle(handle);

ut_ad((*ret.first).first == new_thread_id);
ut_ad((*ret.first).second == handle);
ut_a(ret.second == true); /* true means thread_id was new */
mutex_enter(&thread_mutex);

os_thread_count++;

mutex_exit(&thread_mutex);

return((os_thread_t)handle);
return((os_thread_t)new_thread_id);
#else /* _WIN32 else */

pthread_attr_t attr;
Expand Down Expand Up @@ -208,12 +191,6 @@ os_thread_exit()
os_thread_count--;

#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);

ExitThread(0);
Expand Down
28 changes: 0 additions & 28 deletions storage/innobase/srv/srv0start.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2857,34 +2857,6 @@ innobase_shutdown_for_mysql(void)
/* Cleanup data for datafile scrubbing */
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
and closing the data dictionary. */
btr_search_disable(true);
Expand Down

0 comments on commit 7c6037c

Please sign in to comment.