pike.git / lib / modules / Sql.pmod / pgsql_util.pmod

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:690:    trydelayederror();    return datarowdesc+emptyarray;    }      #ifdef PG_DEBUG   #define INTVOID int   #else   #define INTVOID void   #endif    final INTVOID _decodedata(int msglen,string cenc) { -  _storetiming(); +  _storetiming(); _releasestatement();    string serror;    bytesreceived+=msglen;    int cols=cr->read_int16();    array a=allocate(cols,!alltext&&Val.null);   #ifdef PG_DEBUG    msglen-=2+4*cols;   #endif    foreach(datarowtypes;int i;int typ) {    int collen=cr->read_sint(4);    if(collen>0) {
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:924:    m_delete(pgsqlsess->_prepareds,_query),_tprepared=0;    waitfordescribe();    }    if(_state>=CLOSING)    lock=_unnamedstatementkey=0;    else {    plugbuffer->add_int16(sizeof(datarowtypes));    if(sizeof(datarowtypes))    plugbuffer->add_ints(map(datarowtypes,oidformat),2);    else if (syncparse < 0 && !pgsqlsess->_wasparallelisable -  && pgsqlsess->_portalsinflight > 1) { +  && pgsqlsess->_statementsinflight > 1) {    lock=pgsqlsess->_shortmux->lock();    // Decrement temporarily to account for ourselves -  if(--pgsqlsess->_portalsinflight) { +  if(--pgsqlsess->_statementsinflight) {    pgsqlsess->_waittocommit++; -  PD("Commit waiting for portals to finish\n"); +  PD("Commit waiting for statements to finish\n");    catch(PT(pgsqlsess->_readyforcommit->wait(lock)));    pgsqlsess->_waittocommit--;    }    // Increment again to account for ourselves -  pgsqlsess->_portalsinflight++; +  pgsqlsess->_statementsinflight++;    }    lock=0;    PD("Bind portal %O statement %O\n",_portalname,_preparedname);    _fetchlimit=pgsqlsess->_fetchlimit;    _bindportal();    conxsess bindbuffer = c->start();    _unnamedstatementkey=0;    CHAIN(bindbuffer)->add_int8('B')->add_hstring(plugbuffer, 4, 4);    if(!_tprepared && sizeof(_preparedname))    closestatement(CHAIN(bindbuffer), _preparedname);
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:965:    final void _processrowdesc(array(mapping(string:mixed)) datarowdesc,    array(int) datarowtypes) {    _setrowdesc(datarowdesc,datarowtypes);    if(_tprepared) {    _tprepared.datarowdesc=datarowdesc;    _tprepared.datarowtypes=datarowtypes;    }    }       final void _parseportal() { -  Thread.MutexKey lock; +  Thread.MutexKey lock = closemux->lock(); +  _state=PARSING; +  Thread.MutexKey lockc = pgsqlsess->_shortmux->lock();    if (syncparse || syncparse < 0 && pgsqlsess->_wasparallelisable) { -  lock = pgsqlsess->_shortmux->lock(); -  if(pgsqlsess->_portalsinflight) { +  if(pgsqlsess->_statementsinflight) {    pgsqlsess->_waittocommit++; -  PD("Commit waiting for portals to finish\n"); +  PD("Commit waiting for statements to finish\n");    // Do NOT put this in a function, it would require passing a lock    // variable on the argumentstack to the function, which will cause    // unpredictable lock release issues due to the extra copy on the stack -  catch(PT(pgsqlsess->_readyforcommit->wait(lock))); +  catch(PT(pgsqlsess->_readyforcommit->wait(lockc)));    pgsqlsess->_waittocommit--;    }    } -  pgsqlsess->_portalsinflight++; -  lock = closemux->lock(); -  _state=PARSING; +  pgsqlsess->_statementsinflight++; +  lockc = 0;    lock=0;    statuscmdcomplete=UNDEFINED;    pgsqlsess->_wasparallelisable = paralleliseprefix->match(_query);    }    -  +  final void _releasestatement(void|int nolock) { +  Thread.MutexKey lock; +  if (!nolock) +  lock = closemux->lock(); +  if (_state <= BOUND) { +  _state = COMMITTED; +  lock = pgsqlsess->_shortmux->lock(); +  if (!--pgsqlsess->_statementsinflight && pgsqlsess->_waittocommit) { +  PD("Signal no statements in flight\n"); +  catch(pgsqlsess->_readyforcommit->signal()); +  } +  } +  lock = 0; +  } +     final void _bindportal() { -  Thread.MutexKey lock=closemux->lock(); +  Thread.MutexKey lock = closemux->lock();    _state=BOUND; -  +  Thread.MutexKey lockc = pgsqlsess->_shortmux->lock(); +  pgsqlsess->_portalsinflight++; +  lockc = 0;    lock=0;    }       final void _purgeportal() {    PD("Purge portal\n");    datarows->write(1); // Signal EOF    Thread.MutexKey lock=closemux->lock();    _fetchlimit=0; // disables further Executes    switch(_state) {    case COPYINPROGRESS: -  +  case COMMITTED:    case BOUND: -  case PARSING: +     --pgsqlsess->_portalsinflight;    } -  +  switch(_state) { +  case BOUND: +  case PARSING: +  --pgsqlsess->_statementsinflight; +  }    _state=CLOSED;    lock=0;    releaseconditions();    }       final int _closeportal(conxsess cs) {    object plugbuffer = CHAIN(cs);    int retval=KEEP;    PD("%O Try Closeportal %d\n",_portalname,_state);    Thread.MutexKey lock=closemux->lock();    _fetchlimit=0; // disables further Executes    switch(_state) { -  +  case PARSING: +  case BOUND: +  _releasestatement(1); +  } +  switch(_state) {    case PORTALINIT: -  +  case PARSING:    _unnamedstatementkey=0;    _state=CLOSING;    break;    case COPYINPROGRESS:    PD("CopyDone\n");    plugbuffer->add("c\0\0\0\4"); -  +  case COMMITTED:    case BOUND:    _state=CLOSING;    lock=0;    PD("Close portal %O\n",_portalname);    if(sizeof(_portalname)) {    plugbuffer->add_int8('C')->add_hstring(({'P',_portalname,0}),4,4);    retval=FLUSHSEND;    } else    _unnamedportalkey=0; -  case PARSING: -  _unnamedstatementkey = 0; -  _state = CLOSING; -  lock = 0; +     Thread.MutexKey lockc=pgsqlsess->_shortmux->lock();    if(!--pgsqlsess->_portalsinflight) { -  if(pgsqlsess->_waittocommit) { -  PD("Signal no portals in flight\n"); -  catch(pgsqlsess->_readyforcommit->signal()); -  lockc=0; +  if(!pgsqlsess->_waittocommit && !plugbuffer->stashcount)    /*    * stashcount will be non-zero if a parse request has been queued    * before the close was initiated.    * It's a bit of a tricky race, but this check should be sufficient.    */ -  } else if (!plugbuffer->stashcount) +     pgsqlsess->_readyforquerycount++, retval=SYNCSEND;    pgsqlsess->_pportalcount=0;    }    lockc=0;    }    lock=0;    return retval;    }       final void _processdataready(array datarow,void|int msglen) {