Esempio n. 1
0
/**
 * Creates a thread structure for the specified thread id
 *
 * @param tid the tid
 *
 * @return the created thread structure or NULL if it could not be created
 */
static
thread *create_thread(uint64_t tid) {

    thread *new_thr = create_thread_struct(tid);
    if (new_thr == NULL) {
        return NULL;
    }

    link_thread(new_thr);

    return new_thr;
}
Esempio n. 2
0
/* Note: scribble must be stack-allocated */
static void
init_new_thread(struct thread *th, init_thread_data *scribble, int guardp)
{
    int lock_ret;

    pthread_setspecific(lisp_thread, (void *)1);
    if(arch_os_thread_init(th)==0) {
        /* FIXME: handle error */
        lose("arch_os_thread_init failed\n");
    }

    th->os_thread=thread_self();
    if (guardp)
        protect_control_stack_guard_page(1, NULL);
    protect_binding_stack_guard_page(1, NULL);
    protect_alien_stack_guard_page(1, NULL);
    /* Since GC can only know about this thread from the all_threads
     * list and we're just adding this thread to it, there is no
     * danger of deadlocking even with SIG_STOP_FOR_GC blocked (which
     * it is not). */
#ifdef LISP_FEATURE_SB_SAFEPOINT
    *th->csp_around_foreign_call = (lispobj)scribble;
#endif
    lock_ret = pthread_mutex_lock(&all_threads_lock);
    gc_assert(lock_ret == 0);
    link_thread(th);
    lock_ret = pthread_mutex_unlock(&all_threads_lock);
    gc_assert(lock_ret == 0);

    /* Kludge: Changed the order of some steps between the safepoint/
     * non-safepoint versions of this code.  Can we unify this more?
     */
#ifdef LISP_FEATURE_SB_SAFEPOINT
    gc_state_lock();
    gc_state_wait(GC_NONE);
    gc_state_unlock();
    push_gcing_safety(&scribble->safety);
#endif
}
Esempio n. 3
0
File: thread.c Progetto: slyrus/sbcl
static int
initial_thread_trampoline(struct thread *th)
{
    lispobj function;
#if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
    lispobj *args = NULL;
#endif
#ifdef LISP_FEATURE_SB_THREAD
    pthread_setspecific(lisp_thread, (void *)1);
#endif
#if defined(THREADS_USING_GCSIGNAL) && (defined(LISP_FEATURE_PPC) || defined(LISP_FEATURE_ARM64))
    /* SIG_STOP_FOR_GC defaults to blocked on PPC? */
    unblock_gc_signals(0,0);
#endif
    function = th->no_tls_value_marker;
    th->no_tls_value_marker = NO_TLS_VALUE_MARKER_WIDETAG;
    if(arch_os_thread_init(th)==0) return 1;
    link_thread(th);
    th->os_thread=thread_self();
#ifndef LISP_FEATURE_WIN32
    protect_control_stack_hard_guard_page(1, NULL);
#endif
    protect_binding_stack_hard_guard_page(1, NULL);
    protect_alien_stack_hard_guard_page(1, NULL);
#ifndef LISP_FEATURE_WIN32
    protect_control_stack_guard_page(1, NULL);
#endif
    protect_binding_stack_guard_page(1, NULL);
    protect_alien_stack_guard_page(1, NULL);

    /* WIN32 has a special stack arrangment, calling
     * call_into_lisp_first_time will put the new stack in the middle
     * of the current stack */
#if !defined(LISP_FEATURE_WIN32) && (defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64))
    return call_into_lisp_first_time(function,args,0);
#else
    return funcall0(function);
#endif
}