Branch: Tag:

2014-11-18

2014-11-18 22:08:59 by Stephen R. van den Berg <srb@cuci.nl>

pgsql: Merge shortlived mutexes to improve cache-locality.

103:   final string _host;   final int _port;   private string database, user, pass; - private Thread.Mutex waitforauth; +    private Thread.Condition waitforauthready; - final Thread.Mutex _commitmux; + final Thread.Mutex _shortmux;   final Thread.Condition _readyforcommit;   final int _waittocommit, _readyforquerycount;   
220:    if(!_port)    _port = PGSQL_DEFAULT_PORT;    .pgsql_util.register_backend(); -  waitforauth=Thread.Mutex(); +  _shortmux=Thread.Mutex();    reconnect();   }   
304:   }      private .pgsql_util.conxion getsocket(void|int nossl) { -  return .pgsql_util.conxion(this,qportals,(int)nossl); +  return .pgsql_util.conxion(this,qportals,(int)nossl,_shortmux);   }      //! Cancels all currently running queries in this session.
583:   private void waitauthready() {    if(waitforauthready) {    PD("%d Wait for auth ready %O\n",c?->socket?->query_fd(),backtrace()[-2]); -  Thread.MutexKey lock=waitforauth->lock(); +  Thread.MutexKey lock=_shortmux->lock();    catch(waitforauthready->wait(lock));    lock=0;    PD("%d Wait for auth ready released.\n",c?->socket?->query_fd());
1211:    reconnectdelay=RECONNECTBACKOFF;    break;    } -  Thread.MutexKey lock=waitforauth->lock(); +  Thread.MutexKey lock=_shortmux->lock();    if(!waitforauthready)    waitforauthready=Thread.Condition();    lock=0;
1225:   private int reconnect(void|int force) {    PD("(Re)connect\n");    if(!force) { -  Thread.MutexKey lock=waitforauth->lock(); +  Thread.MutexKey lock=_shortmux->lock();    if(waitforauthready) {    lock=0;    return 0; // Connect still in progress in other thread
1252:    }    PD("Actually start to connect\n");    qportals=Thread.Queue(); -  _commitmux=Thread.Mutex(); +     _readyforcommit=Thread.Condition();    _readyforquerycount=1;    _waittocommit=0;