Skip to content

Commit

Permalink
small fixes to libuv locks
Browse files Browse the repository at this point in the history
- use normal locking instead of nogc
- remove locks before threads have started
  • Loading branch information
JeffBezanson committed Mar 25, 2019
1 parent ad40952 commit 79bc26e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
8 changes: 0 additions & 8 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,31 +410,23 @@ static void *init_stdio_handle(const char *stdio, uv_os_fd_t fd, int readable)
break;
case UV_NAMED_PIPE:
handle = malloc(sizeof(uv_pipe_t));
JL_UV_LOCK();
if ((err = uv_pipe_init(jl_io_loop, (uv_pipe_t*)handle, 0))) {
// JL_UV_UNLOCK() equivalent is done during unwinding
jl_errorf("error initializing %s in uv_pipe_init: %s (%s %d)", stdio, uv_strerror(err), uv_err_name(err), err);
}
if ((err = uv_pipe_open((uv_pipe_t*)handle, fd))) {
// JL_UV_UNLOCK() equivalent is done during unwinding
jl_errorf("error initializing %s in uv_pipe_open: %s (%s %d)", stdio, uv_strerror(err), uv_err_name(err), err);
}
((uv_pipe_t*)handle)->data = NULL;
JL_UV_UNLOCK();
break;
case UV_TCP:
handle = malloc(sizeof(uv_tcp_t));
JL_UV_LOCK();
if ((err = uv_tcp_init(jl_io_loop, (uv_tcp_t*)handle))) {
// JL_UV_UNLOCK() equivalent is done during unwinding
jl_errorf("error initializing %s in uv_tcp_init: %s (%s %d)", stdio, uv_strerror(err), uv_err_name(err), err);
}
if ((err = uv_tcp_open((uv_tcp_t*)handle, (uv_os_sock_t)fd))) {
// JL_UV_UNLOCK() equivalent is done during unwinding
jl_errorf("error initializing %s in uv_tcp_open: %s (%s %d)", stdio, uv_strerror(err), uv_err_name(err), err);
}
((uv_tcp_t*)handle)->data = NULL;
JL_UV_UNLOCK();
break;
}
return handle;
Expand Down
6 changes: 3 additions & 3 deletions src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,13 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
break;
case 'v': // version
jl_printf(JL_STDOUT, "julia version %s\n", JULIA_VERSION_STRING);
jl_exit(0);
exit(0);
case 'h': // help
jl_printf(JL_STDOUT, "%s%s", usage, opts);
jl_exit(0);
exit(0);
case opt_help_hidden:
jl_printf(JL_STDOUT, "%s%s", usage, opts_hidden);
jl_exit(0);
exit(0);
case 'g': // debug info
if (optarg != NULL) {
if (!strcmp(optarg,"0"))
Expand Down
4 changes: 2 additions & 2 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ static inline void jl_assume_(int cond)
static uv_loop_t *const unused_uv_loop_arg = (uv_loop_t *)0xBAD10;

extern jl_mutex_t jl_uv_mutex;
#define JL_UV_LOCK() JL_LOCK_NOGC(&jl_uv_mutex)
#define JL_UV_UNLOCK() JL_UNLOCK_NOGC(&jl_uv_mutex)
#define JL_UV_LOCK() JL_LOCK(&jl_uv_mutex)
#define JL_UV_UNLOCK() JL_UNLOCK(&jl_uv_mutex)

#ifdef __cplusplus
extern "C" {
Expand Down
12 changes: 12 additions & 0 deletions src/locks.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ static inline int jl_mutex_trylock_nogc(jl_mutex_t *lock)
return 0;
}

static inline int jl_mutex_trylock(jl_mutex_t *lock)
{
int got = jl_mutex_trylock_nogc(lock);
if (got) {
jl_ptls_t ptls = jl_get_ptls_states();
JL_SIGATOMIC_BEGIN();
jl_lock_frame_push(lock);
jl_gc_enable_finalizers(ptls, 0);
}
return got;
}

/* Call this function for code that could be called from either a managed
or an unmanaged thread */
static inline void jl_mutex_lock_maybe_nogc(jl_mutex_t *lock)
Expand Down

0 comments on commit 79bc26e

Please sign in to comment.