Skip to content

Commit b394493

Browse files
committed
Terminate interrupt thread on NIF unload
This fixes an issue where the NIF could not be unloaded due to the interrupt monitoring thread never stopping. This would manifest itself in `:init.stop` taking a long time or it breaking `runtime.exs` due to a change that requires the VM to be restarted.
1 parent 9974f6b commit b394493

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/hal_sysfs_interrupts.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,12 @@ void *gpio_poller_thread(void *arg)
181181
// enif_monotonic_time only works in scheduler threads
182182
//ErlNifTime timestamp = enif_monotonic_time(ERL_NIF_NSEC);
183183

184-
if (fdset[count - 1].revents & (POLLIN | POLLHUP)) {
184+
short revents = fdset[count - 1].revents;
185+
if (revents & (POLLERR | POLLNVAL)) {
186+
// Socket closed so quit thread. This happens on NIF unload.
187+
break;
188+
}
189+
if (revents & (POLLIN | POLLHUP)) {
185190
struct gpio_monitor_info message;
186191
ssize_t amount_read = read(*pipefd, &message, sizeof(message));
187192
if (amount_read != sizeof(message)) {

0 commit comments

Comments
 (0)