PEGASUS_USING_STD;
PEGASUS_NAMESPACE_BEGIN
-TSDKeyType CMPI_ThreadContext::contextKey;
-Once CMPI_ThreadContext::contextKeyOnce = PEGASUS_ONCE_INITIALIZER;
+// this static gets initialized on load of CMPIProviderManager library
+// in the constructor of CMPI_ThreadContextKey the key for the thread-specific
+// storage used by CMPI is created
+// This was done to ensure that the key gets created exactly once, saving the
+// need to check for it on later access.
+CMPI_ThreadContextKey CMPI_ThreadContext::globalThreadContextKey;
CMPI_ThreadContext::CMPI_ThreadContext(
const CMPIBroker *mb,
CIMfirst=CIMlast=NULL;
broker=mb;
context=ctx;
- TSDKeyType k=getContextKey();
- prev=(CMPI_ThreadContext*)TSDKey::get_thread_specific(k);
- TSDKey::set_thread_specific(k,this);
+ prev=(CMPI_ThreadContext*)
+ TSDKey::get_thread_specific(globalThreadContextKey.contextKey);
+ TSDKey::set_thread_specific(globalThreadContextKey.contextKey,this);
return;
}
(reinterpret_cast<CMPIInstance*>(cur))->ft->release(
reinterpret_cast<CMPIInstance*>(cur));
}
-
- TSDKeyType k=getContextKey();
- TSDKey::set_thread_specific(k,prev);
+ TSDKey::set_thread_specific(globalThreadContextKey.contextKey,prev);
}
PEGASUS_NAMESPACE_END
#endif
#include <Pegasus/Common/TSDKey.h>
-#include <Pegasus/Common/Once.h>
#include <Pegasus/Provider/CMPI/cmpidt.h>
#include <Pegasus/Provider/CMPI/cmpift.h>
#include "CMPI_Object.h"
{ if (i->n) i->n->p=i->p; else l=i->p; \
if (i->p) i->p->n=i->n; else f=i->n;}
+class CMPI_ThreadContextKey
+{
+public:
+ CMPI_ThreadContextKey()
+ {
+ TSDKey::create(&contextKey);
+ };
+ ~CMPI_ThreadContextKey()
+ {
+ TSDKey::destroy(contextKey);
+ };
+ TSDKeyType contextKey;
+};
+
class CMPI_ThreadContext
{
- /**
- static pthread_key_t contextKey;
- */
- static TSDKeyType contextKey;
- static Once contextKeyOnce;
- static void context_key_alloc();
- /**
- static pthread_key_t getContextKey();
- */
- static TSDKeyType getContextKey();
CMPI_ThreadContext* prev;
const CMPIBroker *broker;
const CMPIContext *context;
*/
CMPI_ThreadContext(const CMPIBroker*,const CMPIContext*);
~CMPI_ThreadContext();
+
+ static CMPI_ThreadContextKey globalThreadContextKey;
};
PEGASUS_NAMESPACE_END
PEGASUS_NAMESPACE_BEGIN
-inline void CMPI_ThreadContext::context_key_alloc()
-{
- TSDKey::create(&contextKey);
-}
-
-inline TSDKeyType CMPI_ThreadContext::getContextKey()
-{
- once(&contextKeyOnce, context_key_alloc);
- return contextKey;
-}
-
inline void CMPI_ThreadContext::add(CMPI_Object *o)
{
ENQ_TOP_LIST(o,CIMfirst,CIMlast,next,prev);
inline CMPI_ThreadContext* CMPI_ThreadContext::getThreadContext()
{
- TSDKeyType k=getContextKey();
- return(CMPI_ThreadContext*)TSDKey::get_thread_specific(k);
+ return (CMPI_ThreadContext*)
+ TSDKey::get_thread_specific(globalThreadContextKey.contextKey);
}
inline const CMPIBroker* CMPI_ThreadContext::getBroker()