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.266 2008/09/09 16:53:13 mast Exp $ + || $Id: threads.c,v 1.267 2008/11/18 19:10:30 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:771: Inside #if defined(PIKE_DEBUG)
   }    fprintf(stderr,"-----------------------\n");   }   #endif      PMOD_EXPORT int count_pike_threads(void)   {    return num_pike_threads;   }    + /* #define PROFILE_CHECK_THREADS */ +    static void check_threads(struct callback *cb, void *arg, void * arg2)   { -  + #ifdef PROFILE_CHECK_THREADS +  static unsigned long calls = 0; +  calls++; + #endif +    #ifndef HAVE_NO_YIELD    /* If we have no yield we can't cut calls here since it's possible    * that a thread switch will take place only occasionally in the    * window below. */ -  static int div_; -  if(div_++ & 255) -  return; +    #ifdef HAVE_GETHRTIME    {    static hrtime_t last_ = 0;    hrtime_t now = gethrtime();    if( now-last_ < 50000000 ) /* 0.05s slice */    return;    last_ = now;    }   #elif defined(HAVE_MACH_TASK_INFO_H) && defined(TASK_THREAD_TIMES_INFO)    {
pike.git/src/threads.c:811: Inside #if undefined(HAVE_NO_YIELD)
   now.tv_usec = info.user_time.microseconds;    timersub(&now, &last_check, &diff);    if (diff.tv_usec < 50000 && diff.tv_sec == 0)    return;    last_check = now;    }    }   #elif defined (USE_CLOCK_FOR_SLICES)    if (clock() - thread_start_clock < (clock_t) (CLOCKS_PER_SEC / 20))    return; + #else +  static int div_; +  if(div_++ & 255) +  return;   #endif   #endif    -  + #ifdef PROFILE_CHECK_THREADS +  { +  static long last_time; +  struct timeval now; +  gettimeofday (&now, NULL); +  if (now.tv_sec > last_time) { +  fprintf (stderr, "check_threads calls in %ld sec(s): %lu\n", +  (long) (now.tv_sec - last_time), calls); +  last_time = (unsigned long) now.tv_sec; +  calls = 0; +  } +  } + #endif +     DEBUG_CHECK_THREAD();       THREADS_ALLOW();    /* Allow other threads to run */    th_yield();    THREADS_DISALLOW();      #ifdef USE_CLOCK_FOR_SLICES    /* Must set the base time for the slice here since clock() returns    * thread local time. */