summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-10-11 00:03:08 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-11-05 09:34:48 +0000
commit17d70babb1cf589c23fc1c7f008ba4e10a48cf72 (patch)
tree0983608363123bdd775358133cda4dad630a55e2
parent397eace051aaf633a8facbe92d04e2194c908e7d (diff)
downloadpsycopg2-17d70babb1cf589c23fc1c7f008ba4e10a48cf72.tar.gz
Keep the GIL while converting the xid into the PostgreSQL transaction id.
-rw-r--r--psycopg/connection_int.c19
-rw-r--r--psycopg/pqpath.c9
-rw-r--r--psycopg/pqpath.h2
3 files changed, 18 insertions, 12 deletions
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c
index d92d53f..2f2a48d 100644
--- a/psycopg/connection_int.c
+++ b/psycopg/connection_int.c
@@ -939,21 +939,30 @@ conn_tpc_command(connectionObject *self, const char *cmd, XidObject *xid)
{
PGresult *pgres = NULL;
char *error = NULL;
- int rv;
+ char *tid = NULL;
+ int rv = -1;
Dprintf("conn_tpc_command: %s", cmd);
+ /* convert the xid into PostgreSQL transaction id while keeping the GIL */
+ if (!(tid = xid_get_tid(xid))) { goto exit; }
+
Py_BEGIN_ALLOW_THREADS;
pthread_mutex_lock(&self->lock);
- rv = pq_tpc_command_locked(self, cmd, xid, &pgres, &error, &_save);
+ if (0 > (rv = pq_tpc_command_locked(self, cmd, tid,
+ &pgres, &error, &_save))) {
+ pthread_mutex_unlock(&self->lock);
+ Py_BLOCK_THREADS;
+ pq_complete_error(self, &pgres, &error);
+ goto exit;
+ }
pthread_mutex_unlock(&self->lock);
Py_END_ALLOW_THREADS;
- if (rv < 0) {
- pq_complete_error(self, &pgres, &error);
- }
+exit:
+ PyMem_Free(tid);
return rv;
}
diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c
index 37d5279..3977f31 100644
--- a/psycopg/pqpath.c
+++ b/psycopg/pqpath.c
@@ -617,19 +617,17 @@ pq_reset(connectionObject *conn)
* holding the global interpreter lock. */
int
-pq_tpc_command_locked(connectionObject *conn, const char *cmd, XidObject *xid,
- PGresult **pgres, char **error,
- PyThreadState **tstate)
+pq_tpc_command_locked(connectionObject *conn, const char *cmd, const char *tid,
+ PGresult **pgres, char **error, PyThreadState **tstate)
{
int rv = -1;
- char *tid = NULL, *etid = NULL, *buf = NULL;
+ char *etid = NULL, *buf = NULL;
Py_ssize_t buflen;
Dprintf("_pq_tpc_command: pgconn = %p, command = %s",
conn->pgconn, cmd);
/* convert the xid into the postgres transaction_id and quote it. */
- if (!(tid = xid_get_tid(xid))) { goto exit; }
if (!(etid = psycopg_escape_string((PyObject *)conn, tid, 0, NULL, NULL)))
{ goto exit; }
@@ -647,7 +645,6 @@ pq_tpc_command_locked(connectionObject *conn, const char *cmd, XidObject *xid,
exit:
PyMem_Free(buf);
PyMem_Free(etid);
- PyMem_Free(tid);
return rv;
}
diff --git a/psycopg/pqpath.h b/psycopg/pqpath.h
index 5f56efa..51a640d 100644
--- a/psycopg/pqpath.h
+++ b/psycopg/pqpath.h
@@ -47,7 +47,7 @@ HIDDEN int pq_abort_locked(connectionObject *conn, PGresult **pgres,
HIDDEN int pq_abort(connectionObject *conn);
HIDDEN int pq_reset(connectionObject *conn);
HIDDEN int pq_tpc_command_locked(connectionObject *conn,
- const char *cmd, XidObject *xid,
+ const char *cmd, const char *tid,
PGresult **pgres, char **error,
PyThreadState **tstate);
HIDDEN int pq_is_busy(connectionObject *conn);