Skip to content

Commit a764f57

Browse files
committed
Events should be non-reentrant #72
1 parent 5c8db6b commit a764f57

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

source/py_gpio.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ static void run_py_callbacks(unsigned int gpio)
185185
gettimeofday(&tv_timenow, NULL);
186186
timenow = tv_timenow.tv_sec*1E6 + tv_timenow.tv_usec;
187187
if (cb->bouncetime == 0 || timenow - cb->lastcall > cb->bouncetime*1000 || cb->lastcall == 0 || cb->lastcall > timenow) {
188+
189+
// save lastcall before calling func to prevent reentrant bounce
190+
cb->lastcall = timenow;
191+
188192
// run callback
189193
gstate = PyGILState_Ensure();
190194
result = PyObject_CallFunction(cb->py_cb, "s", cb->channel);

0 commit comments

Comments
 (0)