void *isr_args; /**< args return when interupt service request triggered */
pthread_t thread_id; /**< the isr handler thread id */
int isr_value_fp; /**< the isr file pointer on the value */
+ mraa_boolean_t isr_thread_terminating; /**< is the isr thread being terminated? */
mraa_boolean_t owner; /**< If this context originally exported the pin */
mraa_result_t (*mmap_write) (mraa_gpio_context dev, int value);
int (*mmap_read) (mraa_gpio_context dev);
dev->value_fp = -1;
dev->isr_value_fp = -1;
+ dev->isr_thread_terminating = 0;
dev->phy_pin = -1;
// then check to make sure the pin is exported.
for (;;) {
ret = mraa_gpio_wait_interrupt(dev->isr_value_fp);
- if (ret == MRAA_SUCCESS) {
+ if (ret == MRAA_SUCCESS && !dev->isr_thread_terminating) {
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
#ifdef SWIGPYTHON
// In order to call a python object (all python functions are objects) we
#endif
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
} else {
- // we must have got an error code so die nicely
+ // we must have got an error code or exit request so die nicely
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
close(dev->isr_value_fp);
dev->isr_value_fp = -1;
if (dev->thread_id == 0 && dev->isr_value_fp == -1) {
return ret;
}
+ // mark the beginning of the thread termination process for interested parties
+ dev->isr_thread_terminating = 1;
// stop isr being useful
ret = mraa_gpio_edge_mode(dev, MRAA_GPIO_EDGE_NONE);
// assume our thread will exit either way we just lost it's handle
dev->thread_id = 0;
dev->isr_value_fp = -1;
+ dev->isr_thread_terminating = 0;
return ret;
}