Branch: Tag:

2003-04-14

2003-04-14 19:24:47 by Martin Stjernholm <mast@lysator.liu.se>

Don't use the handler thread queue implementation for background_run;
it's too.. ehm.. eccentric for that. Fixed a race where two
simultaneous calls to background_run could cause the background
process to stop completely.

Rev: server/base_server/roxen.pike:1.833

6:   // 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.832 2003/04/14 16:40:42 grubba Exp $"; + constant cvs_version="$Id: roxen.pike,v 1.833 2003/04/14 19:24:47 mast Exp $";      //! @appears roxen   //!
560: Inside #if defined(THREADS)
   return tmp;    }    +  // Warning: This function isn't thread safe.    void write(mixed v)    {    if(w_ptr >= sizeof(buffer))
928:   }      #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
951: Inside #if defined(THREADS)
   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));
963: Inside #if defined(THREADS)
   }      #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])) :
1003:   //! @[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.
1011: Inside #if defined(THREADS)
   function enqueue = lambda()    {    bg_queue->write (({func, args})); -  if (bg_queue->size() == 1) +  if (!bg_process_running)    handle (bg_process_queue);    };