summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2012-10-06 01:03:12 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2012-10-06 01:03:12 +0100
commit2137db89d4568fc58dd30a16a0c451cf8768491f (patch)
treefc975587cf91ba38cf812a759e5308d915b3e662
parent9f9da182f1d5c188c306161f8b96263ce333168b (diff)
downloadpsycopg2-2137db89d4568fc58dd30a16a0c451cf8768491f.tar.gz
Added function conn_close_locked()
-rw-r--r--psycopg/connection.h1
-rw-r--r--psycopg/connection_int.c24
2 files changed, 18 insertions, 7 deletions
diff --git a/psycopg/connection.h b/psycopg/connection.h
index 9647ffd..01cc6a4 100644
--- a/psycopg/connection.h
+++ b/psycopg/connection.h
@@ -141,6 +141,7 @@ HIDDEN void conn_notifies_process(connectionObject *self);
RAISES_NEG HIDDEN int conn_setup(connectionObject *self, PGconn *pgconn);
HIDDEN int conn_connect(connectionObject *self, long int async);
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_rollback(connectionObject *self);
RAISES_NEG HIDDEN int conn_set_session(connectionObject *self, const char *isolevel,
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 */