pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:397:   MUTEX_T thread_table_lock;   static MUTEX_T interleave_lock;   static struct program *mutex_key = 0;   PMOD_EXPORT struct program *thread_id_prog = 0;   static struct program *thread_local_prog = 0;   PMOD_EXPORT ptrdiff_t thread_storage_offset;   static int live_threads = 0;   static COND_T live_threads_change;   static COND_T threads_disabled_change;    - struct thread_local + struct thread_local_var   {    INT32 id;   };      static volatile IMUTEX_T *interleave_list = NULL;      #define THREADSTATE2OBJ(X) ((X)->thread_obj)      #if defined(PIKE_DEBUG)   
pike.git/src/threads.c:1897:    assign_svalue(&thread_state->result, Pike_sp-1);    pop_stack();       thread_state->status = THREAD_EXITED;    }       UNSETJMP(back);       DEBUG_CHECK_THREAD();    -  if(thread_state->thread_local != NULL) { -  free_mapping(thread_state->thread_local); -  thread_state->thread_local = NULL; +  if(thread_state->thread_locals != NULL) { +  free_mapping(thread_state->thread_locals); +  thread_state->thread_locals = NULL;    }       co_broadcast(&thread_state->status_change);       THREADS_FPRINTF(0, (stderr,"new_thread_func(): Thread %p done\n",    arg.thread_state));       /* This thread is now officially dead. */       while(Pike_fp)
pike.git/src/threads.c:3020:   void init_thread_obj(struct object *UNUSED(o))   {    memset(&THIS_THREAD->state, 0, sizeof(struct Pike_interpreter_struct));    THIS_THREAD->thread_obj = Pike_fp->current_object;    THIS_THREAD->swapped = 0;    THIS_THREAD->status=THREAD_NOT_STARTED;    THIS_THREAD->flags = 0;    THIS_THREAD->waiting = 0;    SET_SVAL(THIS_THREAD->result, T_INT, NUMBER_UNDEFINED, integer, 0);    co_init(& THIS_THREAD->status_change); -  THIS_THREAD->thread_local=NULL; +  THIS_THREAD->thread_locals=NULL;   #ifdef CPU_TIME_MIGHT_BE_THREAD_LOCAL    THIS_THREAD->auto_gc_time = 0;   #endif   }      static void cleanup_thread_state (struct thread_state *th)   {   #ifdef PIKE_DEBUG    if (th->thread_obj) Pike_fatal ("Thread state still active.\n");   #endif
pike.git/src/threads.c:3055:    co_destroy(& THIS_THREAD->status_change);    th_destroy(& THIS_THREAD->id);   }      void exit_thread_obj(struct object *UNUSED(o))   {    THIS_THREAD->thread_obj = NULL;       cleanup_thread_state (THIS_THREAD);    -  if(THIS_THREAD->thread_local != NULL) { -  free_mapping(THIS_THREAD->thread_local); -  THIS_THREAD->thread_local = NULL; +  if(THIS_THREAD->thread_locals != NULL) { +  free_mapping(THIS_THREAD->thread_locals); +  THIS_THREAD->thread_locals = NULL;    }   }      /*! @endclass    */      static void thread_was_recursed(struct object *UNUSED(o))   {    struct thread_state *tmp=THIS_THREAD; -  if(tmp->thread_local != NULL) -  gc_recurse_mapping(tmp->thread_local); +  if(tmp->thread_locals != NULL) +  gc_recurse_mapping(tmp->thread_locals);   }      static void thread_was_checked(struct object *UNUSED(o))   {    struct thread_state *tmp=THIS_THREAD; -  if(tmp->thread_local != NULL) -  debug_gc_check (tmp->thread_local, +  if(tmp->thread_locals != NULL) +  debug_gc_check (tmp->thread_locals,    " as mapping for thread local values in thread");      #ifdef PIKE_DEBUG    if(tmp->swapped)    gc_mark_stack_external (tmp->state.frame_pointer, tmp->state.stack_pointer,    tmp->state.evaluator_stack);   #endif   }      /*! @class Local
pike.git/src/threads.c:3103:    *!    *! @note    *! This class is simulated when Pike is compiled without thread support,    *! so it's always available.    */      /* FIXME: Why not use an init callback()? */   void f_thread_local_create( INT32 args )   {    static INT32 thread_local_id = 0; -  ((struct thread_local *)CURRENT_STORAGE)->id = +  ((struct thread_local_var *)CURRENT_STORAGE)->id =    thread_local_id++;    pop_n_elems(args);    push_int(0);   }      PMOD_EXPORT void f_thread_local(INT32 args)   {    struct object *loc = clone_object(thread_local_prog,0);    pop_n_elems(args);    push_object(loc);
pike.git/src/threads.c:3131:    *! the @[set()] method by this thread.    *!    *! @seealso    *! @[set()]    */   void f_thread_local_get(INT32 args)   {    struct svalue key;    struct mapping *m;    SET_SVAL(key, T_INT, NUMBER_NUMBER, integer, -  ((struct thread_local *)CURRENT_STORAGE)->id); +  ((struct thread_local_var *)CURRENT_STORAGE)->id);    pop_n_elems(args);    if(Pike_interpreter.thread_state != NULL && -  (m = Pike_interpreter.thread_state->thread_local) != NULL) +  (m = Pike_interpreter.thread_state->thread_locals) != NULL)    mapping_index_no_free(Pike_sp++, m, &key);    else {    push_undefined();    }   }      /*! @decl mixed set(mixed value)    *!    *! Set the thread local value.    *!
pike.git/src/threads.c:3165:    *! Note that the value set can only be retreived by the same thread.    *!    *! @seealso    *! @[get()]    */   void f_thread_local_set(INT32 args)   {    struct svalue key;    struct mapping *m;    SET_SVAL(key, T_INT, NUMBER_NUMBER, integer, -  ((struct thread_local *)CURRENT_STORAGE)->id); +  ((struct thread_local_var *)CURRENT_STORAGE)->id);    if(args>1)    pop_n_elems(args-1);    else if(args<1)    SIMPLE_TOO_FEW_ARGS_ERROR("Thread.Local.set", 1);       if(Pike_interpreter.thread_state == NULL)    Pike_error("Trying to set Thread.Local without thread!\n");    -  if((m = Pike_interpreter.thread_state->thread_local) == NULL) -  m = Pike_interpreter.thread_state->thread_local = +  if((m = Pike_interpreter.thread_state->thread_locals) == NULL) +  m = Pike_interpreter.thread_state->thread_locals =    allocate_mapping(4);       mapping_insert(m, &key, &Pike_sp[-1]);   }      #ifdef PIKE_DEBUG   void gc_check_thread_local (struct object *UNUSED(o))   {    /* Only used by with locate_references. */    if (Pike_in_gc == GC_PASS_LOCATE) {    struct svalue key, *val;    struct thread_state *s;       SET_SVAL(key, T_INT, NUMBER_NUMBER, integer, -  ((struct thread_local *)CURRENT_STORAGE)->id); +  ((struct thread_local_var *)CURRENT_STORAGE)->id);       FOR_EACH_THREAD (s, { -  if (s->thread_local && -  (val = low_mapping_lookup(s->thread_local, &key))) +  if (s->thread_locals && +  (val = low_mapping_lookup(s->thread_locals, &key)))    debug_gc_check_svalues (val, 1,    " as thread local value in Thread.Local object"    " (indirect ref)");    });    }   }   #endif      /*! @endclass    */
pike.git/src/threads.c:3479:    set_exit_callback(exit_threads_disable);    tmp = Pike_compiler->new_program;    add_ref(tmp);    end_class("threads_disabled", 0);    tmp->flags|=PROGRAM_DESTRUCT_IMMEDIATE;    add_global_program("_disable_threads", tmp);    free_program(tmp);    }       START_NEW_PROGRAM_ID(THREAD_LOCAL); -  ADD_STORAGE(struct thread_local); +  ADD_STORAGE(struct thread_local_var);    ADD_FUNCTION("get",f_thread_local_get,tFunc(tNone,tMix),0);    ADD_FUNCTION("set",f_thread_local_set,tFunc(tSetvar(1,tMix),tVar(1)),0);    ADD_FUNCTION("create", f_thread_local_create,    tFunc(tVoid,tVoid), ID_PROTECTED);   #ifdef PIKE_DEBUG    set_gc_check_callback(gc_check_thread_local);   #endif    thread_local_prog=Pike_compiler->new_program;    add_ref(thread_local_prog);    end_class("thread_local", 0);