pike.git/
lib/
modules/
Sql.pmod/
pgsql.pike
Branch:
Tag:
Non-build tags
All tags
No tags
2016-02-24
2016-02-24 12:46:07 by Stephen R. van den Berg <srb@cuci.nl>
da3dc8e5529342e0f3b1f7ca5b23134b9cee76d1 (
49
lines) (+
22
/-
27
)
[
Show
|
Annotate
]
Branch:
8.1
pgsql: Sync destruction of objects with natural thread termination.
63:
final int _fetchlimit=FETCHLIMIT; final Thread.Mutex _unnamedportalmux;
-
private Thread.Mutex unnamedstatement;
+
private Thread.Mutex unnamedstatement
,termthread
;
+
private Thread.MutexKey termlock;
final int _portalsinflight; private .pgsql_util.conxion c;
597:
#endif final void _processloop(.pgsql_util.conxion ci) {
-
if(!this) // Oops, current object already destructed
-
return;
+
if(c && (!ci || c!=ci)) // If we are switching or dropping connections c->close(); // force a close on the old socket (c=ci)->socket->set_id(procmessage);
616:
plugbuffer->add_int8(0); PD("%O\n",(string)plugbuffer); if(catch(ci->start()->add_hstring(plugbuffer,4,4)->sendcmd(SENDOUT))) {
-
if(this) // Only when not destructed yet
+
if(_options.reconnect) _connectfail(); else destruct(waitforauthready);
-
+
termlock=0;
return; } } // Do not flush at this point, PostgreSQL 9.4 disapproves
628:
} private void procmessage() {
-
if(!this) // Oops, current object already destructed
-
return;
+
int terminating=0; .pgsql_util.conxion ci=c; // cache value FIXME sensible? .pgsql_util.conxiin cr=ci->i; // cache value FIXME sensible?
1179:
} break; }
-
if(!this) { // Already destructed
-
ci->close(); // So close descriptors only
-
return;
-
}
+
PD("Closing database processloop %O\n",err);
-
catch { // Cater for destruct races
+
_delayederror=err; for(;objectp(portal);portal=qportals->read()) if(objectp(portal)) {
1197:
_connectfail(); else destruct(waitforauthready);
-
}
;
+
termlock=0
;
if(err && !stringp(err)) throw(err); }
1211:
/*semi*/final void close() { if(qportals && qportals->size()) catch(cancelquery());
-
catch(
c->close()
)
;
+
c->close();
c=0; destruct(waitforauthready); } protected void destroy() {
-
+
termlock=(termthread=Thread.Mutex())->lock();
catch(close()); .pgsql_util.unregister_backend();
-
+
termthread->lock(1);
} final void _connectfail(void|mixed err) {