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.947 2006/11/14 15:18:50 anders Exp $"; + constant cvs_version="$Id: roxen.pike,v 1.948 2006/11/14 21:27:06 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:1018: 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]. + //! The function might be run in the backend thread if no thread + //! support is available, so it should never run for a long 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);    };    -  +  mixed res;    if (delay) -  call_out (enqueue, delay); +  res = call_out (enqueue, delay);    else    enqueue();       enqueue = 0; // To avoid garbage.    -  +  return res;   #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.
Roxen.git/server/base_server/roxen.pike:1103:    error ("Minimum ref calculation wrong - have only %d refs.\n", self_refs);   #endif    if (stopping || self_refs <= 4) return;    func (@args);    background_run (period, repeat, func, args);    }       //! @decl void set_period (int|float period);    //!    //! Changes the period to @[period] seconds between calls. +  //! +  //! @note +  //! This does not change the currently ongoing period, if any. That +  //! might be remedied.    void set_period (int|float period_)    {    period = period_;    }       //! @decl static void create (int|float period, function func, mixed... args);    //!    //! The function @[func] will be called with the following arguments    //! after approximately @[period] seconds, and then kept being    //! called with approximately that amount of time between each call.