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

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:127:    final bufcon start(void|int waitforreal) {    realbuffer->stashcount++;   #ifdef PG_DEBUG    if(waitforreal)    error("pgsql.bufcon not allowed here\n");   #endif    return this;    }       final void sendcmd(int mode,void|sql_result portal) { -  Thread.MutexKey lock=realbuffer->stashupdate->lock(); +  Thread.MutexKey lock=realbuffer->shortmux->lock();    if(portal)    realbuffer->stashqueue->write(portal);    realbuffer->stash->add(this);    mode=mergemode(realbuffer,mode);    if(!--realbuffer->stashcount)    realbuffer->stashavail.signal();    lock=0;    this->clear();    if(lock=realbuffer->nostash->trylock(1)) {    realbuffer->started=lock; lock=0;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:149:    }    }      }      class conxion {    inherit Stdio.Buffer:i;    inherit Stdio.Buffer:o;       private Thread.Condition fillread; -  private Thread.Mutex fillreadmux; +     private Thread.Queue qportals; -  +  final Thread.Mutex shortmux;    final Stdio.File socket;    private object pgsqlsess;    private int towrite; -  private Thread.Mutex towritemux; +        final function(:void) gottimeout;    final int timeout;    final Thread.Mutex nostash;    final Thread.MutexKey started; -  final Thread.Mutex stashupdate; +     final Thread.Queue stashqueue;    final Thread.Condition stashavail;    final Stdio.Buffer stash;    final int stashflushmode;    final int stashcount;    final int synctransact;   #ifdef PG_DEBUG    final int queueoutidx;    final int queueinidx=-1;   #endif
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:182:    private inline void queueup(sql_result portal) {    qportals->write(portal); portal->_synctransact=synctransact;    PD("%d>%O %d %d Queue portal %d bytes\n",socket->query_fd(),    portal._portalname,++queueoutidx,synctransact,sizeof(this));    }       final conxion|bufcon start(void|int waitforreal) {    Thread.MutexKey lock;    if(lock=(waitforreal?nostash->lock:nostash->trylock)(1)) {    started=lock; -  lock=stashupdate->lock(); +  lock=shortmux->lock();    if(stashcount)    stashavail.wait(lock);    add(stash); stash->clear();    foreach(stashqueue->try_read_array();;sql_result portal)    queueup(portal);    lock=0;    return this;    }    stashcount++;    return bufcon(this);
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:204:       protected bool range_error(int howmuch) {    if(!howmuch)    return false;   #ifdef PG_DEBUG    if(howmuch<0)    error("Out of range %d\n",howmuch);   #endif    if(fillread) {    array cid=callout(gottimeout,timeout); -  Thread.MutexKey lock=fillreadmux->lock(); +  Thread.MutexKey lock=shortmux->lock();    fillread.wait(lock);    lock=0;    local_backend->remove_call_out(cid);    } else    throw(MAGICTERMINATE);    return true;    }       private int read_cb(mixed id,mixed b) { -  Thread.MutexKey lock=fillreadmux->lock(); +  Thread.MutexKey lock=shortmux->lock();    if(fillread)    fillread.signal();    lock=0;    return 0;    }       private int write_cb() { -  Thread.MutexKey lock=towritemux->lock(); +  Thread.MutexKey lock=shortmux->lock();    towrite-=output_to(socket,towrite);    lock=0;    if(!fillread && !sizeof(this)) {    PD("%d>Close socket delayed\n",socket->query_fd());    socket->close();    }    return 0;    }       final inline int consume(int w) { return i::consume(w); }
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:264:    mode=SENDOUT;    break;    case FLUSHLOGSEND:    PD("%d>%O %d Queue simplequery %d bytes\n",    socket->query_fd(),portal._portalname,++queueoutidx,sizeof(this));    mode=FLUSHSEND;    }    qportals->write(synctransact++);    } while(0);    if(started) { -  Thread.MutexKey lock=stashupdate->lock(); +  Thread.MutexKey lock=shortmux->lock();    if(sizeof(stash)) {    add(stash); stash->clear();    foreach(stashqueue->try_read_array();;sql_result portal)    queueup(portal);    }    mode=mergemode(this,mode);    stashflushmode=KEEP;    lock=0;    }    catch {   outer:    do {    switch(mode) {    default:    break outer;    case FLUSHSEND:    PD("Flush\n");    add(PGFLUSH);    case SENDOUT:;    } -  Thread.MutexKey lock=towritemux->lock(); +  Thread.MutexKey lock=shortmux->lock();    if(towrite=sizeof(this)) {    PD("%d>Sendcmd %O\n",socket->query_fd(),((string)this)[..towrite-1]);    towrite-=output_to(socket,towrite);    }    lock=0;    } while(0);    started=0;    return;    };    if(pgsqlsess)
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:375:    res=predef::sprintf("conxion fd: %d input queue: %d/%d "    "queued portals: %d output queue: %d/%d\n",    socket&&socket->query_fd(),    sizeof(i::this),i::_size_object(),    qportals->size(),sizeof(this),_size_object());    break;    }    return res;    }    -  protected void create(object _pgsqlsess,Thread.Queue _qportals,int nossl) { +  protected void create(object _pgsqlsess,Thread.Queue _qportals,int nossl, +  Thread.Mutex _shortmux) {    i::create(); o::create();    qportals = _qportals;    synctransact = 1; -  towritemux=Thread.Mutex(); +     fillread=Thread.Condition(); -  fillreadmux=Thread.Mutex(); +  shortmux=_shortmux;    gottimeout=sendcmd; // Preset it with a NOP    timeout=128; // Just a reasonable amount    socket=Stdio.File();    nostash=Thread.Mutex(); -  stashupdate=Thread.Mutex(); +     stashqueue=Thread.Queue();    stashavail=Thread.Condition();    stash=Stdio.Buffer();    pgsqlsess=_pgsqlsess;    Thread.Thread(connectloop,nossl);    }   }      //! The result object returned by @[Sql.pgsql()->big_query()], except for   //! the noted differences it behaves the same as @[Sql.sql_result].
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:820:    if(!prepbufferready || _state>=CLOSING)    lock=_unnamedstatementkey=0;    else {    destruct(prepbufferready); // Make sure we do this exactly once    lock=0;    plugbuffer->add_int16(sizeof(datarowdesc));    if(sizeof(datarowdesc))    foreach(datarowdesc;;mapping col)    plugbuffer->add_int16(oidformat(col.type));    else if(commitprefix->match(_query)) { -  lock=pgsqlsess->_commitmux->lock(); +  lock=pgsqlsess->_shortmux->lock();    if(pgsqlsess->_portalsinflight) {    pgsqlsess->_waittocommit++;    PD("Commit waiting for portals to finish\n");    pgsqlsess->_readyforcommit->wait(lock);    pgsqlsess->_waittocommit--;    }    lock=0;    }    PD("Bind portal %O statement %O\n",_portalname,_preparedname);    _fetchlimit=pgsqlsess->_fetchlimit;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:895:    plugbuffer->add("c\0\0\0\4");    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; -  Thread.MutexKey lockc=pgsqlsess->_commitmux->lock(); +  Thread.MutexKey lockc=pgsqlsess->_shortmux->lock();    if(!--pgsqlsess->_portalsinflight) {    if(pgsqlsess->_waittocommit) {    PD("Signal no portals in flight\n");    pgsqlsess->_readyforcommit->signal();    lockc=0;    } else if(!alreadyfilled)    pgsqlsess->_readyforquerycount++, retval=SYNCSEND;    pgsqlsess->_pportalcount=0;    }    lockc=0;