Skip to content

Commit 17437eb

Browse files
committed
Threadpool - support changing group on Windows with generic thread pool
1 parent d8ea11a commit 17437eb

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

sql/threadpool_generic.cc

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,38 @@ static int io_poll_associate_fd(TP_file_handle pollfd, TP_file_handle fd, void *
394394
}
395395

396396

397+
typedef LONG NTSTATUS;
398+
399+
typedef struct _IO_STATUS_BLOCK {
400+
union {
401+
NTSTATUS Status;
402+
PVOID Pointer;
403+
};
404+
ULONG_PTR Information;
405+
} IO_STATUS_BLOCK, * PIO_STATUS_BLOCK;
406+
407+
struct FILE_COMPLETION_INFORMATION {
408+
HANDLE Port;
409+
PVOID Key;
410+
};
411+
412+
enum FILE_INFORMATION_CLASS {
413+
FileReplaceCompletionInformation = 0x3D
414+
};
415+
416+
417+
typedef NTSTATUS(WINAPI* pNtSetInformationFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FILE_INFORMATION_CLASS);
418+
397419
int io_poll_disassociate_fd(TP_file_handle pollfd, TP_file_handle fd)
398420
{
399-
/* Not possible to unbind/rebind file descriptor in IOCP. */
421+
static pNtSetInformationFile my_NtSetInformationFile = (pNtSetInformationFile)
422+
GetProcAddress(GetModuleHandle("ntdll"), "NtSetInformationFile");
423+
if (!my_NtSetInformationFile)
424+
return -1; /* unexpected, we only support Windows 8.1+*/
425+
IO_STATUS_BLOCK iosb{};
426+
FILE_COMPLETION_INFORMATION fci{};
427+
if (my_NtSetInformationFile(fd,&iosb,&fci,sizeof(fci),FileReplaceCompletionInformation))
428+
return -1;
400429
return 0;
401430
}
402431

@@ -1409,7 +1438,6 @@ void TP_connection_generic::set_io_timeout(int timeout_sec)
14091438
}
14101439

14111440

1412-
#ifndef HAVE_IOCP
14131441
/**
14141442
Handle a (rare) special case,where connection needs to
14151443
migrate to a different group because group_count has changed
@@ -1444,11 +1472,9 @@ static int change_group(TP_connection_generic *c,
14441472
mysql_mutex_unlock(&new_group->mutex);
14451473
return ret;
14461474
}
1447-
#endif
14481475

14491476
int TP_connection_generic::start_io()
14501477
{
1451-
#ifndef HAVE_IOCP
14521478
/*
14531479
Usually, connection will stay in the same group for the entire
14541480
connection's life. However, we do allow group_count to
@@ -1467,7 +1493,6 @@ int TP_connection_generic::start_io()
14671493
if (change_group(this, thread_group, group))
14681494
return -1;
14691495
}
1470-
#endif
14711496

14721497
/*
14731498
Bind to poll descriptor if not yet done.

0 commit comments

Comments
 (0)