00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "cmpisrv.h"
00024 #include <pthread.h>
00025 #include "OW_NonRecursiveMutex.hpp"
00026 #include "OW_NonRecursiveMutexLock.hpp"
00027 #include "OW_Format.hpp"
00028 #include "OW_ThreadImpl.hpp"
00029
00030 pthread_key_t CMPI_ThreadContext::theKey;
00031 namespace
00032 {
00033
00035 pthread_once_t once_control = PTHREAD_ONCE_INIT;
00036
00037 }
00038
00039 CMPI_ThreadContext* CMPI_ThreadContext::getThreadContext()
00040 {
00041
00042 pthread_once(&once_control, &initializeTheKey);
00043
00044 return (CMPI_ThreadContext*)pthread_getspecific(theKey);
00045 }
00046
00047 namespace OW_NAMESPACE
00048 {
00049 OW_DECLARE_EXCEPTION(CMPI_ThreadContext)
00050 OW_DEFINE_EXCEPTION(CMPI_ThreadContext)
00051 }
00052
00053 void CMPI_ThreadContext::setContext()
00054 {
00055
00056 pthread_once(&once_control, &initializeTheKey);
00057
00058 int rc = pthread_setspecific(theKey,this);
00059 if (rc != 0)
00060 OW_THROW(OpenWBEM::CMPI_ThreadContextException, OpenWBEM::Format("pthread_setspecific failed. error = %1", rc).c_str());
00061
00062
00063 }
00064
00065
00066 void CMPI_ThreadContext::setThreadContext()
00067 {
00068
00069 m_prev=getThreadContext();
00070
00071
00072 setContext();
00073 }
00074
00075 void CMPI_ThreadContext::add(CMPI_Object *o)
00076 {
00077 ENQ_TOP_LIST(o,CIMfirst,CIMlast,next,prev);
00078 }
00079
00080 void CMPI_ThreadContext::addObject(CMPI_Object* o)
00081 {
00082 CMPI_ThreadContext* ctx=getThreadContext();
00083 ctx->add(o);
00084 }
00085
00086 void CMPI_ThreadContext::remove(CMPI_Object *o)
00087 {
00088 DEQ_FROM_LIST(o,CIMfirst,CIMlast,next,prev);
00089 }
00090
00091 void CMPI_ThreadContext::remObject(CMPI_Object* o)
00092 {
00093 CMPI_ThreadContext* ctx=getThreadContext();
00094 ctx->remove(o);
00095 }
00096
00097 CMPIBroker * CMPI_ThreadContext::getBroker()
00098 {
00099 return getThreadContext()->broker;
00100 }
00101
00102 CMPIContext * CMPI_ThreadContext::getContext()
00103 {
00104 return getThreadContext()->context;
00105 }
00106
00107 CMPI_ThreadContext::CMPI_ThreadContext()
00108 : m_prev(0)
00109 , CIMfirst(0)
00110 , CIMlast(0)
00111 {
00112 setThreadContext();
00113 }
00114
00115 CMPI_ThreadContext::CMPI_ThreadContext(CMPIBroker * mb, CMPIContext * ctx)
00116 : m_prev(0)
00117 , CIMfirst(0)
00118 , CIMlast(0)
00119 , broker(mb)
00120 , context(ctx)
00121 {
00122 setThreadContext();
00123 }
00124
00125 CMPI_ThreadContext::~CMPI_ThreadContext()
00126 {
00127
00128 for (CMPI_Object *nxt,*cur=CIMfirst; cur; cur=nxt)
00129 {
00130 nxt=cur->next;
00131 ((CMPIInstance*)cur)->ft->release((CMPIInstance*)cur);
00132 }
00133
00134 pthread_setspecific(theKey, m_prev);
00135 }