@@ -721,18 +721,52 @@ int wiringPiISR (int pin, int mode, void (*function)(void))
721721 fprintf (stderr , "Unable to read from the sysfs GPIO node: %s \n" , strerror (errno ));
722722 }
723723
724- libwiring .isrFunctions [PIN_NUM_CALC_SYSFD (GpioPin )] = function ;
725-
726724 pthread_mutex_lock (& pinMutex ) ;
727725 pinPass = GpioPin ;
728726 pthread_create (& threadId , NULL , interruptHandler , NULL ) ;
729727 while (pinPass != -1 )
730728 delay (1 ) ;
731729 pthread_mutex_unlock (& pinMutex ) ;
732730
731+ libwiring .isrFunctions [PIN_NUM_CALC_SYSFD (GpioPin )] = function ;
732+ libwiring .isrThreadIds [PIN_NUM_CALC_SYSFD (GpioPin )] = threadId ;
733+
733734 return 0 ;
734735}
735736
737+ /*----------------------------------------------------------------------------*/
738+ int wiringPiISRCancel (int pin ) {
739+ int GpioPin = -1 ;
740+
741+ if (libwiring .mode == MODE_UNINITIALISED )
742+ return wiringPiFailure (
743+ WPI_FATAL ,
744+ "wiringPiISRCancel: wiringPi has not been initialised. " \
745+ "Unable to continue.\n" ) ;
746+
747+ if (libwiring .getModeToGpio )
748+ GpioPin = libwiring .getModeToGpio (libwiring .mode , pin );
749+ else
750+ return wiringPiFailure (
751+ WPI_FATAL ,
752+ "%s: getModeToGpio function not initialize!\n" ,
753+ __func__ );
754+
755+ pthread_t threadId = libwiring .isrThreadIds [PIN_NUM_CALC_SYSFD (GpioPin )];
756+
757+ if (pthread_cancel (threadId ) < 0 )
758+ return wiringPiFailure (
759+ WPI_FATAL ,
760+ "%s: wiringPiISRCancel: Unregister for the interrupt pin failed!\n" ,
761+ __func__ );
762+ else {
763+ libwiring .isrFunctions [PIN_NUM_CALC_SYSFD (GpioPin )] = NULL ;
764+ libwiring .isrThreadIds [PIN_NUM_CALC_SYSFD (GpioPin )] = 0 ;
765+ }
766+
767+ return 0 ;
768+ }
769+
736770/*----------------------------------------------------------------------------*/
737771static void initialiseEpoch (void )
738772{
0 commit comments