Added function conn_close_locked()

This commit is contained in:
Daniele Varrazzo 2012-10-06 01:03:12 +01:00
parent f4f67ad985
commit 6d1b3b21e6
2 changed files with 18 additions and 7 deletions

View File

@ -141,6 +141,7 @@ HIDDEN void conn_notifies_process(connectionObject *self);
RAISES_NEG HIDDEN int conn_setup(connectionObject *self, PGconn *pgconn); RAISES_NEG HIDDEN int conn_setup(connectionObject *self, PGconn *pgconn);
HIDDEN int conn_connect(connectionObject *self, long int async); HIDDEN int conn_connect(connectionObject *self, long int async);
HIDDEN void conn_close(connectionObject *self); HIDDEN void conn_close(connectionObject *self);
HIDDEN void conn_close_locked(connectionObject *self);
RAISES_NEG HIDDEN int conn_commit(connectionObject *self); RAISES_NEG HIDDEN int conn_commit(connectionObject *self);
RAISES_NEG HIDDEN int conn_rollback(connectionObject *self); RAISES_NEG HIDDEN int conn_rollback(connectionObject *self);
RAISES_NEG HIDDEN int conn_set_session(connectionObject *self, const char *isolevel, RAISES_NEG HIDDEN int conn_set_session(connectionObject *self, const char *isolevel,

View File

@ -922,12 +922,24 @@ conn_close(connectionObject *self)
return; return;
} }
/* sets this connection as closed even for other threads; also note that /* sets this connection as closed even for other threads; */
we need to check the value of pgconn, because we get called even when
the connection fails! */
Py_BEGIN_ALLOW_THREADS; Py_BEGIN_ALLOW_THREADS;
pthread_mutex_lock(&self->lock); pthread_mutex_lock(&self->lock);
conn_close_locked(self);
pthread_mutex_unlock(&self->lock);
Py_END_ALLOW_THREADS;
}
/* conn_close_locked - shut down the connection with the lock already taken */
void conn_close_locked(connectionObject *self)
{
if (self->closed) {
return;
}
/* We used to call pq_abort_locked here, but the idea of issuing a /* We used to call pq_abort_locked here, but the idea of issuing a
* rollback on close/GC has been considered inappropriate. * rollback on close/GC has been considered inappropriate.
* *
@ -937,9 +949,10 @@ conn_close(connectionObject *self)
* transaction though: to avoid these problems the transaction should be * transaction though: to avoid these problems the transaction should be
* closed only in status CONN_STATUS_READY. * closed only in status CONN_STATUS_READY.
*/ */
self->closed = 1; self->closed = 1;
/* we need to check the value of pgconn, because we get called even when
* the connection fails! */
if (self->pgconn) { if (self->pgconn) {
PQfinish(self->pgconn); PQfinish(self->pgconn);
self->pgconn = NULL; self->pgconn = NULL;
@ -947,9 +960,6 @@ conn_close(connectionObject *self)
PQfreeCancel(self->cancel); PQfreeCancel(self->cancel);
self->cancel = NULL; self->cancel = NULL;
} }
pthread_mutex_unlock(&self->lock);
Py_END_ALLOW_THREADS;
} }
/* conn_commit - commit on a connection */ /* conn_commit - commit on a connection */