# HG changeset patch # User Michiel Broek # Date 1426793543 -3600 # Node ID 5d3670aafd1b7699f25e9b94aadce060b8f3c46f # Parent 217f330b05cb82bb3cbe01fff73da6fcaa03eb6e More global device locking diff -r 217f330b05cb -r 5d3670aafd1b thermferm/devices.c --- a/thermferm/devices.c Wed Mar 18 14:45:43 2015 +0100 +++ b/thermferm/devices.c Thu Mar 19 20:32:23 2015 +0100 @@ -178,6 +178,10 @@ now = time(NULL); +#ifdef HAVE_WIRINGPI_H + piLock(LOCK_DEVICES); +#endif + for (device = Config.devices; device; device = device->next) { if (! strcmp(uuid, device->uuid)) { /* @@ -185,14 +189,8 @@ * every 2 minutes because commands can have temporary * disconnects, or have radio problems. */ -#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 @@ -202,13 +200,14 @@ for (i = 0; i < strlen(buf); i++) if (buf[i] == '-') buf[i] = ','; + piUnlock(LOCK_DEVICES); enableTransmit(device->gpiopin); rc = toggleSwitch(buf); disableTransmit(); + piLock(LOCK_DEVICES); syslog(LOG_NOTICE, "RC433 command %s rc=%d", buf, rc); if (debug) fprintf(stdout, "RC433 command %s rc=%d\n", buf, rc); - piLock(LOCK_DEVICES); device->value = value; device->timestamp = time(NULL); piUnlock(LOCK_DEVICES); @@ -228,10 +227,16 @@ } #endif } else { +#ifdef HAVE_WIRINGPI_H + piUnlock(LOCK_DEVICES); +#endif return 0; } } } +#ifdef HAVE_WIRINGPI_H + piUnlock(LOCK_DEVICES); +#endif return 0; }