bpo-31653: Don't release the GIL if we can acquire a multiprocessing semaphore immediately (#4078)
This commit is contained in:
parent
bcbdd2f8db
commit
c872d39d32
|
@ -0,0 +1,2 @@
|
|||
Don't release the GIL if we can acquire a multiprocessing semaphore
|
||||
immediately.
|
|
@ -304,6 +304,15 @@ semlock_acquire(SemLockObject *self, PyObject *args, PyObject *kwds)
|
|||
deadline.tv_nsec %= 1000000000;
|
||||
}
|
||||
|
||||
/* Check whether we can acquire without releasing the GIL and blocking */
|
||||
do {
|
||||
res = sem_trywait(self->handle);
|
||||
err = errno;
|
||||
} while (res < 0 && errno == EINTR && !PyErr_CheckSignals());
|
||||
errno = err;
|
||||
|
||||
if (res < 0 && errno == EAGAIN && blocking) {
|
||||
/* Couldn't acquire immediately, need to block */
|
||||
do {
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
if (blocking && timeout_obj == Py_None)
|
||||
|
@ -317,6 +326,7 @@ semlock_acquire(SemLockObject *self, PyObject *args, PyObject *kwds)
|
|||
if (res == MP_EXCEPTION_HAS_BEEN_SET)
|
||||
break;
|
||||
} while (res < 0 && errno == EINTR && !PyErr_CheckSignals());
|
||||
}
|
||||
|
||||
if (res < 0) {
|
||||
errno = err;
|
||||
|
|
Loading…
Reference in New Issue