Skip to content

Commit a76493f

Browse files
authored
Merge pull request #53 from billmccartney/master
Added several disabling of the GIL so that other threads can run when…
2 parents fcd44e6 + 24b5127 commit a76493f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

spidev_module.c

+8
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,9 @@ SpiDev_xfer2(SpiDevObject *self, PyObject *args)
400400
PyObject *obj;
401401
PyObject *seq;
402402
struct spi_ioc_transfer xfer;
403+
Py_BEGIN_ALLOW_THREADS
403404
memset(&xfer, 0, sizeof(xfer));
405+
Py_END_ALLOW_THREADS
404406
uint8_t *txbuf, *rxbuf;
405407
char wrmsg_text[4096];
406408

@@ -420,8 +422,10 @@ SpiDev_xfer2(SpiDevObject *self, PyObject *args)
420422
return NULL;
421423
}
422424

425+
Py_BEGIN_ALLOW_THREADS
423426
txbuf = malloc(sizeof(__u8) * len);
424427
rxbuf = malloc(sizeof(__u8) * len);
428+
Py_END_ALLOW_THREADS
425429

426430
for (ii = 0; ii < len; ii++) {
427431
PyObject *val = PySequence_Fast_GET_ITEM(seq, ii);
@@ -448,6 +452,7 @@ SpiDev_xfer2(SpiDevObject *self, PyObject *args)
448452
seq = PySequence_List(obj);
449453
}
450454

455+
Py_BEGIN_ALLOW_THREADS
451456
xfer.tx_buf = (unsigned long)txbuf;
452457
xfer.rx_buf = (unsigned long)rxbuf;
453458
xfer.len = len;
@@ -456,6 +461,7 @@ SpiDev_xfer2(SpiDevObject *self, PyObject *args)
456461
xfer.bits_per_word = bits_per_word ? bits_per_word : self->bits_per_word;
457462

458463
status = ioctl(self->fd, SPI_IOC_MESSAGE(1), &xfer);
464+
Py_END_ALLOW_THREADS
459465
if (status < 0) {
460466
PyErr_SetFromErrno(PyExc_IOError);
461467
free(txbuf);
@@ -474,8 +480,10 @@ SpiDev_xfer2(SpiDevObject *self, PyObject *args)
474480
// Stop generating an extra CS except in mode CS_HOGH
475481
if (self->mode & SPI_CS_HIGH) status = read(self->fd, &rxbuf[0], 0);
476482

483+
Py_BEGIN_ALLOW_THREADS
477484
free(txbuf);
478485
free(rxbuf);
486+
Py_END_ALLOW_THREADS
479487

480488

481489
if (PyTuple_Check(obj)) {

0 commit comments

Comments
 (0)