Skip to content

Commit

Permalink
Use JULIA_CB to cache isopen
Browse files Browse the repository at this point in the history
  • Loading branch information
rsofaer committed May 13, 2013
1 parent 2609de0 commit 4369e52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,8 @@ function isopen(stream::AsyncStream)
stream.open
end

_uv_hook_isopen(stream::AsyncStream) = int32(isopen(stream))

function close(stream::AsyncStream)
if stream.open
ccall(:jl_close_uv,Void,(Ptr{Void},),stream.handle)
Expand Down
9 changes: 7 additions & 2 deletions src/jl_uv.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extern "C" {
XX(getaddrinfo) \
XX(pollcb) \
XX(fspollcb) \
XX(isopen) \
XX(fseventscb)
//TODO add UDP and other missing callbacks

Expand All @@ -69,6 +70,7 @@ DLLEXPORT void jl_get_uv_hooks()
int base_module_conflict = 0; //set to 1 if Base is getting redefined since it means there are two place to try the callbacks
// warning: this is defined without the standard do {...} while (0) wrapper, since I wanted ret to escape
// warning: during bootstrapping, callbacks will be called twice if a MethodError occured at ANY time during callback call
// Use: JULIA_CB(hook, arg1, numberOfAdditionalArgs, arg2Type, arg2, ..., argNType, argN)
#define JULIA_CB(hook,args...) \
jl_value_t *ret; \
if (!base_module_conflict) { \
Expand Down Expand Up @@ -300,8 +302,11 @@ DLLEXPORT void jl_close_uv(uv_handle_t *handle)
if ( (handle->type == UV_NAMED_PIPE || handle->type == UV_TCP) && uv_is_writable( (uv_stream_t *) handle)) {
// Make sure that the stream has not already been marked closed in Julia.
// A double shutdown would cause the process to hang on exit.
jl_function_t* jl_is_open = (jl_function_t*) jl_get_global(jl_base_module, jl_symbol("isopen"));
if ( jl_apply(jl_is_open, (jl_value_t **) &(handle->data), 1) == jl_false ){
JULIA_CB(isopen, handle->data, 0);
if (!jl_is_int32(ret)) {
jl_error("jl_close_uv: _uv_hook_isopen must return an int32.");
}
if (!jl_unbox_int32(ret)){
return;
}

Expand Down

0 comments on commit 4369e52

Please sign in to comment.