Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows support to abort blocking system calls. (#12654) #1131

Merged
merged 1 commit into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 29 additions & 32 deletions mono/metadata/w32file-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,49 +92,46 @@ cancel_w32_io (HANDLE file_handle)
gboolean
mono_w32file_read (gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread)
{
gboolean res = FALSE;

gboolean interrupted;
guint32 last_error;
gboolean res;

MonoThreadInfo *info = mono_thread_info_current ();

mono_win32_enter_blocking_io_call (info, (HANDLE)handle);
MONO_ENTER_GC_SAFE;
res = ReadFile ((HANDLE)handle, buffer, numbytes, (PDWORD)bytesread, NULL);
/* need to save and restore since clients expect error code set for
* failed IO calls and mono_thread_info_uninstall_interrupt overwrites value */
last_error = mono_w32error_get_last ();

MONO_EXIT_GC_SAFE;
mono_win32_leave_blocking_io_call (info, (HANDLE)handle);
mono_w32error_set_last (last_error);

mono_thread_info_install_interrupt (cancel_w32_io, handle, &interrupted);
if (!interrupted)
{
guint32 last_error;
MONO_ENTER_GC_SAFE;
res = ReadFile (handle, buffer, numbytes, bytesread, NULL);
MONO_PROFILER_RAISE (fileio, (1, *bytesread));
MONO_EXIT_GC_SAFE;

/* need to save and restore since clients expect error code set for
* failed IO calls and mono_thread_info_uninstall_interrupt overwrites value */
last_error = mono_w32error_get_last ();
mono_thread_info_uninstall_interrupt (&interrupted);
mono_w32error_set_last (last_error);
}

return res;
}

gboolean
mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten)
{
gboolean res = FALSE;
gboolean interrupted;
guint32 last_error;
gboolean res;

MonoThreadInfo *info = mono_thread_info_current ();

mono_thread_info_install_interrupt (cancel_w32_io, handle, &interrupted);
if (!interrupted)
{
guint32 last_error;
MONO_ENTER_GC_SAFE;
res = WriteFile (handle, buffer, numbytes, byteswritten, NULL);
MONO_PROFILER_RAISE (fileio, (0, *byteswritten));
MONO_EXIT_GC_SAFE;

/* need to save and restore since clients expect error code set for
* failed IO calls and mono_thread_info_uninstall_interrupt overwrites value */
last_error = mono_w32error_get_last ();
mono_thread_info_uninstall_interrupt (&interrupted);
mono_w32error_set_last (last_error);
}
mono_win32_enter_blocking_io_call (info, (HANDLE)handle);
MONO_ENTER_GC_SAFE;
res = WriteFile ((HANDLE)handle, buffer, numbytes, (PDWORD)byteswritten, NULL);
/* need to save and restore since clients expect error code set for
* failed IO calls and mono_thread_info_uninstall_interrupt overwrites value */
last_error = mono_w32error_get_last ();
MONO_EXIT_GC_SAFE;
mono_win32_leave_blocking_io_call (info, (HANDLE)handle);
mono_w32error_set_last (last_error);

return res;
}
Expand Down
Loading