pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: threads.c,v 1.277 2009/03/13 21:06:54 mast Exp $ + || $Id: threads.c,v 1.278 2009/03/13 21:44:46 mast Exp $   */      #include "global.h"      PMOD_EXPORT int num_threads = 1;   PMOD_EXPORT int threads_disabled = 0;      /* #define PICKY_MUTEX */      #ifdef _REENTRANT
pike.git/src/threads.c:349: Inside #if defined(USE_CLOCK_FOR_SLICES)
  PMOD_EXPORT clock_t thread_start_clock = 0;   PMOD_EXPORT THREAD_T last_clocked_thread = 0;   #endif      #ifdef PIKE_DEBUG   PMOD_EXPORT const char msg_ip_not_locked[] =    "Interpreter not locked.\n";   PMOD_EXPORT const char msg_ip_not_locked_this_thr[] =    "Interpreter not locked by this thread.\n";   PMOD_EXPORT const char msg_thr_swapped_over[] = -  "Thread 0x%08x swapped in over existing thread 0x%08x.\n"; +  "Thread %"PRINTSIZET"x swapped in over existing thread %"PRINTSIZET"x.\n";   PMOD_EXPORT const char msg_saved_thread_id[] =    "Saved thread id: ";   PMOD_EXPORT const char msg_swap_in_cur_thr_failed[] =    "SWAP_IN_CURRENT_THREAD failed.\n";   PMOD_EXPORT const char msg_thr_not_swapped_in[] =    "Thread is not swapped in.\n";   PMOD_EXPORT const char msg_cur_thr_not_bound[] =    "Current thread is not bound to the interpreter. "    "Nested use of ALLOW_THREADS()?\n";   PMOD_EXPORT const char msg_thr_states_mixed[] =    "Thread states mixed up between threads.\n";   PMOD_EXPORT const char msg_thr_allow_in_gc[] =    "Threads allowed during garbage collection (pass %d).\n";   PMOD_EXPORT const char msg_thr_allow_in_disabled[] =    "Threads allowed from a different thread " -  "while threads are disabled. (self: 0x%08x, disabler: 0x%08x)\n"; +  "while threads are disabled. " +  "(self: %"PRINTSIZET"x, disabler: %"PRINTSIZET"x)\n";   PMOD_EXPORT const char msg_global_dynbuf_in_use[] =    "Threads allowed while the global dynamic buffer is in use.\n";   #endif      struct thread_local   {    INT32 id;   };      static volatile IMUTEX_T *interleave_list = NULL;
pike.git/src/threads.c:471:   {    low_init_threads_disable();       if(live_threads) {    SWAP_OUT_CURRENT_THREAD();    while (live_threads) {    THREADS_FPRINTF(0,    (stderr,    "_disable_threads(): Waiting for %d threads to finish\n",    live_threads)); -  low_co_wait_interpreter(&live_threads_change); +  _do_co_wait_interpreter(&live_threads_change);    } -  +  THREADS_FPRINTF(0, (stderr, "_disable_threads(): threads now disabled\n"));    SWAP_IN_CURRENT_THREAD();    }   }      void exit_threads_disable(struct object *o)   {    THREADS_FPRINTF(0, (stderr, "exit_threads_disable(): threads_disabled:%d\n",    threads_disabled));    if(threads_disabled) {    if(!--threads_disabled) {    IMUTEX_T *im = (IMUTEX_T *)interleave_list;       /* Order shouldn't matter for unlock, so no need to do it backwards. */    while(im) { -  THREADS_FPRINTF(0, -  (stderr, -  "exit_threads_disable(): Unlocking IM 0x%p\n", im)); +  THREADS_FPRINTF(0, (stderr, +  "exit_threads_disable(): Unlocking IM %p\n", im));    mt_unlock(&(im->lock));    im = im->next;    }       mt_unlock(&interleave_lock);       THREADS_FPRINTF(0, (stderr, "_exit_threads_disable(): Wake up!\n"));    co_broadcast(&threads_disabled_change);   #ifdef PIKE_DEBUG    threads_disabled_thread = 0;
pike.git/src/threads.c:518:      void init_interleave_mutex(IMUTEX_T *im)   {    mt_init(&(im->lock));       THREADS_FPRINTF(0, (stderr,    "init_interleave_mutex(): init_threads_disable()\n"));       init_threads_disable(NULL);    -  THREADS_FPRINTF(0, (stderr, -  "init_interleave_mutex(): Locking IM 0x%p\n", im)); +  THREADS_FPRINTF(0, (stderr, "init_interleave_mutex(): Locking IM %p\n", im));       /* Lock it so that it can be unlocked by exit_threads_disable() */    mt_lock(&(im->lock));       im->next = (IMUTEX_T *)interleave_list;    if (interleave_list) {    interleave_list->prev = im;    }    interleave_list = im;    im->prev = NULL;
pike.git/src/threads.c:1229:    * so that we can avoid races.    *    * The main race is the one on current_object,    * since it at this point only has one reference.    *    * We also want the stuff in arg to be copied properly    * before we exit the function...    */    SWAP_OUT_CURRENT_THREAD();    while (thread_state->status == THREAD_NOT_STARTED) { -  THREADS_FPRINTF(0, (stderr, "THREAD_CREATE %p waiting...\n", +  THREADS_FPRINTF(0, (stderr, "f_thread_create %p waiting...\n",    thread_state)); -  low_co_wait_interpreter(&thread_state->status_change); +  _do_co_wait_interpreter(&thread_state->status_change);    } -  +  THREADS_FPRINTF(0, (stderr, "f_thread_create %p continue\n", thread_state));    SWAP_IN_CURRENT_THREAD();    } else {    low_cleanup_interpret(&thread_state->state);    free_array(arg.args);    Pike_error("Failed to create thread (errno = %d).\n", tmp);    }    -  THREADS_FPRINTF(0, (stderr, "THREAD_CREATE -> t:%p\n", -  thread_state)); +  THREADS_FPRINTF(0, (stderr, "f_thread_create %p done\n", thread_state));    push_int(0);   }      /*! @endclass    */      #ifdef UNIX_THREADS   /*! @decl void thread_set_concurrency(int concurrency)    *!    *! @fixme
pike.git/src/threads.c:1649:    *!    *! The corresponding mutex will be unlocked when the object    *! is destructed (eg by not having any references left).    *!    *! @seealso    *! @[Mutex], @[Condition]    */   #define THIS_KEY ((struct key_storage *)(CURRENT_STORAGE))   void init_mutex_key_obj(struct object *o)   { -  THREADS_FPRINTF(1, (stderr, "KEY k:%p, o:%p\n", +  THREADS_FPRINTF(1, (stderr, "KEY k:%p, t:%p\n",    THIS_KEY, Pike_interpreter.thread_state));    THIS_KEY->mut=0;    THIS_KEY->mutex_obj = NULL;    THIS_KEY->owner = Pike_interpreter.thread_state;    add_ref(THIS_KEY->owner_obj = Pike_interpreter.thread_state->thread_obj);    THIS_KEY->initialized=1;   }      void exit_mutex_key_obj(struct object *o)   {
pike.git/src/threads.c:2013:   static void f_thread_id_result(INT32 args)   {    struct thread_state *th=THIS_THREAD;       if (threads_disabled) {    Pike_error("Cannot wait for threads when threads are disabled!\n");    }       th->waiting++;    -  THREADS_FPRINTF(0, (stderr, -  "Thread->wait(): Waiting for thread %p (state:%d).\n", -  th, th->status)); +  THREADS_FPRINTF(0, (stderr, "Thread->wait(): Waiting for thread_state %p " +  "(state:%d).\n", th, th->status));    while(th->status != THREAD_EXITED) {    SWAP_OUT_CURRENT_THREAD();    co_wait_interpreter(&th->status_change);    SWAP_IN_CURRENT_THREAD();    check_threads_etc();    THREADS_FPRINTF(0, -  (stderr, -  "Thread->wait(): Waiting for thread %p (state:%d).\n", -  th, th->status)); +  (stderr, "Thread->wait(): Waiting for thread_state %p " +  "(state:%d).\n", th, th->status));    }       assign_svalue_no_free(Pike_sp, &th->result);    Pike_sp++;    dmalloc_touch_svalue(Pike_sp-1);       th->waiting--;       if (!th->thread_obj)    /* Do this only if exit_thread_obj already has run. */