Branch: Tag:

2002-10-23

2002-10-23 19:07:01 by Martin Stjernholm <mast@lysator.liu.se>

Added a mutex for the modules_stopped condition variable. Before this,
a race could cause the server to not exit after all modules have been
properly stopped in a shutdown.

Rev: server/base_server/configuration.pike:1.524

5:   // @appears Configuration   //! A site's main configuration    - constant cvs_version = "$Id: configuration.pike,v 1.523 2002/09/20 12:08:01 anders Exp $"; + constant cvs_version = "$Id: configuration.pike,v 1.524 2002/10/23 19:07:01 mast Exp $";   #include <module.h>   #include <module_constants.h>   #include <roxen.h>
388: Inside #if defined(THREADS)
  private int num_modules = 0;   #ifdef THREADS   private Thread.Condition modules_stopped = Thread.Condition(); + private Thread.Mutex modules_stopped_mutex = Thread.Mutex();   #endif   private void safe_stop_module (RoxenModule mod, string desc)   {    if (mixed err = catch (mod && mod->stop && mod->stop()))    report_error ("While stopping " + desc + ": " + describe_backtrace (err)); -  if (!--num_modules) +    #ifdef THREADS -  modules_stopped->signal() +  Thread.MutexKey lock = modules_stopped_mutex->lock(); +  if (!--num_modules) +  modules_stopped->signal(); +  lock = 0; + #else +  --num_modules;   #endif -  ; +    }      void stop (void|int asynch)
455:   #undef STOP_MODULES       if (!asynch) { -  num_modules -= 17; -  if (num_modules) { +    #ifdef THREADS -  // Relying on the interpreter lock here. -  modules_stopped->wait(); +  Thread.MutexKey lock = modules_stopped_mutex->lock(); +  num_modules -= 17; +  if (num_modules) modules_stopped->wait (lock); +  lock = 0;   #else -  +  if (num_modules != 17)    error ("num_modules shouldn't be nonzero here when running nonthreaded.\n");   #endif    }   } - } +       string type_from_filename( string file, int|void to, string|void myext )   {