~ubuntu-branches/ubuntu/trusty/sblim-sfcb/trusty-proposed

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
/*
 * $Id: support.h,v 1.14 2007/04/27 09:11:07 sschuetz Exp $
 *
 * support.h
 *
 * (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:        Frank Scheffler
 * Contributions: Adrian Schuur <schuur@de.ibm.com>
 *
 * Description: Various memory management and provider support routines.
 *
 */

/** @file support.h
 *  @brief Memory managment system and support routines for providers.
 *
 *  @author Frank Scheffler
 *
 *  @sa support.c
 *  @sa native.h
 */

#ifndef CMPI_TOOL_H
#define CMPI_TOOL_H

#include "cmpidt.h"
#include "cmpift.h"
#include "cmpiftx.h"
#include "cmpimacs.h"
#include <time.h>
#include <sys/time.h>
#include <dlfcn.h>

#define ENQ_BOT_LIST(i,f,l,n,p) { if (l) l->n=i; else f=i; \
                                  i->p=l; i->n=NULL; l=i;}
#define ENQ_TOP_LIST(i,f,l,n,p) { if (f) f->p=i; else l=i; \
                                   i->p=NULL; i->n=f; f=i;}
#define DEQ_FROM_LIST(i,f,l,n,p) \
                    { if (i->n) i->n->p=i->p; else l=i->p; \
                      if (i->p) i->p->n=i->n; else f=i->n;}

CMPIClassMI *loadClassMI(const char *provider,
			 void *library,
			 CMPIBroker * broker,
			 CMPIContext * ctx);

CMPIMethodMI *loadMethodMI(const char *provider,
			   void *library,
			   CMPIBroker * broker, 
			   CMPIContext * ctx);

CMPIPropertyMI *loadPropertyMI(const char *provider,
			       void *library,
			       CMPIBroker * broker, 
			       CMPIContext * ctx);

CMPIInstanceMI *loadInstanceMI(const char *provider,
			       void *library,
			       CMPIBroker * broker, 
			       CMPIContext * ctx);

CMPIIndicationMI *loadIndicationMI(const char *provider,
				   void *library,
				   CMPIBroker * broker,
				   CMPIContext * ctx);

CMPIAssociationMI *loadAssociationMI(const char *provider,
				     void *library,
				     CMPIBroker * broker,
				     CMPIContext * ctx);

CMPIQualifierDeclMI *loadQualifierDeclMI(const char *provider,
                                         void *library,
                                         CMPIBroker * broker,
                                         CMPIContext * ctx);                                         

/** @def MEM_NOT_TRACKED
 *
 *  Cloned object state in which memory is not tracked. 
 */

/** @def MEM_TRACKED
 *
 *  State in which memory is being tracked.
 */

/** @def MEM_RELEASED
 *
 *  State in which previously tracked memory has been released.
 */

/** @def MT_SIZE_STEP
 *
 *  The initial size of trackable memory pointers per thread. This size is
 *  incremented by the same amount once the limit is reached.
 */

/** @struct ObjectFT
 *  @brief Function table for generic object wrapper
 *
 *  This structure contains the function table for operating on generic objects. 
 */

/** @struct Object
 *  @brief Generic object structure
 *
 *  This structure is a generic wrapper for the underlying object implementation.
 */

/** @var typedef struct _managed_thread managed_thread
 *  @brief Per-Thread heap management structure.
 *
 *  @sa _managed_thread
 */

/** @struct _managed_thread
 *  @brief Per-Thread heap management structure.
 *
 *  This struct is used for managing the heap bound to the current thread.
 */

/** @var typedef struct heapControl HeapControl
 *  @brief Heap management structure.
 *
 *  @sa heapControl
 */

/** @struct heapControl
 *  @brief Heap management structure.
 *
 *  This struct is returned using a global pthread_key_t and stores all allocated
 *  objects that are going to be freed, once the thread is flushed or dies.
 */

#define MEM_NOT_TRACKED -2
#define MEM_TRACKED   1
#define MEM_RELEASED -1

#define MT_SIZE_STEP 100

typedef struct {
   int ftVersion;                    /**< function table version */
   CMPIStatus(*release) (void *obj); /**< function pointer to generic object release function 
				      *   @param obj generic object to be freed */
} ObjectFT;


typedef struct {
   void *hdl;                        /**< pointer to underlying object implementation */
   ObjectFT *ft;                     /**< pointer to generic object function table */
} Object;

typedef struct _managed_thread managed_thread;

typedef struct heapControl {
   unsigned memSize;                 /**< current maximum number of tracked object pointers */
   unsigned memUsed;                 /**< number of currently tracked object pointers */
   void **memObjs;                   /**< pointers to object allocations */
   unsigned memEncUsed;              /**< current maximum number of tracked encapsulated object pointers */
   unsigned memEncSize;              /**< number of currently tracked encapsulated object pointers */
   Object **memEncObjs;              /**< pointers to encapsulated object allocations */
} HeapControl;
 
struct _managed_thread {
   void *broker;
   void *ctx;                        /**< pointer to current thread context */
   void *data;
   HeapControl hc;                   /**< heap control structure for this thread */
   int   cleanupDone;                /**< cleanup state */
};



void *tool_mm_load_lib(const char *libname);

void tool_mm_flush();
void *tool_mm_alloc(int, size_t);
void *tool_mm_realloc(void *, size_t);
int tool_mm_add(void *);
void tool_mm_set_broker(void *, void *);
int tool_mm_remove(void *);
void *tool_mm_get_broker(void **);

int memAdd(void *ptr, int *memId);
void *memAlloc(int add, size_t size, int *memId);
void *memAddEncObj(int mode, void *ptr, size_t size, int *memId);
void memUnlinkEncObj(int memId);
void memLinkEncObj(void *ptr, int *memId);
void memLinkInstance(CMPIInstance *ci);

void * markHeap();
void releaseHeap(void * heap);


typedef struct cntlVals {
   int type;
   char *id;
   char *val;
} CntlVals;

void cntlSkipws(char **p);
int cntlParseStmt(char *in, CntlVals * rv);
char *cntlGetVal(CntlVals * rv);
char *cntlGetStr(CntlVals * rv);

int uninit_sfcBroker();
void uninitGarbageCollector();

extern double timevalDiff(struct timeval *sv, struct timeval *ev);

#define PADDING_LEN(s) ( (s)%sizeof(int) ? sizeof(int) - (s)%sizeof(int) : 0)
#define PADDED_LEN(s) ((s) + PADDING_LEN(s))

#endif