(file) Return to CMPI_ThreadContext.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / CMPI

  1 schuur 1.1 //%2003////////////////////////////////////////////////////////////////////////
  2            //
  3            // Copyright (c) 2000, 2001, 2002  BMC Software, Hewlett-Packard Development
  4            // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
  6            // IBM Corp.; EMC Corporation, The Open Group.
  7            //
  8            // Permission is hereby granted, free of charge, to any person obtaining a copy
  9            // of this software and associated documentation files (the "Software"), to
 10            // deal in the Software without restriction, including without limitation the
 11            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 12            // sell copies of the Software, and to permit persons to whom the Software is
 13            // furnished to do so, subject to the following conditions:
 14            //
 15            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 16            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 17            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 18            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 19            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 20            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 21            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 22 schuur 1.1 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 23            //
 24            //==============================================================================
 25            //
 26            // Author:      Adrian Schuur, schuur@de.ibm.com
 27            //
 28            // Modified By:
 29            //
 30            //%/////////////////////////////////////////////////////////////////////////////
 31            
 32 schuur 1.3.2.1 #include "CMPI_Version.h"
 33 schuur 1.2     
 34 schuur 1.1     #include "CMPI_Object.h"
 35                
 36 schuur 1.3     #ifndef PEGASUS_PLATFORM_WIN32_IX86_MSVC
 37 schuur 1.1     #include <pthread.h>
 38 schuur 1.3     #endif
 39 schuur 1.1     #include <limits.h>
 40                
 41                
 42                PEGASUS_USING_STD;
 43                PEGASUS_NAMESPACE_BEGIN
 44                
 45 schuur 1.3     PEGASUS_THREAD_KEY_TYPE CMPI_ThreadContext::contextKey;
 46                int CMPI_ThreadContext::context_key_once=1;
 47 schuur 1.1     
 48                void CMPI_ThreadContext::context_key_alloc()
 49                {
 50 schuur 1.3     	pegasus_key_create(&contextKey);
 51 schuur 1.1     }
 52                
 53 schuur 1.3     PEGASUS_THREAD_KEY_TYPE CMPI_ThreadContext::getContextKey()
 54 schuur 1.1     {
 55 schuur 1.3     	if (context_key_once) {
 56                		 context_key_alloc();
 57                		 context_key_once=0;
 58                	}
 59 schuur 1.1         return contextKey;
 60                }
 61                
 62                void CMPI_ThreadContext::add(CMPI_Object *o) {
 63                   ENQ_TOP_LIST(o,CIMfirst,CIMlast,next,prev);
 64                }
 65                
 66                void CMPI_ThreadContext::addObject(CMPI_Object* o) {
 67                   CMPI_ThreadContext* ctx=getThreadContext();
 68                   ctx->add(o);
 69                }
 70                
 71                void CMPI_ThreadContext::remove(CMPI_Object *o) {
 72 schuur 1.3.2.2    if (reinterpret_cast<long>(o->next)!=-1) {
 73 schuur 1.1        DEQ_FROM_LIST(o,CIMfirst,CIMlast,next,prev);
 74 schuur 1.3.2.2       o->next=reinterpret_cast<CMPI_Object*>((void*)-1l);
 75                   }
 76 schuur 1.1     }
 77                
 78                void CMPI_ThreadContext::remObject(CMPI_Object* o) {
 79                   CMPI_ThreadContext* ctx=getThreadContext();
 80                   ctx->remove(o);
 81                }
 82                
 83                CMPI_ThreadContext* CMPI_ThreadContext::getThreadContext() {
 84 schuur 1.3        PEGASUS_THREAD_KEY_TYPE k=getContextKey();
 85 schuur 1.1        #ifndef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
 86 schuur 1.3         return (CMPI_ThreadContext*)pegasus_get_thread_specific(k);
 87 schuur 1.1        #else
 88                    CMPI_ThreadContext* tCtx=NULL;
 89                    pthread_getspecific(k,(void**)&tCtx);
 90                    return tCtx;
 91                   #endif
 92                }
 93                
 94                CMPIBroker* CMPI_ThreadContext::getBroker() {
 95                   return getThreadContext()->broker;
 96                }
 97                
 98                CMPIContext* CMPI_ThreadContext::getContext() {
 99                   return getThreadContext()->context;
100                }
101                
102                CMPI_ThreadContext::CMPI_ThreadContext(CMPIBroker *mb, CMPIContext *ctx ) {
103                   CIMfirst=CIMlast=NULL;
104                   broker=mb;
105                   context=ctx;
106 schuur 1.3        PEGASUS_THREAD_KEY_TYPE k=getContextKey();
107 schuur 1.1        #ifndef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
108 schuur 1.3          prev=(CMPI_ThreadContext*)pegasus_get_thread_specific(k);
109 schuur 1.1        #else
110                    pthread_getspecific(k,(void**)&prev);
111                   #endif
112 schuur 1.3        pegasus_set_thread_specific(k,this);
113 schuur 1.1        return;
114                }
115                
116                CMPI_ThreadContext::~CMPI_ThreadContext() {
117                   for (CMPI_Object *nxt,*cur=CIMfirst; cur; cur=nxt) {
118                      nxt=cur->next;
119                      ((CMPIInstance*)cur)->ft->release((CMPIInstance*)cur);
120                   }
121                
122 schuur 1.3        PEGASUS_THREAD_KEY_TYPE k=getContextKey();
123                   pegasus_set_thread_specific(k,prev);
124 schuur 1.1     }
125                
126                
127                PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2