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
|
34 schuur 1.1 #include "CMPI_Object.h"
35
36 #include <pthread.h>
37 #include <limits.h>
38
39
40 PEGASUS_USING_STD;
41 PEGASUS_NAMESPACE_BEGIN
42
43 //ulong CMPI_ThreadContext::hiKey=PTHREAD_KEYS_MAX+1;
44 pthread_key_t CMPI_ThreadContext::contextKey;
45 pthread_once_t CMPI_ThreadContext::context_key_once=PTHREAD_ONCE_INIT;
46
47 void CMPI_ThreadContext::context_key_alloc()
48 {
49 pthread_key_create(&contextKey,NULL);
50 }
51
52 pthread_key_t CMPI_ThreadContext::getContextKey()
53 {
54 pthread_once(&context_key_once,context_key_alloc);
55 schuur 1.1 return contextKey;
56 }
57
58 void CMPI_ThreadContext::add(CMPI_Object *o) {
59 ENQ_TOP_LIST(o,CIMfirst,CIMlast,next,prev);
60 }
61
62 void CMPI_ThreadContext::addObject(CMPI_Object* o) {
63 CMPI_ThreadContext* ctx=getThreadContext();
64 ctx->add(o);
65 }
66
67 void CMPI_ThreadContext::remove(CMPI_Object *o) {
68 DEQ_FROM_LIST(o,CIMfirst,CIMlast,next,prev);
69 }
70
71 void CMPI_ThreadContext::remObject(CMPI_Object* o) {
72 CMPI_ThreadContext* ctx=getThreadContext();
73 ctx->remove(o);
74 }
75
76 schuur 1.1 CMPI_ThreadContext* CMPI_ThreadContext::getThreadContext() {
77 pthread_key_t k=getContextKey();
78 // cerr<<"+++ pthread_key_t: "<<(void*)k<<endl;
79 #ifndef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
80 return (CMPI_ThreadContext*)pthread_getspecific(k);
81 #else
82 CMPI_ThreadContext* tCtx=NULL;
83 pthread_getspecific(k,(void**)&tCtx);
84 return tCtx;
85 #endif
86 }
87
88 CMPIBroker* CMPI_ThreadContext::getBroker() {
89 return getThreadContext()->broker;
90 }
91
92 CMPIContext* CMPI_ThreadContext::getContext() {
93 return getThreadContext()->context;
94 }
95
96 CMPI_ThreadContext::CMPI_ThreadContext(CMPIBroker *mb, CMPIContext *ctx ) {
97 schuur 1.1 CIMfirst=CIMlast=NULL;
98 broker=mb;
99 context=ctx;
100 // cerr<<"+++++++++++++++++++++++++"<<endl;
101 pthread_key_t k=getContextKey();
102 #ifndef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
103 prev=(CMPI_ThreadContext*)pthread_getspecific(k);
104 #else
105 pthread_getspecific(k,(void**)&prev);
106 #endif
107 if (prev) cerr<<"+++ OLD_DATA: "<<(void*)prev<<endl;
108 pthread_setspecific(k,this);
109 return;
110 }
111
112 CMPI_ThreadContext::~CMPI_ThreadContext() {
113 // cerr<<"-------------------------"<<endl;
114
115 for (CMPI_Object *nxt,*cur=CIMfirst; cur; cur=nxt) {
116 nxt=cur->next;
117 ((CMPIInstance*)cur)->ft->release((CMPIInstance*)cur);
118 schuur 1.1 }
119
120 pthread_key_t k=getContextKey();
121 pthread_setspecific(k,prev);
122 }
123
124
125 PEGASUS_NAMESPACE_END
|