summaryrefslogtreecommitdiff
path: root/psycopg/connection_int.c
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2012-10-11 22:25:59 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2012-10-11 22:26:51 +0100
commit5fbf3ef147046548031896b49a27a21d94efae30 (patch)
tree00710eb709a08041f80a326b909d7136347e1626 /psycopg/connection_int.c
parentee763e0f47802232000293b3e4e33d87f7d19720 (diff)
parentb61a2a34c40e9b6e8774178e553a2e81eb889f06 (diff)
downloadpsycopg2-5fbf3ef147046548031896b49a27a21d94efae30.tar.gz
Merge branch 'fix-113' into devel
Diffstat (limited to 'psycopg/connection_int.c')
-rw-r--r--psycopg/connection_int.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c
index 8c8fed4..a93c233 100644
--- a/psycopg/connection_int.c
+++ b/psycopg/connection_int.c
@@ -922,12 +922,24 @@ conn_close(connectionObject *self)
return;
}
- /* sets this connection as closed even for other threads; also note that
- we need to check the value of pgconn, because we get called even when
- the connection fails! */
+ /* sets this connection as closed even for other threads; */
Py_BEGIN_ALLOW_THREADS;
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
* 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
* closed only in status CONN_STATUS_READY.
*/
-
self->closed = 1;
+ /* we need to check the value of pgconn, because we get called even when
+ * the connection fails! */
if (self->pgconn) {
PQfinish(self->pgconn);
self->pgconn = NULL;
@@ -947,9 +960,6 @@ conn_close(connectionObject *self)
PQfreeCancel(self->cancel);
self->cancel = NULL;
}
-
- pthread_mutex_unlock(&self->lock);
- Py_END_ALLOW_THREADS;
}
/* conn_commit - commit on a connection */