gpio: make mraa_gpio_isr_exit block until the interrupt handling thread is terminated.
authorBernd Barsuhn <bernd.barsuhn@me.com>
Wed, 29 Oct 2014 12:25:38 +0000 (13:25 +0100)
committerBrendan Le Foll <brendan.le.foll@intel.com>
Tue, 4 Nov 2014 10:12:34 +0000 (10:12 +0000)
Signed-off-by: Bernd Barsuhn <bernd.barsuhn@me.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
src/gpio/gpio.c

index 0319b6e..67ff5de 100644 (file)
@@ -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