Roxen.git / server / base_server / roxen.pike

version» Context lines:

Roxen.git/server/base_server/roxen.pike:1:   // This file is part of Roxen WebServer.   // Copyright © 1996 - 2001, Roxen IS.   //   // The Roxen WebServer main program.   //   // Per Hedbor, Henrik Grubbström, Pontus Hagland, David Hedbor and others.   // ABS and suicide systems contributed freely by Francesco Chemolli    - constant cvs_version="$Id: roxen.pike,v 1.807 2003/03/05 16:31:17 mast Exp $"; + constant cvs_version="$Id: roxen.pike,v 1.808 2003/05/05 16:46:50 mast Exp $";      // The argument cache. Used by the image cache.   ArgCache argcache;      // Some headerfiles   #define IN_ROXEN   #include <roxen.h>   #include <config.h>   #include <module.h>   #include <variables.h>
Roxen.git/server/base_server/roxen.pike:531: Inside #if defined(THREADS)
   }       mixed tryread()    {    if (!(w_ptr - r_ptr)) return ([])[0];    mixed tmp = buffer[r_ptr];    buffer[r_ptr++] = 0; // Throw away any references.    return tmp;    }    +  // Warning: This function isn't thread safe.    void write(mixed v)    {    if(w_ptr >= sizeof(buffer))    {    buffer=buffer[r_ptr..]+allocate(8);    w_ptr-=r_ptr;    r_ptr=0;    }    buffer[w_ptr++]=v;    r_cond::signal();
Roxen.git/server/base_server/roxen.pike:885:    //    // I hope that this will solve all your problems. /per    if( really > 0 )    return lambda( mixed ... args ){ call_out( f, 0, @args ); };    if( really < 0 )    return f;    return SignalAsyncVerifier( f )->call;   }      #ifdef THREADS - static Queue bg_queue = Queue(); + static Thread.Queue bg_queue = Thread.Queue();   static int bg_process_running;      // Use a time buffer to strike a balance if the server is busy and   // always have at least one busy thread: The maximum waiting time in   // that case is somewhere between bg_time_buffer_min and   // bg_time_buffer_max. If there are only short periods of time between   // the queue runs, the max waiting time will shrink towards the   // minimum.   static constant bg_time_buffer_max = 30;   static constant bg_time_buffer_min = 0.5;
Roxen.git/server/base_server/roxen.pike:908: Inside #if defined(THREADS)
  static void bg_process_queue()   {    if (bg_process_running) return;    // Relying on the interpreter lock here.    bg_process_running = 1;       int maxbeats =    min (time() - bg_last_busy, bg_time_buffer_max) * (int) (1 / 0.04);       if (mixed err = catch { -  while (array task = bg_queue->tryread()) { +  while (bg_queue->size()) { +  // Not a race here since only one thread is reading the queue. +  array task = bg_queue->read(); +     // Wait a while if another thread is busy already.    if (busy_threads > 1) {    for (maxbeats = max (maxbeats, (int) (bg_time_buffer_min / 0.04));    busy_threads > 1 && maxbeats > 0;    maxbeats--)    // Pike implementation note: If 0.02 or smaller, we'll busy wait here.    sleep (0.04);    bg_last_busy = time();    }      #ifdef DEBUG_BACKGROUND_RUN -  report_debug ("background run %s (%s)\n", +  report_debug ("background_run run %s (%s)\n",    functionp (task[0]) ?    sprintf ("%s: %s", Function.defined (task[0]),    master()->describe_function (task[0])) :    programp (task[0]) ?    sprintf ("%s: %s", Program.defined (task[0]),    master()->describe_program (task[0])) :    sprintf ("%O", task[0]),    map (task[1], lambda (mixed arg)    {return sprintf ("%O", arg);}) * ", ");   #endif
Roxen.git/server/base_server/roxen.pike:960:   //!   //! The function @[func] will be enqueued after approximately @[delay]   //! seconds, to be called with the rest of the arguments as its   //! arguments.   //!   //! The function might be run in the backend thread, so it should   //! never run for a considerable time. Instead do another call to   //! @[background_run] to queue it up again after some work has been   //! done, or use @[BackgroundProcess].   { + #ifdef DEBUG_BACKGROUND_RUN +  report_debug ("background_run enqueue %s (%s)\n", +  functionp (func) ? +  sprintf ("%s: %s", Function.defined (func), +  master()->describe_function (func)) : +  programp (func) ? +  sprintf ("%s: %s", Program.defined (func), +  master()->describe_program (func)) : +  sprintf ("%O", func), +  map (args, lambda (mixed arg) +  {return sprintf ("%O", arg);}) * ", "); + #endif +    #ifdef THREADS    if (!hold_wakeup_cond)    // stop_handler_threads is running; ignore more work.    return;       function enqueue = lambda()    {    bg_queue->write (({func, args})); -  if (bg_queue->size() == 1) +  if (!bg_process_running)    handle (bg_process_queue);    };       if (delay)    call_out (enqueue, delay);    else    enqueue();       enqueue = 0; // To avoid garbage.