Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d0d592f

Browse files
committed
Oops, move the GIL release/reacquire from oss_sync() to _do_ioctl_0():
that way it applies to *only* the ioctl() call, and also happens for the other blocking ioctls (POST, RESET).
1 parent 7b4abbb commit d0d592f

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

Modules/ossaudiodev.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,22 @@ static PyObject *
291291
_do_ioctl_0(int fd, PyObject *args, char *fname, int cmd)
292292
{
293293
char argfmt[32] = ":";
294+
int rv;
294295

295296
assert(strlen(fname) <= 30);
296297
strcat(argfmt, fname);
297298
if (!PyArg_ParseTuple(args, argfmt))
298299
return NULL;
299300

300-
if (ioctl(fd, cmd, 0) == -1)
301+
/* According to [email protected], all three of the ioctls that
302+
use this function can block, so release the GIL. This is
303+
especially important for SYNC, which can block for several
304+
seconds. */
305+
Py_BEGIN_ALLOW_THREADS
306+
rv = ioctl(fd, cmd, 0);
307+
Py_END_ALLOW_THREADS
308+
309+
if (rv == -1)
301310
return PyErr_SetFromErrno(PyExc_IOError);
302311
Py_INCREF(Py_None);
303312
return Py_None;
@@ -353,12 +362,7 @@ oss_speed(oss_audio_t *self, PyObject *args)
353362
static PyObject *
354363
oss_sync(oss_audio_t *self, PyObject *args)
355364
{
356-
int rv;
357-
358-
Py_BEGIN_ALLOW_THREADS
359-
rv = _do_ioctl_0(self->fd, args, "sync", SNDCTL_DSP_SYNC);
360-
Py_END_ALLOW_THREADS
361-
return rv;
365+
return _do_ioctl_0(self->fd, args, "sync", SNDCTL_DSP_SYNC);
362366
}
363367

364368
static PyObject *

0 commit comments

Comments
 (0)