Branch: Tag:

2017-11-21

2017-11-21 01:26:02 by Stephen R. van den Berg <srb@cuci.nl>

pgsql: Simplify and bolster the code by using Thread.ResourceCount.

65:   final Thread.Mutex _unnamedportalmux;   private Thread.Mutex unnamedstatement;   private Thread.MutexKey termlock; - final int _portalsinflight; - final int _statementsinflight; + private Thread.ResourceCountKey backendreg; + final Thread.ResourceCount _portalsinflight, _statementsinflight;   final int _wasparallelisable;   final int _intransaction;   
108:   private string cnonce;   private Thread.Condition waitforauthready;   final Thread.Mutex _shortmux; - final Thread.Condition _readyforcommit; - final int _waittocommit, _readyforquerycount; + final int _readyforquerycount;    - private string _sprintf(int type, void|mapping flags) { + protected string _sprintf(int type) {    string res=UNDEFINED;    switch(type) {    case 'O':
213:       if(!_port)    _port = PGSQL_DEFAULT_PORT; -  .pgsql_util.register_backend(); +  backendreg = .pgsql_util.register_backend();    _shortmux=Thread.Mutex();    PD("Connect\n");    waitforauthready = Thread.Condition();
226:    _unnamedportalmux = Thread.Mutex();    unnamedstatement = Thread.Mutex();    readyforquery_cb = connect_cb; -  _portalsinflight = 0; -  _statementsinflight = 0; +  _portalsinflight = Thread.ResourceCount(); +  _statementsinflight = Thread.ResourceCount();    _wasparallelisable = 0;   }   
1143: Inside #if defined(PG_DEBUGMORE)
  #ifdef PG_DEBUGMORE    showportalstack("ERRORRESPONSE");   #endif -  if (!_portalsinflight && !_readyforquerycount) +  if (_portalsinflight->drained() && !_readyforquerycount)    sendsync();    PD("%O ErrorResponse %O\n",    objectp(portal)&&(portal._portalname||portal._preparedname),
1345:   protected void destroy() {    string errstring;    mixed err = catch(close()); -  .pgsql_util.unregister_backend(); +  backendreg = 0;    /*    * Flush out any asynchronously reported errors to stderr; because we are    * inside a destructor, throwing an error will not work anymore.