check Cmi_state_key against -1 before calling pthread_getspecific
authorGengbin Zheng <gzheng@illinois.edu>
Sat, 1 Sep 2012 06:11:07 +0000 (01:11 -0500)
committerGengbin Zheng <gzheng@illinois.edu>
Sat, 1 Sep 2012 06:11:07 +0000 (01:11 -0500)
src/arch/util/machine-smp.c

index 1f94e81716ad6176fefa27263fe381f968301921..6e562704aa3c3b02ea98bfc93a6cbf0f50f2ab4c 100644 (file)
@@ -285,11 +285,10 @@ static CmiState     Cmi_state_vector;
 #define CmiGetState() ((CmiState)pthread_getspecific(Cmi_state_key))
 #else
 CmiState CmiGetState() {
-       CmiState ret=(CmiState)pthread_getspecific(Cmi_state_key);
-       if (ret==NULL || Cmi_state_key == (pthread_key_t)(-1)) {
-               return &Cmi_default_state;
-       }
-       return ret;
+       CmiState ret;
+       if (Cmi_state_key == (pthread_key_t)(-1)) return &Cmi_default_state;
+       ret=(CmiState)pthread_getspecific(Cmi_state_key);
+       return (ret==NULL)? &Cmi_default_state : ret;
 }
 
 #endif