BUG#: 8582
authorvenkat.puvvada <venkat.puvvada>
Fri, 7 Aug 2009 14:33:53 +0000 (14:33 +0000)
committervenkat.puvvada <venkat.puvvada>
Fri, 7 Aug 2009 14:33:53 +0000 (14:33 +0000)
TITLE: multiple creations of CMPI_ThreadContext::contextKey
DESCRIPTION: Serialized creation of CMPI_ThreadContext::contextKey using Once class.

src/Pegasus/ProviderManager2/CMPI/CMPI_ThreadContext.cpp
src/Pegasus/ProviderManager2/CMPI/CMPI_ThreadContext.h

index fa59000726b0cbfed834e86301f63ac495be8254..31ff589f2090520c9281dd75ce48c9a0c4b64ff2 100644 (file)
@@ -43,7 +43,7 @@ PEGASUS_USING_STD;
 PEGASUS_NAMESPACE_BEGIN
 
 TSDKeyType CMPI_ThreadContext::contextKey;
-int CMPI_ThreadContext::context_key_once=1;
+Once CMPI_ThreadContext::contextKeyOnce = PEGASUS_ONCE_INITIALIZER;
 
 void CMPI_ThreadContext::context_key_alloc()
 {
@@ -52,11 +52,7 @@ void CMPI_ThreadContext::context_key_alloc()
 
 TSDKeyType CMPI_ThreadContext::getContextKey()
 {
-    if( context_key_once )
-    {
-        context_key_alloc();
-        context_key_once=0;
-    }
+    once(&contextKeyOnce, context_key_alloc);
     return contextKey;
 }
 
index 6b3200d7fefea7b1a3067d6ee374a2dba7258e3d..99da0ab70f59ec1d527b8bf3925917d1b93a4d14 100644 (file)
@@ -39,6 +39,7 @@
 #endif
 
 #include <Pegasus/Common/TSDKey.h>
+#include <Pegasus/Common/Once.h>
 #include <Pegasus/Provider/CMPI/cmpidt.h>
 #include <Pegasus/Provider/CMPI/cmpift.h>
 
@@ -60,7 +61,7 @@ class CMPI_ThreadContext
        static pthread_key_t contextKey;
     */
     static TSDKeyType contextKey;
-    static int context_key_once;
+    static Once contextKeyOnce;
     static void context_key_alloc();
     /**
        static pthread_key_t getContextKey();