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.4 #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.5 if (reinterpret_cast<long>(o->next)!=-1) {
73 DEQ_FROM_LIST(o,CIMfirst,CIMlast,next,prev);
74 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 konrad.r 1.6 //return getThreadContext()->broker;
96 CMPI_ThreadContext *ctx = getThreadContext();
97 if (ctx)
98 return ctx->broker;
99 return 0;
|
100 schuur 1.1 }
101
102 CMPIContext* CMPI_ThreadContext::getContext() {
103 return getThreadContext()->context;
104 }
105
106 CMPI_ThreadContext::CMPI_ThreadContext(CMPIBroker *mb, CMPIContext *ctx ) {
107 CIMfirst=CIMlast=NULL;
108 broker=mb;
109 context=ctx;
|
110 schuur 1.3 PEGASUS_THREAD_KEY_TYPE k=getContextKey();
|
111 schuur 1.1 #ifndef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
|
112 schuur 1.3 prev=(CMPI_ThreadContext*)pegasus_get_thread_specific(k);
|
113 schuur 1.1 #else
114 pthread_getspecific(k,(void**)&prev);
115 #endif
|
116 schuur 1.3 pegasus_set_thread_specific(k,this);
|
117 schuur 1.1 return;
118 }
119
120 CMPI_ThreadContext::~CMPI_ThreadContext() {
121 for (CMPI_Object *nxt,*cur=CIMfirst; cur; cur=nxt) {
122 nxt=cur->next;
123 ((CMPIInstance*)cur)->ft->release((CMPIInstance*)cur);
124 }
125
|
126 schuur 1.3 PEGASUS_THREAD_KEY_TYPE k=getContextKey();
127 pegasus_set_thread_specific(k,prev);
|
128 schuur 1.1 }
129
130
131 PEGASUS_NAMESPACE_END
|