mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-26 10:53:44 +03:00
Dropped locking version of pq_is_busy()
The locking version was used for sync connections, the non-locking one for green ones. However it only calls non-blocking functions, so it doesn't really matter releasing the gil. So have only the non-locking one. Note that the name are sort of swapped: pq_is_busy() does now what pq_is_busy_locked() used to do.
This commit is contained in:
parent
5467f65122
commit
2a8fa4bef7
|
@ -936,16 +936,7 @@ _conn_poll_query(connectionObject *self)
|
|||
|
||||
case ASYNC_READ:
|
||||
Dprintf("conn_poll: async_status = ASYNC_READ");
|
||||
if (self->async) {
|
||||
res = _conn_poll_advance_read(self, pq_is_busy(self));
|
||||
}
|
||||
else {
|
||||
/* we are a green connection being polled as result of a query.
|
||||
this means that our caller has the lock and we are being called
|
||||
from the callback. If we tried to acquire the lock now it would
|
||||
be a deadlock. */
|
||||
res = _conn_poll_advance_read(self, pq_is_busy_locked(self));
|
||||
}
|
||||
break;
|
||||
|
||||
case ASYNC_DONE:
|
||||
|
|
|
@ -770,57 +770,16 @@ exit:
|
|||
means that there is data available to be collected. -1 means an error, the
|
||||
exception will be set accordingly.
|
||||
|
||||
this function locks the connection object
|
||||
this function call Py_*_ALLOW_THREADS macros */
|
||||
|
||||
int
|
||||
pq_is_busy(connectionObject *conn)
|
||||
{
|
||||
int res;
|
||||
Dprintf("pq_is_busy: consuming input");
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
pthread_mutex_lock(&(conn->lock));
|
||||
|
||||
if (PQconsumeInput(conn->pgconn) == 0) {
|
||||
Dprintf("pq_is_busy: PQconsumeInput() failed");
|
||||
pthread_mutex_unlock(&(conn->lock));
|
||||
Py_BLOCK_THREADS;
|
||||
|
||||
/* if the libpq says pgconn is lost, close the py conn */
|
||||
if (CONNECTION_BAD == PQstatus(conn->pgconn)) {
|
||||
conn->closed = 2;
|
||||
}
|
||||
|
||||
PyErr_SetString(OperationalError, PQerrorMessage(conn->pgconn));
|
||||
return -1;
|
||||
}
|
||||
|
||||
res = PQisBusy(conn->pgconn);
|
||||
|
||||
Py_BLOCK_THREADS;
|
||||
conn_notifies_process(conn);
|
||||
conn_notice_process(conn);
|
||||
Py_UNBLOCK_THREADS;
|
||||
|
||||
pthread_mutex_unlock(&(conn->lock));
|
||||
Py_END_ALLOW_THREADS;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/* pq_is_busy_locked - equivalent to pq_is_busy but we already have the lock
|
||||
*
|
||||
* The function should be called with the lock and holding the GIL.
|
||||
*/
|
||||
|
||||
int
|
||||
pq_is_busy_locked(connectionObject *conn)
|
||||
pq_is_busy(connectionObject *conn)
|
||||
{
|
||||
Dprintf("pq_is_busy_locked: consuming input");
|
||||
Dprintf("pq_is_busy: calling PQconsumeInput()");
|
||||
|
||||
if (PQconsumeInput(conn->pgconn) == 0) {
|
||||
Dprintf("pq_is_busy_locked: PQconsumeInput() failed");
|
||||
Dprintf("pq_is_busy: PQconsumeInput() failed");
|
||||
|
||||
/* if the libpq says pgconn is lost, close the py conn */
|
||||
if (CONNECTION_BAD == PQstatus(conn->pgconn)) {
|
||||
|
@ -831,8 +790,8 @@ pq_is_busy_locked(connectionObject *conn)
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* notices and notifies will be processed at the end of the loop we are in
|
||||
* (async reading) by pq_fetch. */
|
||||
conn_notifies_process(conn);
|
||||
conn_notice_process(conn);
|
||||
|
||||
return PQisBusy(conn->pgconn);
|
||||
}
|
||||
|
|
|
@ -60,7 +60,6 @@ HIDDEN int pq_tpc_command_locked(connectionObject *conn,
|
|||
PGresult **pgres, char **error,
|
||||
PyThreadState **tstate);
|
||||
HIDDEN int pq_is_busy(connectionObject *conn);
|
||||
HIDDEN int pq_is_busy_locked(connectionObject *conn);
|
||||
HIDDEN int pq_flush(connectionObject *conn);
|
||||
HIDDEN void pq_clear_async(connectionObject *conn);
|
||||
RAISES_NEG HIDDEN int pq_set_non_blocking(connectionObject *conn, int arg);
|
||||
|
|
Loading…
Reference in New Issue
Block a user