Branch: Tag:

1997-09-03

1997-09-03 05:26:10 by Henrik Grubbström (Grubba) <grubba@grubba.org>

_lock is now reentrant safe

Rev: server/base_server/configuration.pike:1.73

1: - string cvs_version = "$Id: configuration.pike,v 1.72 1997/09/03 05:16:31 per Exp $"; + string cvs_version = "$Id: configuration.pike,v 1.73 1997/09/03 05:26:10 grubba Exp $";   #include <module.h>   #include <roxen.h>   /* A configuration.. */
845: Inside #if defined(THREADS)
  object _lock(object|function f)   {    object key; -  function|int q; -  if(q=locks[f]) -  { -  if(q!=-1) -  { +  function|int l; +  if (functionp(f)) { +  f = function_object(f); +  } +  if (l = locks[f]) { +  if (l != -1) { +  // Allow recursive locks. +  catch {    //perror("lock %O\n", f); -  key=q(); +  key = l(); +  };    } -  } else { -  if(objectp(f)) -  if(f->thread_safe) +  } else if (f->thread_safe) {    locks[f]=-1; -  else -  locks[f]=Mutex()->lock; -  else if(function_object(f)->thread_safe) -  locks[f]=-1; -  else -  { -  //perror("new lock for %O\n", f); -  locks[f]=Mutex()->lock; +  } else { +  if (!locks[f]) { +  // Needed to avoid race-condition. +  l = Mutex()->lock; +  if (!locks[f]) { +  locks[f]=l;    } -  if((q=locks[f]) && q!=-1) -  { +  }    //perror("lock %O\n", f); -  key=q(); +  key = l();    } -  } +     return key;   }