From caebb8b1fbff6b29bc0618508024f701d3d0d31b Mon Sep 17 00:00:00 2001 From: Constantin Musca Date: Fri, 15 Jan 2016 18:13:41 +0200 Subject: [PATCH] iio: guard pthread_setcancelstate with HAVE_PTHREAD_CANCEL Signed-off-by: Constantin Musca Signed-off-by: Brendan Le Foll --- src/iio/iio.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/iio/iio.c b/src/iio/iio.c index 7ad20a8..fd2c7f6 100644 --- a/src/iio/iio.c +++ b/src/iio/iio.c @@ -318,15 +318,21 @@ mraa_iio_trigger_handler(void* arg) for (;;) { if (mraa_iio_wait_event(dev->fp, &data[0], &read_size) == MRAA_SUCCESS) { +#ifdef HAVE_PTHREAD_CANCEL pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); +#endif // only can process if readsize >= enabled channel's datasize for (i = 0; i < (read_size / dev->datasize); i++) { dev->isr((void*)&data); } +#ifdef HAVE_PTHREAD_CANCEL pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); +#endif } else { // we must have got an error code so die nicely +#ifdef HAVE_PTHREAD_CANCEL pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); +#endif return NULL; } } @@ -467,12 +473,18 @@ mraa_iio_event_handler(void* arg) for (;;) { if (mraa_iio_event_poll_nonblock(dev->fp_event, &data) == MRAA_SUCCESS) { +#ifdef HAVE_PTHREAD_CANCEL pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); +#endif dev->isr_event(&data, dev->isr_args); +#ifdef HAVE_PTHREAD_CANCEL pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); +#endif } else { // we must have got an error code so die nicely +#ifdef HAVE_PTHREAD_CANCEL pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); +#endif return NULL; } }