-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrokerOs.c
298 lines (266 loc) · 6.39 KB
/
brokerOs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*
* brokerOs.c
*
* (C) Copyright IBM Corp. 2005
*
* THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
* ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
* CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
*
* You can obtain a current copy of the Eclipse Public License from
* http://www.opensource.org/licenses/eclipse-1.0.php
*
* Author: Adrian Schuur <[email protected]>
*
* Description:
*
* This module implements OS dependent CMPI broker functions.
*
*/
#include <pthread.h>
#include "native.h"
#include <stdlib.h>
static char *
resolveFileName(const char *filename)
{
char dlName[1024];
#if defined(CMPI_PLATFORM_WIN32_IX86_MSVC)
strcpy(dlName, filename);
strcat(dlName, ".dll");
#elif defined(CMPI_PLATFORM_LINUX_GENERIC_GNU)
strcpy(dlName, "lib");
strcat(dlName, filename);
strcat(dlName, ".so");
#elif defined(CMPI_OS_HPUX)
#ifdef CMPI_PLATFORM_HPUX_PARISC_ACC
strcpy(dlName, "lib");
strcat(dlName, filename);
strcat(dlName, ".so");
#else
strcpy(dlName, "lib");
strcat(dlName, filename);
strcat(dlName, ".so");
#endif
#elif defined(CMPI_OS_OS400)
strcpy(dlName, filename);
#elif defined(CMPI_OS_DARWIN)
strcpy(dlName, "lib");
strcat(dlName, filename);
strcat(dlName, ".dylib");
#else
strcpy(dlName, "lib");
strcat(dlName, filename);
strcat(dlName, ".so");
#endif
return strdup(dlName);
}
static CMPI_THREAD_TYPE newThread
(CMPI_THREAD_RETURN(CMPI_THREAD_CDECL * start) (void *), void *parm,
int detached) {
#if defined(CMPI_PLATFORM_LINUX_GENERIC_GNU)
pthread_t t;
pthread_attr_t tattr;
if (detached) {
pthread_attr_init(&tattr);
pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
pthread_create(&t, &tattr, (void *(*)(void *)) start, parm);
} else
pthread_create(&t, NULL, (void *(*)(void *)) start, parm);
return (CMPI_THREAD_TYPE) t;
#else
#error Platform not yet supported
#endif
}
static int
threadOnce(int *once, void (*init) (void))
{
#if defined(CMPI_PLATFORM_LINUX_GENERIC_GNU)
return pthread_once(once, init);
#else
#error Platform not yet supported
#endif
}
static int
createThreadKey(CMPI_THREAD_KEY_TYPE * key, void (*cleanup) (void *))
{
#if defined(CMPI_PLATFORM_LINUX_GENERIC_GNU)
return pthread_key_create((pthread_key_t *) key, cleanup);
#else
#error Platform not yet supported
#endif
}
static int
destroyThreadKey(CMPI_THREAD_KEY_TYPE key)
{
#if defined(CMPI_PLATFORM_LINUX_GENERIC_GNU)
return pthread_key_delete(key);
#else
#error Platform not yet supported
#endif
}
static void *
getThreadSpecific(CMPI_THREAD_KEY_TYPE key)
{
#if defined(CMPI_PLATFORM_LINUX_GENERIC_GNU)
return pthread_getspecific(key);
#else
#error Platform not yet supported
#endif
}
static int
setThreadSpecific(CMPI_THREAD_KEY_TYPE key, void *value)
{
#if defined(CMPI_PLATFORM_LINUX_GENERIC_GNU)
return pthread_setspecific(key, value);
#else
#error Platform not yet supported
#endif
}
static CMPI_MUTEX_TYPE
newMutex(int opt)
{
#if defined(CMPI_PLATFORM_LINUX_GENERIC_GNU)
static pthread_mutex_t tmpl = PTHREAD_MUTEX_INITIALIZER;
int state = 0;
pthread_mutex_t *m =
memAlloc(MEM_TRACKED, sizeof(pthread_mutex_t), &state);
*m = tmpl;
return m;
#else
#error Platform not yet supported
#endif
}
static void
destroyMutex(CMPI_MUTEX_TYPE m)
{
#if defined(CMPI_PLATFORM_LINUX_GENERIC_GNU)
free(m);
#else
#error Platform not yet supported
#endif
}
static void
lockMutex(CMPI_MUTEX_TYPE m)
{
#if defined(CMPI_PLATFORM_LINUX_GENERIC_GNU)
pthread_mutex_lock((pthread_mutex_t *) m);
#else
#error Platform not yet supported
#endif
}
static void
unlockMutex(CMPI_MUTEX_TYPE m)
{
#if defined(CMPI_PLATFORM_LINUX_GENERIC_GNU)
pthread_mutex_unlock((pthread_mutex_t *) m);
#else
#error Platform not yet supported
#endif
}
static CMPI_COND_TYPE
newCondition(int opt)
{
#if defined(CMPI_PLATFORM_LINUX_GENERIC_GNU)
pthread_cond_t tmpl = PTHREAD_COND_INITIALIZER;
pthread_cond_t *c = calloc(1, sizeof(pthread_cond_t));
*c = tmpl;
return c;
#else
#error Platform not yet supported
#endif
}
static void
destroyCondition(CMPI_COND_TYPE c)
{
#if defined(CMPI_PLATFORM_LINUX_GENERIC_GNU)
free(c);
#else
#error Platform not yet supported
#endif
}
static int
timedCondWait(CMPI_COND_TYPE c, CMPI_MUTEX_TYPE m, struct timespec *wait)
{
#if defined(CMPI_PLATFORM_LINUX_GENERIC_GNU)
return pthread_cond_timedwait((pthread_cond_t *) c,
(pthread_mutex_t *) m, wait);
#else
#error Platform not yet supported
#endif
}
static int
condWait(CMPI_COND_TYPE c, CMPI_MUTEX_TYPE m)
{
#if defined(CMPI_PLATFORM_LINUX_GENERIC_GNU)
return pthread_cond_wait((pthread_cond_t *) c, (pthread_mutex_t *) m);
#else
#error Platform not yet supported
#endif
}
CMPIBrokerExtFT brokerExt_FT = {
CMPICurrentVersion,
resolveFileName,
newThread,
NULL, // Join not implemented yet
NULL, // exit not implemented yet
NULL, // cancel not implemented yet
NULL, // sleep not implemented yet
threadOnce,
createThreadKey,
destroyThreadKey,
getThreadSpecific,
setThreadSpecific,
newMutex,
destroyMutex,
lockMutex,
unlockMutex,
newCondition,
destroyCondition,
condWait,
timedCondWait,
NULL // Signal not supported yet
};
CMPIBrokerExtFT *CMPI_BrokerExt_Ftab = &brokerExt_FT;
/*
* -----------------------------------------------
* CMPIBrokerMemFT -memory specific CIMOM routines
* ------------------------------------------------
*/
extern void *markHeap();
extern void releaseHeap(void *);
/* The following two are wrappers for markHeap() and releaseHeap()
* in support.c which allows for provider calls via broker->mft functions
*/
static CMPIGcStat *mark(const CMPIBroker *mb, CMPIStatus *rc)
{
return((CMPIGcStat *)markHeap());
}
static CMPIStatus release(const CMPIBroker *mb, const CMPIGcStat *gc)
{
CMPIStatus st = {CMPI_RC_OK, NULL};
releaseHeap((void *)gc);
return(st);
}
CMPIBrokerMemFT brokerMem_FT = {
CMPICurrentVersion,
mark,
release,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
CMPIBrokerMemFT *CMPI_BrokerMem_Ftab = &brokerMem_FT;
/* MODELINES */
/* DO NOT EDIT BELOW THIS COMMENT */
/* Modelines are added by 'make pretty' */
/* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil; -*- */
/* vi:set ts=2 sts=2 sw=2 expandtab: */