From 2a851d7cc792dd992302a1153db845a8f3b549f7 Mon Sep 17 00:00:00 2001 From: Bernd Barsuhn Date: Wed, 29 Oct 2014 13:25:38 +0100 Subject: [PATCH] gpio: make mraa_gpio_isr_exit block until the interrupt handling thread is terminated. Signed-off-by: Bernd Barsuhn Signed-off-by: Brendan Le Foll --- src/gpio/gpio.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gpio/gpio.c b/src/gpio/gpio.c index 0319b6e..67ff5de 100644 --- a/src/gpio/gpio.c +++ b/src/gpio/gpio.c @@ -300,9 +300,10 @@ mraa_gpio_isr_exit(mraa_gpio_context dev) // stop isr being useful ret = mraa_gpio_edge_mode(dev, MRAA_GPIO_EDGE_NONE); - if ((dev->thread_id != 0) && - (pthread_cancel(dev->thread_id) != 0)) { - ret = MRAA_ERROR_INVALID_HANDLE; + if ((dev->thread_id != 0)) { + if ((pthread_cancel(dev->thread_id) != 0) || (pthread_join(dev->thread_id, NULL) != 0)) { + ret = MRAA_ERROR_INVALID_HANDLE; + } } // close the filehandle in case it's still open