pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1:   #include "global.h" - RCSID("$Id: threads.c,v 1.162 2002/06/17 15:44:13 grubba Exp $"); + RCSID("$Id: threads.c,v 1.163 2002/09/14 02:58:49 mast Exp $");      PMOD_EXPORT int num_threads = 1;   PMOD_EXPORT int threads_disabled = 0;      #ifdef _REENTRANT   #include "threads.h"   #include "array.h"   #include "mapping.h"   #include "object.h"   #include "pike_macros.h"
pike.git/src/threads.c:22:   #include "operators.h"   #include "bignum.h"      #include <errno.h>      PMOD_EXPORT int live_threads = 0;   PMOD_EXPORT COND_T live_threads_change;   PMOD_EXPORT COND_T threads_disabled_change;   PMOD_EXPORT size_t thread_stack_size=1024 * 1204;    + #ifdef USE_CLOCK_FOR_SLICES + PMOD_EXPORT clock_t thread_start_clock = 0; + #endif +    #ifndef HAVE_PTHREAD_ATFORK   #include "callback.h"   #define PIKE_USE_OWN_ATFORK      static struct callback_list atfork_prepare_callback;   static struct callback_list atfork_parent_callback;   static struct callback_list atfork_child_callback;      int th_atfork(void (*prepare)(void),void (*parent)(void),void (*child)(void))   {
pike.git/src/threads.c:536:   }         PMOD_EXPORT int count_pike_threads(void)   {    return num_pike_threads;   }      static void check_threads(struct callback *cb, void *arg, void * arg2)   { - #ifdef HAVE_GETHRTIME -  static long long last_; -  if( gethrtime()-last_ < 50000000 ) /* 0.05s slice */ -  return; -  last_ = gethrtime(); - #else +     static int div_;    if(div_++ & 255)    return; -  + #ifdef HAVE_GETHRTIME +  { +  static hrtime_t last_; +  hrtime_t now = gethrtime(); +  if( now-last_ < 50000000 ) /* 0.05s slice */ +  return; +  last_ = now; +  } + #elif defined(USE_CLOCK_FOR_SLICES) +  if (clock() - thread_start_clock < (clock_t) (CLOCKS_PER_SEC / 20)) +  return;   #endif      #ifdef DEBUG    if(thread_for_id(th_self()) != Pike_interpreter.thread_id)    fatal("thread_for_id() (or Pike_interpreter.thread_id) failed!\n")       if(Pike_interpreter.backlink != OBJ2THREAD(Pike_interpreter.thread_id))    fatal("Hashlink is wrong!\n");   #endif       THREADS_ALLOW();    /* Allow other threads to run */   #ifdef HAVE_THR_YIELD    thr_yield();   #endif    THREADS_DISALLOW();    -  + #ifdef USE_CLOCK_FOR_SLICES +  /* Must set the base time for the slice here since clock() returns +  * thread local time. */ +  thread_start_clock = clock(); + #endif +    #ifdef DEBUG    if(thread_for_id(th_self()) != Pike_interpreter.thread_id)    fatal("thread_for_id() (or Pike_interpreter.thread_id) failed!\n")   #endif   }      TH_RETURN_TYPE new_thread_func(void * data)   {    struct thread_starter arg = *(struct thread_starter *)data;    JMP_BUF back;