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 - 2004, 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.964 2009/06/24 11:37:59 mast Exp $"; + constant cvs_version="$Id: roxen.pike,v 1.965 2009/06/29 13:22:54 mast Exp $";      //! @appears roxen   //!   //! The Roxen WebServer main program.      // The argument cache. Used by the image cache.   ArgCache argcache;      // Some headerfiles   #define IN_ROXEN
Roxen.git/server/base_server/roxen.pike:1051: Inside #if defined(THREADS)
   }    }) {    bg_process_running = 0;    handle (bg_process_queue);    throw (err);    }    bg_process_running = 0;   }   #endif    - void background_run (int|float delay, function func, mixed... args) + mixed background_run (int|float delay, function func, mixed... args)   //! Enqueue a task to run in the background in a way that makes as   //! little impact as possible on the incoming requests. No matter how   //! many tasks are queued to run in the background, only one is run at   //! a time. The tasks won't be starved, though.   //!   //! 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]. -  + //! + //! @returns + //! If the function is queued for execution right away then zero is + //! returned. Otherwise its call out identifier is returned, which can + //! be used with @[find_call_out] or @[remove_call_out].   {   #ifdef DEBUG_BACKGROUND_RUN    report_debug ("background_run enqueue %s (%s) [%d jobs in queue]\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);}) * ", ",    bg_queue->size());   #endif      #ifdef THREADS    if (!hold_wakeup_cond)    // stop_handler_threads is running; ignore more work. -  return; +  return 0;       function enqueue = lambda()    {    bg_queue->write (({func, args}));    if (!bg_process_running)    handle (bg_process_queue);    };    -  +  // Be careful to zero enqueue below to avoid trampoline garbage. +     if (delay) -  call_out (enqueue, delay); -  else +  // A trick to zero enqueue without putting the call_out return +  // value into a local variable. +  return call_out (enqueue, (enqueue = 0, delay)); +  else {    enqueue(); -  -  enqueue = 0; // To avoid garbage. -  +  enqueue = 0; +  return 0; +  }   #else    // Can't do much better when we haven't got threads.. -  call_out (func, delay, @args); +  return call_out (func, delay, @args);   #endif   }      class BackgroundProcess   //! A class to do a task repeatedly in the background, in a way that   //! makes as little impact as possible on the incoming requests (using   //! @[background_run]).   //!   //! The user must keep a reference to this object, otherwise it will remove   //! itself and the callback won't be called anymore.