From e38b4af98751e5aa7dbc33e66468fe239e5f2b93 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Wed, 19 Jun 2019 16:00:42 -0600 Subject: [PATCH] Release the Python GIL while enqueuing and dequeuing messages! --- src/cxoConnection.c | 4 ++++ src/cxoQueue.c | 12 +++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/cxoConnection.c b/src/cxoConnection.c index c1a4b56..3292915 100644 --- a/src/cxoConnection.c +++ b/src/cxoConnection.c @@ -1469,9 +1469,11 @@ static PyObject *cxoConnection_dequeue(cxoConnection *conn, PyObject* args, return NULL; // dequeue payload + Py_BEGIN_ALLOW_THREADS status = dpiConn_deqObject(conn->handle, nameBuffer.ptr, nameBuffer.size, optionsObj->handle, propertiesObj->handle, payloadObj->handle, &messageIdValue, &messageIdLength); + Py_END_ALLOW_THREADS cxoBuffer_clear(&nameBuffer); if (status < 0) return cxoError_raiseAndReturnNull(); @@ -1512,9 +1514,11 @@ static PyObject *cxoConnection_enqueue(cxoConnection *conn, PyObject* args, return NULL; // enqueue payload + Py_BEGIN_ALLOW_THREADS status = dpiConn_enqObject(conn->handle, nameBuffer.ptr, nameBuffer.size, optionsObj->handle, propertiesObj->handle, payloadObj->handle, &messageIdValue, &messageIdLength); + Py_END_ALLOW_THREADS cxoBuffer_clear(&nameBuffer); if (status < 0) return cxoError_raiseAndReturnNull(); diff --git a/src/cxoQueue.c b/src/cxoQueue.c index 6b7acd9..657fa63 100644 --- a/src/cxoQueue.c +++ b/src/cxoQueue.c @@ -192,7 +192,7 @@ int cxoQueue_deqHelper(cxoQueue *queue, uint32_t *numProps, const char *buffer; cxoMsgProps *temp; cxoObject *obj; - int ok; + int ok, status; // use the same array to store the intermediate values provided by ODPI-C; // by doing so there is no need to allocate an additional array and any @@ -200,7 +200,10 @@ int cxoQueue_deqHelper(cxoQueue *queue, uint32_t *numProps, handles = (dpiMsgProps**) props; // perform dequeue - if (dpiQueue_deqMany(queue->handle, numProps, handles) < 0) + Py_BEGIN_ALLOW_THREADS + status = dpiQueue_deqMany(queue->handle, numProps, handles); + Py_END_ALLOW_THREADS + if (status < 0) return cxoError_raiseAndReturnInt(); // create objects that are returned to the user @@ -298,7 +301,10 @@ int cxoQueue_enqHelper(cxoQueue *queue, uint32_t numProps, } // perform enqueue - if (dpiQueue_enqMany(queue->handle, numProps, handles) < 0) + Py_BEGIN_ALLOW_THREADS + status = dpiQueue_enqMany(queue->handle, numProps, handles); + Py_END_ALLOW_THREADS + if (status < 0) return cxoError_raiseAndReturnInt(); return 0;