Changed zigbee sample to use signal-atomic
authorJoseph Morrow <joseph.l.morrow@intel.com>
Sat, 19 Sep 2015 03:27:03 +0000 (20:27 -0700)
committerPatrick Lankswert <patrick.lankswert@intel.com>
Sun, 20 Sep 2015 05:42:20 +0000 (05:42 +0000)
The signal atomic type is more reliable than bool, since it is
guaranteed to enforce thread safety. Also fixed the logic in the 'while'
loop so that this will function properly when the calls work.

Change-Id: I1ef4713f9e894592b1b25c874327bce810c83352
Signed-off-by: Joseph Morrow <joseph.l.morrow@intel.com>
Signed-off-by: Erich Keane <erich.keane@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2769
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Patrick Lankswert <patrick.lankswert@intel.com>
plugins/samples/linux/IotivityandZigbeeServer.c

index 3b66e64..443d6c8 100644 (file)
@@ -79,7 +79,7 @@ int main(int argc, char* argv[])
     {
         OC_LOG(INFO, TAG, "Zigbee Plugin started correctly, press Ctrl-C to terminate application");
         // Loop until sigint
-        while (processSignal(false) && result == OC_STACK_OK)
+        while (!processSignal(false) && result == OC_STACK_OK)
         {
             result = OCProcess();
             if (result != OC_STACK_OK)
@@ -150,16 +150,13 @@ OCStackResult SetDeviceInfo()
 
 bool processSignal(bool set)
 {
-    static bool signal = false;
+    static sig_atomic_t signal = 0;
     if (set)
     {
-        // boolean assignments are atomic, and since we
-        // only have a single modifier, and only in one direction,
-        // this does not require locking.
-        signal = true;
+        signal = 1;
     }
 
-    return signal;
+    return signal == 1;
 }
 
 void processCancel(int signal)