Branch: Tag:

2017-11-10

2017-11-10 00:27:26 by Stephen R. van den Berg <srb@cuci.nl>

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

68:   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;   
112:   private string database, user, pass;   private Thread.Condition waitforauthready;   final Thread.Mutex _shortmux; - final Thread.Condition _readyforcommit; - final int _waittocommit, _readyforquerycount; + final int _readyforquerycount;    - private string _sprintf(int type) { + protected string _sprintf(int type) {    string res=UNDEFINED;    switch(type) {    case 'O':
223:       if(!_port)    _port = PGSQL_DEFAULT_PORT; -  .pgsql_util.register_backend(); +  backendreg = .pgsql_util.register_backend();    _shortmux=Thread.Mutex();    reconnect();   }
446:    "messages_received":_msgsreceived,    "bytes_received":_bytesreceived,    "reconnect_count":reconnected, -  "portals_in_flight":_portalsinflight, -  "statements_in_flight":_statementsinflight, +     ]);    return stats;   }
1070: 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),
1269:   protected void _destruct() {    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.
1341:    }    PD("Actually start to connect\n");    qportals=Thread.Queue(); -  _readyforcommit=Thread.Condition(); +     _readyforquerycount=1; -  _waittocommit=0; +     qportals->write(1);    if (!(c = .pgsql_util.conxion(this, qportals, 0)))    ERROR("Couldn't connect to database on %s:%d\n",_host,_port);
1351:    _unnamedportalmux=Thread.Mutex();    unnamedstatement=Thread.Mutex();    readyforquery_cb=recon?reconnect_cb:connect_cb; -  _portalsinflight=0; -  _statementsinflight = 0; +  _portalsinflight = Thread.ResourceCount(); +  _statementsinflight = Thread.ResourceCount();    _wasparallelisable = 0;    return 1;   }