diff options
| author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-10-11 00:03:08 +0100 |
|---|---|---|
| committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-11-05 09:34:48 +0000 |
| commit | 17d70babb1cf589c23fc1c7f008ba4e10a48cf72 (patch) | |
| tree | 0983608363123bdd775358133cda4dad630a55e2 /psycopg/connection_int.c | |
| parent | 397eace051aaf633a8facbe92d04e2194c908e7d (diff) | |
| download | psycopg2-17d70babb1cf589c23fc1c7f008ba4e10a48cf72.tar.gz | |
Keep the GIL while converting the xid into the PostgreSQL transaction id.
Diffstat (limited to 'psycopg/connection_int.c')
| -rw-r--r-- | psycopg/connection_int.c | 19 |
1 files changed, 14 insertions, 5 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; } |
