mirror of https://github.com/joan2937/pigpio
V68+: #261 close gpio ISR fd when ISR cancelled.
This commit is contained in:
parent
3ea6fd94fd
commit
7ef99aee42
12
pigpio.c
12
pigpio.c
|
@ -970,6 +970,7 @@ typedef struct
|
||||||
int timeout;
|
int timeout;
|
||||||
unsigned ex;
|
unsigned ex;
|
||||||
void *userdata;
|
void *userdata;
|
||||||
|
int fd;
|
||||||
int inited;
|
int inited;
|
||||||
} gpioISR_t;
|
} gpioISR_t;
|
||||||
|
|
||||||
|
@ -11477,12 +11478,16 @@ static void *pthISRThread(void *x)
|
||||||
|
|
||||||
sprintf(buf, "/sys/class/gpio/gpio%d/value", isr->gpio);
|
sprintf(buf, "/sys/class/gpio/gpio%d/value", isr->gpio);
|
||||||
|
|
||||||
|
isr->fd = -1; /* no fd assigned */
|
||||||
|
|
||||||
if ((fd = open(buf, O_RDONLY)) < 0)
|
if ((fd = open(buf, O_RDONLY)) < 0)
|
||||||
{
|
{
|
||||||
DBG(DBG_ALWAYS, "gpio %d not exported", isr->gpio);
|
DBG(DBG_ALWAYS, "gpio %d not exported", isr->gpio);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isr->fd = fd; /* store fd so it can be closed */
|
||||||
|
|
||||||
pfd.fd = fd;
|
pfd.fd = fd;
|
||||||
|
|
||||||
pfd.events = POLLPRI;
|
pfd.events = POLLPRI;
|
||||||
|
@ -11602,6 +11607,13 @@ static int intGpioSetISRFunc(
|
||||||
if (gpioISR[gpio].pth) /* delete any existing ISR */
|
if (gpioISR[gpio].pth) /* delete any existing ISR */
|
||||||
{
|
{
|
||||||
gpioStopThread(gpioISR[gpio].pth);
|
gpioStopThread(gpioISR[gpio].pth);
|
||||||
|
|
||||||
|
if (gpioISR[gpio].fd >= 0)
|
||||||
|
{
|
||||||
|
close(gpioISR[gpio].fd);
|
||||||
|
gpioISR[gpio].fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
gpioISR[gpio].func = NULL;
|
gpioISR[gpio].func = NULL;
|
||||||
gpioISR[gpio].pth = NULL;
|
gpioISR[gpio].pth = NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue