pike.git
/
lib
/
modules
/
Sql.pmod
/
pgsql_util.pmod
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:165:
private inline mixed callout(function(mixed ...:void) f, float|int delay,mixed ... args) { return local_backend->call_out(f,delay,@args); } // Some pgsql utility functions class bufcon { inherit Stdio.Buffer;
+
private int dirty;
#ifdef PG_DEBUGRACE final bufcon `chain() { return this; } #endif private conxion realbuffer; protected void create(conxion _realbuffer) { realbuffer=_realbuffer; } final int `stashcount() { return realbuffer->stashcount; } final bufcon start(void|int waitforreal) {
-
+
dirty = 1;
realbuffer->stashcount++;
-
+
dirty = 2;
#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->shortmux->lock(); if (portal)
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:205:
if (mode == SYNCSEND) { add(PGSYNC); realbuffer->stashqueue->write(1); mode = SENDOUT; // Demote it to prevent an extra SYNC upon stashflush } realbuffer->stash->add(this); PD("%d>Stashed mode %d > %d\n", realbuffer->socket->query_fd(), mode, realbuffer->stashflushmode); if (mode > realbuffer->stashflushmode) realbuffer->stashflushmode = mode;
+
dirty = 1;
if(!--realbuffer->stashcount)
-
realbuffer->stashavail.signal();
+
dirty = 0,
realbuffer->stashavail.signal();
+
else
+
dirty = 0;
lock=0; this->clear(); if(lock=realbuffer->nostash->trylock(1)) { #ifdef PG_DEBUGRACE conxsess sess = conxsess(realbuffer); realbuffer->started = lock; lock = 0; sess->sendcmd(SENDOUT); #else realbuffer->started = lock; lock = 0; realbuffer->sendcmd(SENDOUT); #endif } }
-
+
+
protected void _destruct() {
+
switch (dirty) {
+
case 1:
+
werror("FIXME: Race condition detected %s\n",
+
describe_backtrace(({"", backtrace()[..<1]})));
+
if (!realbuffer->stashcount)
+
break;
+
case 2:
+
Thread.MutexKey lock = realbuffer->shortmux->lock(2);
+
if (!--realbuffer->stashcount)
+
realbuffer->stashavail.signal();
+
lock = 0;
+
}
+
}
}; class conxiin { inherit Stdio.Buffer:i; final Thread.Condition fillread; final Thread.Mutex fillreadmux; final int procmsg; private int didreadcb;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:333:
mode = getstash(KEEP); lock=0; if (mode > KEEP) sendcmd(mode); // Force out stash to the server #ifdef PG_DEBUGRACE return sess; #else return this; #endif }
-
stashcount++;
-
return bufcon(this);
+
return bufcon(this)
->start()
;
} private int write_cb() { Thread.MutexKey lock = shortmux->lock(); if (this) { // Guard against async destructs towrite -= output_to(socket, towrite); lock = 0; if (!i->fillread && !sizeof(this)) close(); }
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:511:
private string _sprintf(int type) { string res=UNDEFINED; switch(type) { case 'O': int fd=-1; if(socket) catch(fd=socket->query_fd()); res=predef::sprintf("conxion fd: %d input queue: %d/%d " "queued portals: %d output queue: %d/%d\n"
-
"started: %d\n",
+
"started: %
d stashcount: %
d\n",
fd,sizeof(i),i->_size_object(), qportals && qportals->size(), sizeof(this), _size_object(),
-
!!started);
+
!!started
, stashcount
);
break; } return res; } protected void create(object pgsqlsess,Thread.Queue _qportals,int nossl) { o::create(); qportals = _qportals; synctransact = 1; socket=sfile();