Skip to content

Commit

Permalink
fix init location of thread(0), for single-threaded profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Oct 30, 2015
1 parent 6fdc9b9 commit 905310d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
31 changes: 18 additions & 13 deletions src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ DLLEXPORT int16_t jl_threadid() { return ti_tid; }
struct _jl_thread_heap_t *jl_mk_thread_heap(void);
// must be called by each thread at startup

void ti_initthread(int16_t tid)
static void ti_initthread(int16_t tid)
{
ti_tid = tid;
jl_pgcstack = NULL;
Expand All @@ -67,6 +67,21 @@ void ti_initthread(int16_t tid)
jl_all_task_states[tid].pbt_size = &bt_size;
}

static void ti_init_master_thread()
{
#ifdef _OS_WINDOWS_
if (!DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
GetCurrentProcess(), &jl_all_task_states[0].system_id, 0,
TRUE, DUPLICATE_SAME_ACCESS)) {
jl_printf(JL_STDERR, "WARNING: failed to access handle to main thread\n");
jl_all_task_states[0].system_id = INVALID_HANDLE_VALUE;
}
#else
jl_all_task_states[0].system_id = pthread_self();
#endif
ti_initthread(0);
}

// all threads call this function to run user code
static jl_value_t *ti_run_fun(jl_function_t *f, jl_svec_t *args)
{
Expand Down Expand Up @@ -241,7 +256,7 @@ void jl_init_threading(void)
#endif

// initialize this master thread (set tid, create heap, etc.)
ti_initthread(0);
ti_init_master_thread();
}

void jl_start_threads(void)
Expand All @@ -264,16 +279,6 @@ void jl_start_threads(void)
ti_threadsetaffinity(uv_thread_self(), 0);

// create threads
#ifdef _OS_WINDOWS_
if (!DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
GetCurrentProcess(), &jl_all_task_states[0].system_id, 0,
TRUE, DUPLICATE_SAME_ACCESS)) {
jl_printf(JL_STDERR, "WARNING: failed to access handle to main thread\n");
jl_all_task_states[0].system_id = INVALID_HANDLE_VALUE;
}
#else
jl_all_task_states[0].system_id = pthread_self();
#endif
targs = malloc((jl_n_threads - 1) * sizeof (ti_threadarg_t *));

uv_barrier_init(&thread_init_done, jl_n_threads);
Expand Down Expand Up @@ -480,7 +485,7 @@ void jl_init_threading(void)
sig_stack_size = 1<<16;
#endif

ti_initthread(0);
ti_init_master_thread();
}

void jl_start_threads(void) { }
Expand Down
1 change: 0 additions & 1 deletion src/threading.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ void ti_threadsetaffinity(uint64_t thread_id, int proc_num);
void ti_threadfun(void *arg);

// helpers for thread function
void ti_initthread(int16_t tid);
jl_value_t *ti_runthread(jl_function_t *f, jl_svec_t *args, size_t nargs);

#ifdef __cplusplus
Expand Down

0 comments on commit 905310d

Please sign in to comment.