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

Make CoreIO thread-safer #21893

Merged
merged 1 commit into from
May 16, 2017
Merged
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
17 changes: 14 additions & 3 deletions src/jl_uv.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ JL_DLLEXPORT int jl_fs_write(int handle, const char *data, size_t len,
int64_t offset)
{
jl_ptls_t ptls = jl_get_ptls_states();
if (ptls->safe_restore)
if (ptls->safe_restore || ptls->tid != 0)
return write(handle, data, len);
uv_fs_t req;
uv_buf_t buf[1];
Expand Down Expand Up @@ -432,7 +432,7 @@ JL_DLLEXPORT void jl_uv_puts(uv_stream_t *stream, const char *str, size_t n)
sizeof(((uv_stream_t*)0)->type) == sizeof(((ios_t*)0)->bm),
"UV and ios layout mismatch");

uv_file fd = 0;
uv_file fd = -1;

// Fallback for output during early initialisation...
if (stream == (void*)STDOUT_FILENO || stream == (void*)STDERR_FILENO) {
Expand All @@ -443,7 +443,18 @@ JL_DLLEXPORT void jl_uv_puts(uv_stream_t *stream, const char *str, size_t n)
fd = ((jl_uv_file_t*)stream)->file;
}

if (fd) {
// Hack to make CoreIO thread-safer
jl_ptls_t ptls = jl_get_ptls_states();
if (ptls->tid != 0) {
if (stream == JL_STDOUT) {
fd = STDOUT_FILENO;
}
else if (stream == JL_STDERR) {
fd = STDERR_FILENO;
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewrite to test for fd == -1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.... In case we have anyone that somehow closed the STDIN I guess?

if (fd != -1) {
// Write to file descriptor...
jl_fs_write(fd, str, n, -1);
}
Expand Down