Skip to content

Commit

Permalink
Allow the tls state to be overrided (to a faster one)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed Nov 22, 2015
1 parent 0ee77f9 commit ba275d0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,9 @@ DLLEXPORT JL_CONST_FUNC jl_tls_states_t *(jl_get_ptls_states)(void);
#ifndef JULIA_ENABLE_THREADING
extern DLLEXPORT jl_tls_states_t jl_tls_states;
#define jl_get_ptls_states() (&jl_tls_states)
#else
typedef jl_tls_states_t *(*jl_get_ptls_states_func)(void);
DLLEXPORT void jl_set_ptls_states_getter(jl_get_ptls_states_func f);
#endif

STATIC_INLINE void jl_eh_restore_state(jl_handler_t *eh)
Expand Down
27 changes: 20 additions & 7 deletions src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,35 @@ extern "C" {
#include "threading.h"

#ifdef JULIA_ENABLE_THREADING
// fallback provided for embedding
static JL_CONST_FUNC jl_tls_states_t *jl_get_ptls_states_fallback(void)
{
# if !defined(_COMPILER_MICROSOFT_)
// Definition for compiling Julia on platforms with GCC __thread.
# define JL_THREAD __thread
static __thread jl_tls_states_t tls_states;
# else
// Definition for compiling Julia on Windows
# define JL_THREAD __declspec(thread)
static __declspec(thread) jl_tls_states_t tls_states;
# endif
JL_THREAD jl_tls_states_t jl_tls_states;
return &tls_states;
}
static jl_get_ptls_states_func jl_tls_states_cb = jl_get_ptls_states_fallback;
DLLEXPORT JL_CONST_FUNC jl_tls_states_t *(jl_get_ptls_states)(void)
{
return (*jl_tls_states_cb)();
}
DLLEXPORT void jl_set_ptls_states_getter(jl_get_ptls_states_func f)
{
// only allow setting this once
if (f && jl_tls_states_cb == jl_get_ptls_states_fallback) {
jl_tls_states_cb = f;
}
}
#else
DLLEXPORT jl_tls_states_t jl_tls_states;
#endif

DLLEXPORT JL_CONST_FUNC jl_tls_states_t *(jl_get_ptls_states)(void)
{
return &jl_tls_states;
}
#endif

// thread ID
DLLEXPORT int jl_n_threads; // # threads we're actually using
Expand Down
15 changes: 15 additions & 0 deletions ui/repl.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@
extern "C" {
#endif

#ifdef JULIA_ENABLE_THREADING
static JL_CONST_FUNC jl_tls_states_t *jl_get_ptls_states_static(void)
{
# if !defined(_COMPILER_MICROSOFT_)
static __thread jl_tls_states_t tls_states;
# else
static __declspec(thread) jl_tls_states_t tls_states;
# endif
return &tls_states;
}
#endif

static int lisp_prompt = 0;
static int codecov = JL_LOG_NONE;
static int malloclog= JL_LOG_NONE;
Expand Down Expand Up @@ -551,6 +563,9 @@ static int true_main(int argc, char *argv[])
#ifndef _OS_WINDOWS_
int main(int argc, char *argv[])
{
#ifdef JULIA_ENABLE_THREADING
jl_set_ptls_states_getter(jl_get_ptls_states_static);
#endif
uv_setup_args(argc, argv); // no-op on Windows
#else
static void lock_low32() {
Expand Down

0 comments on commit ba275d0

Please sign in to comment.