Added extra lock

Sat, 07 Mar 2015 11:33:10 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 07 Mar 2015 11:33:10 +0100
changeset 323
608592f74b10
parent 322
1dc57faf5ab5
child 324
940a668e568f

Added extra lock

thermferm/devices.c file | annotate | diff | comparison | revisions
--- a/thermferm/devices.c	Fri Feb 20 16:07:39 2015 +0100
+++ b/thermferm/devices.c	Sat Mar 07 11:33:10 2015 +0100
@@ -166,7 +166,8 @@
 int device_out(char *uuid, int value)
 {
     devices_list	*device;
-    time_t		now;
+    time_t		now, my_timestamp;
+    int			my_value;
 #ifdef HAVE_WIRINGPI_H
     int			i, rc;
     char		buf[40];
@@ -184,7 +185,15 @@
 	     * every 2 minutes because commands can have temporary
 	     * disconnects, or have radio problems.
 	     */
-	    if ((value != device->value) || (((int)now - (int)device->timestamp) > 120)) {
+#ifdef HAVE_WIRINGPI_H
+	    piLock(LOCK_DEVICES);
+#endif
+	    my_timestamp = device->timestamp;
+	    my_value = device->value;
+#ifdef HAVE_WIRINGPI_H
+	    piUnlock(LOCK_DEVICES);
+#endif
+	    if ((value != my_value) || (((int)now - (int)my_timestamp) > 120)) {
 
 #ifdef HAVE_WIRINGPI_H
 		rc = 0;

mercurial