pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:257: Inside #if defined(PG_DEBUG)
protected final bool range_error(int howmuch) {
#ifdef PG_DEBUG
if (howmuch <= 0)
error("Out of range %d\n", howmuch);
#endif
if (fillread) {
Thread.MutexKey lock = fillreadmux->lock();
if (!didreadcb)
fillread.wait(lock);
didreadcb = 0;
- lock = 0;
+
} else
throw(MAGICTERMINATE);
return true;
}
final int read_cb(mixed id, mixed b) {
PD("Read callback %O\n", b && ((string)b)
#ifndef PG_DEBUGMORE
[..255]
#endif
);
Thread.MutexKey lock = fillreadmux->lock();
if (procmsg && id)
procmsg = 0, lock = 0, Thread.Thread(id);
else if (fillread)
didreadcb = 1, fillread.signal();
- lock = 0;
+
return 0;
}
private void create() {
i::create();
fillreadmux = Thread.Mutex();
fillread = Thread.Condition();
}
};
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:431:
PD("Flush\n");
add(PGFLUSH);
case SENDOUT:;
}
if (towrite = sizeof(this)) {
PD("%d>Sendcmd %O\n",
socket->query_fd(), ((string)this)[..towrite-1]);
towrite -= output_to(socket, towrite);
}
} while (0);
- lock = started = 0;
+ started = 0;
return;
};
lock = 0;
PD("Sendcmd failed %s\n", describe_backtrace(err));
destruct(this);
}
final int close() {
if (!closenext && nostash) {
closenext = 1;
-
+ {
Thread.MutexKey lock = i->fillreadmux->lock();
- if (i->fillread) { // Delayed close() after flushing the output buffer
+ if (i->fillread) { // Delayed close() after flushing the output buffer
i->fillread.signal();
i->fillread = 0;
}
- lock = 0;
+ }
PD("%d>Delayed close, flush write\n", socket->query_fd());
i->read_cb(socket->query_id(), 0);
return 0;
} else
return -1;
}
final void purge() {
if (stashcount) {
stashcount = 0;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:675:
|| (_unnamedstatementkey ? "*parsing*" : ""));
break;
}
return res;
}
protected void create(proxy _pgsqlsess, conxion _c, string query,
int _portalbuffersize, int alltyped, array params, int forcetext,
int _timeout, int _syncparse, int _transtype) {
pgsqlsess = _pgsqlsess;
- if (catch(cr = (c = _c)->i))
+ if (c = _c)
+ cr = c->i;
+ else
losterror();
_query = query;
datarows = Thread.Queue();
_ddescribe = Thread.Condition();
_ddescribemux = Thread.Mutex();
closemux = Thread.Mutex();
portalbuffersize = _portalbuffersize;
alltext = !alltyped;
_params = params;
_forcetext = forcetext;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:728:
final void _storetiming() {
if (_tprepared) {
_tprepared.trun = gethrtime() - _tprepared.trunstart;
m_delete(_tprepared, "trunstart");
_tprepared = 0;
}
}
private void waitfordescribe() {
+ {
Thread.MutexKey lock = _ddescribemux->lock();
if (!datarowtypes)
PT(_ddescribe->wait(lock));
- lock = 0;
+ }
if (this) // If object already destructed, skip the next call
trydelayederror(); // since you cannot call functions anymore
else
error(LOSTERROR);
}
//! @seealso
//! @[Sql.sql_result()->num_fields()]
/*semi*/final int num_fields() {
if (!datarowtypes)
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:880:
return msglen;
#endif
}
final void _setrowdesc(array(mapping(string:mixed)) drowdesc,
array(int) drowtypes) {
Thread.MutexKey lock = _ddescribemux->lock();
datarowdesc = drowdesc;
datarowtypes = drowtypes;
_ddescribe->broadcast();
- lock = 0;
+
}
final void _preparebind(array dtoid) {
array(string|int) paramValues =_params ? _params[2] : emptyarray;
if (sizeof(dtoid) != sizeof(paramValues))
SUSERERROR("Invalid number of bindings, expected %d, got %d\n",
sizeof(dtoid), sizeof(paramValues));
Thread.MutexKey lock = _ddescribemux->lock();
if (!_portalname) {
_portalname
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1066:
_unnamedstatementkey = 0;
CHAIN(bindbuffer)->add_int8('B')->add_hstring(plugbuffer, 4, 4);
if (!_tprepared && sizeof(_preparedname))
closestatement(CHAIN(bindbuffer), _preparedname);
_sendexecute(_fetchlimit
&& !(transtype != NOTRANS
|| sizeof(_query) >= MINPREPARELENGTH &&
execfetchlimit->match(_query))
&& _fetchlimit, bindbuffer);
}
- } else
- lock = 0;
+
}
-
+ }
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 = closemux->lock();
_state = PARSING;
-
+ {
Thread.MutexKey lockc = pgsqlsess->shortmux->lock();
if (syncparse || syncparse < 0 && pgsqlsess->wasparallelisable) {
PD("Commit waiting for statements to finish\n");
catch(PT(pgsqlsess->statementsinflight->wait_till_drained(lockc)));
}
stmtifkey = pgsqlsess->statementsinflight->acquire();
- lockc = 0;
- lock = 0;
+ }
+ }
statuscmdcomplete = 0;
pgsqlsess->wasparallelisable = paralleliseprefix->match(_query);
}
final void _releasestatement(void|int nolock) {
Thread.MutexKey lock;
if (!nolock)
lock = closemux->lock();
if (_state <= BOUND) {
_state = COMMITTED;
stmtifkey = 0;
}
- lock = 0;
+
}
final void _bindportal() {
Thread.MutexKey lock = closemux->lock();
_state = BOUND;
portalsifkey = pgsqlsess->portalsinflight->acquire();
- 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:
portalsifkey = 0;
}
switch (_state) {
case BOUND:
case PARSING:
stmtifkey = 0;
}
_state = PURGED;
- lock = 0;
+ }
releaseconditions();
}
final int _closeportal(conxsess cs) {
void|bufcon|conxsess 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) {
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1176:
if (plugbuffer->stashcount->drained() && transtype != TRANSBEGIN)
/*
* 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.
*/
pgsqlsess->readyforquerycount++, retval = SYNCSEND;
pgsqlsess->pportalcount = 0;
}
}
- lock = 0;
+
return retval;
}
final void _processdataready(array datarow, void|int msglen) {
bytesreceived += msglen;
inflight--;
if (_state<CLOSED)
datarows->write(datarow);
if (++index == 1)
PD("<%O _fetchlimit %d=min(%d||1,%d), inflight %d\n", _portalname,
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1199:
if (_fetchlimit) {
_fetchlimit =
min((portalbuffersize >> 1) * index / bytesreceived || 1,
pgsqlsess._fetchlimit);
Thread.MutexKey lock = closemux->lock();
if (_fetchlimit && inflight <= (_fetchlimit - 1) >> 1)
_sendexecute(_fetchlimit);
else if (!_fetchlimit)
PD("<%O _fetchlimit %d, inflight %d, skip execute\n",
_portalname, _fetchlimit, inflight);
- lock = 0;
+
}
}
private void releaseconditions() {
_unnamedportalkey = _unnamedstatementkey = 0;
if (!datarowtypes) {
if (_state != PURGED && !delayederror)
delayederror = LOSTERROR;
datarowtypes = emptyarray;
_ddescribe->broadcast();
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1435:
private Crypto.SCRAM SASLcontext;
final Thread.Condition waitforauthready;
final Thread.Mutex shortmux;
final int readyforquerycount;
private string _sprintf(int type) {
string res;
switch (type) {
case 'O':
res = sprintf(DRIVERNAME".proxy(%s@%s:%d/%s,%d,%d)",
- user, host, port, database, c?->socket && c->socket->query_fd(),
+ user, host, port, database, c && c->socket && c->socket->query_fd(),
backendpid);
break;
}
return res;
}
private void create(void|string host, void|string database,
void|string user, void|string pass,
void|mapping(string:mixed) options) {
if (this::pass = pass) {
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1479:
runtimeparameter = ([]);
unnamedportalmux = Thread.Mutex();
unnamedstatement = Thread.Mutex();
readyforquery_cb = connect_cb;
portalsinflight = Thread.ResourceCount();
statementsinflight = Thread.ResourceCount();
wasparallelisable = 0;
}
final int is_open() {
- catch {
- return c->socket->is_open();
- };
- return 0;
+ return c && c->socket && c->socket->is_open();
}
final string geterror(void|int clear) {
throwdelayederror(this);
untolderror = 0;
string s = lastmessage * "\n";
if (clear)
lastmessage = emptyarray;
warningscollected = 0;
return sizeof(s) && s;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:1650:
showportalstack("LOOPTOP");
#endif
if (!sizeof(cr)) { // Preliminary check, fast path
Thread.MutexKey lock = cr->fillreadmux->lock();
if (!sizeof(cr)) { // Check for real
if (!cr->fillread) {
lock = 0;
throw(MAGICTERMINATE); // Force proper termination
}
cr->procmsg = 1;
- lock = 0;
+
return; // Terminate thread, wait for callback
}
- lock = 0;
+
}
int msgtype = cr->read_int8();
if (!portal) {
portal = qportals->try_read();
#ifdef PG_DEBUG
showportal(msgtype);
#endif
}
int msglen = cr->read_int32();
msgsreceived++;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:2288:
PD("Terminating processloop due to %s\n", describe_backtrace(err));
delayederror = err;
}
destruct(waitforauthready);
c->purge();
};
}
final void close() {
throwdelayederror(this);
+ {
Thread.MutexKey lock;
if (qportals && qportals->size())
catch(cancelquery());
if (unnamedstatement)
termlock = unnamedstatement->lock(1);
if (c) // Prevent trivial backtraces
c->close();
if (unnamedstatement)
lock = unnamedstatement->lock(1);
-
+ if (c)
c->purge();
- lock = 0;
+ }
destruct(waitforauthready);
}
private void destroy() {
string errstring;
mixed err = catch(close());
backendreg = 0;
if (untolderror) {
/*
* Flush out any asynchronously reported errors to stderr; because we are