Browse code

shm duplication functions

Jan Janak authored on 07/04/2003 11:48:26
Showing 4 changed files
... ...
@@ -38,6 +38,7 @@
38 38
 #include "../dprint.h"
39 39
 #include "../trim.h"
40 40
 #include "../mem/mem.h"
41
+#include "../mem/shm_mem.h"
41 42
 #include "parse_param.h"
42 43
 
43 44
 
... ...
@@ -369,15 +370,34 @@ int parse_params(str* _s, pclass_t _c, param_hooks_t* _h, param_t** _p)
369 369
 /*
370 370
  * Free linked list of parameters
371 371
  */
372
-void free_params(param_t* _p)
372
+static inline void do_free_params(param_t* _p, int _shm)
373 373
 {
374 374
 	param_t* ptr;
375 375
 	
376 376
 	while(_p) {
377 377
 		ptr = _p;
378 378
 		_p = _p->next;
379
-		pkg_free(ptr);
380
-	}
379
+		if (_shm) shm_free(ptr);
380
+		else pkg_free(ptr);
381
+	}	
382
+}
383
+
384
+
385
+/*
386
+ * Free linked list of parameters
387
+ */
388
+void free_params(param_t* _p)
389
+{
390
+	do_free_params(_p, 0);
391
+}
392
+
393
+
394
+/*
395
+ * Free linked list of parameters
396
+ */
397
+void shm_free_params(param_t* _p)
398
+{
399
+	do_free_params(_p, 1);
381 400
 }
382 401
 
383 402
 
... ...
@@ -426,7 +446,7 @@ void print_params(param_t* _p)
426 426
 /*
427 427
  * Duplicate linked list of parameters
428 428
  */
429
-int duplicate_params(param_t** _n, param_t* _p)
429
+static inline int do_duplicate_params(param_t** _n, param_t* _p, int _shm)
430 430
 {
431 431
 	param_t* last, *ptr, *t;
432 432
 
... ...
@@ -439,7 +459,11 @@ int duplicate_params(param_t** _n, param_t* _p)
439 439
 	*_n = 0;
440 440
 	ptr = _p;
441 441
 	while(ptr) {
442
-		t = (param_t*)pkg_malloc(sizeof(param_t));
442
+		if (_shm) {
443
+			t = (param_t*)shm_malloc(sizeof(param_t));
444
+		} else {
445
+			t = (param_t*)pkg_malloc(sizeof(param_t));
446
+		}
443 447
 		if (!t) {
444 448
 			LOG(L_ERR, "duplicate_params(): Invalid parameter value\n");
445 449
 			goto err;
... ...
@@ -455,6 +479,24 @@ int duplicate_params(param_t** _n, param_t* _p)
455 455
 	}
456 456
 
457 457
  err:
458
-	free_params(*_n);
458
+	do_free_params(*_n, _shm);
459 459
 	return 0;
460 460
 }
461
+
462
+
463
+/*
464
+ * Duplicate linked list of parameters
465
+ */
466
+int duplicate_params(param_t** _n, param_t* _p)
467
+{
468
+	return do_duplicate_params(_n, _p, 0);
469
+}
470
+
471
+
472
+/*
473
+ * Duplicate linked list of parameters
474
+ */
475
+int shm_duplicate_params(param_t** _n, param_t* _p)
476
+{
477
+	return do_duplicate_params(_n, _p, 1);
478
+}
... ...
@@ -118,6 +118,14 @@ void free_params(param_t* _p);
118 118
 
119 119
 
120 120
 /*
121
+ * Free linked list of parameters from shared memory
122
+ */
123
+void shm_free_params(param_t* _p);
124
+
125
+
126
+
127
+
128
+/*
121 129
  * Print linked list of parameters, just for debugging
122 130
  */
123 131
 void print_params(param_t* _p);
... ...
@@ -129,4 +137,10 @@ void print_params(param_t* _p);
129 129
 int duplicate_params(param_t** _n, param_t* _p);
130 130
 
131 131
 
132
+/*
133
+ * Duplicate linked list of parameters
134
+ */
135
+int shm_duplicate_params(param_t** _n, param_t* _p);
136
+
137
+
132 138
 #endif /* PARSE_PARAM_H */
... ...
@@ -31,6 +31,7 @@
31 31
 #include <string.h>
32 32
 #include "parse_rr.h"
33 33
 #include "../mem/mem.h"
34
+#include "../mem/shm_mem.h"
34 35
 #include "../dprint.h"
35 36
 #include "../trim.h"
36 37
 #include "../ut.h"
... ...
@@ -139,7 +140,7 @@ int parse_rr(struct hdr_field* _h)
139 139
  * Free list of rrs
140 140
  * _r is head of the list
141 141
  */
142
-void free_rr(rr_t** _r)
142
+static inline void do_free_rr(rr_t** _r, int _shm)
143 143
 {
144 144
 	rr_t* ptr;
145 145
 
... ...
@@ -149,12 +150,35 @@ void free_rr(rr_t** _r)
149 149
 		if (ptr->params) {
150 150
 			free_params(ptr->params);
151 151
 		}
152
-		pkg_free(ptr);
152
+		if (_shm) shm_free(ptr);
153
+		else pkg_free(ptr);
153 154
 	}
154 155
 }
155 156
 
156 157
 
157 158
 /*
159
+ * Free list of rrs
160
+ * _r is head of the list
161
+ */
162
+
163
+void free_rr(rr_t** _r)
164
+{
165
+	do_free_rr(_r, 0);
166
+}
167
+
168
+
169
+/*
170
+ * Free list of rrs
171
+ * _r is head of the list
172
+ */
173
+
174
+void shm_free_rr(rr_t** _r)
175
+{
176
+	do_free_rr(_r, 1);
177
+}
178
+
179
+
180
+/*
158 181
  * Print list of RRs, just for debugging
159 182
  */
160 183
 void print_rr(rr_t* _r)
... ...
@@ -198,7 +222,7 @@ static inline void xlate_pointers(struct sip_msg* _m, rr_t* _r)
198 198
 /*
199 199
  * Duplicate a single rr_t structure using pkg_malloc
200 200
  */
201
-int duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r)
201
+static inline int do_duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r, int _shm)
202 202
 {
203 203
 	int len;
204 204
 	rr_t* res;
... ...
@@ -214,7 +238,8 @@ int duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r)
214 214
 		len = _r->nameaddr.len;
215 215
 	}
216 216
 
217
-	res = pkg_malloc(sizeof(rr_t) + len);
217
+	if (_shm) res = shm_malloc(sizeof(rr_t) + len);
218
+	else res = pkg_malloc(sizeof(rr_t) + len);
218 219
 	if (!res) {
219 220
 		LOG(L_ERR, "duplicate_rr(): No memory left\n");
220 221
 		return -2;
... ...
@@ -225,7 +250,8 @@ int duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r)
225 225
 
226 226
 	if (duplicate_params(&res->params, _r->params) < 0) {
227 227
 		LOG(L_ERR, "Error while duplicating parameters\n");
228
-		pkg_free(res);
228
+		if (_shm) shm_free(res);
229
+		else pkg_free(res);
229 230
 		return -3;
230 231
 	}
231 232
 
... ...
@@ -233,3 +259,21 @@ int duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r)
233 233
 	*_new = res;
234 234
 	return 0;
235 235
 }
236
+
237
+
238
+/*
239
+ * Duplicate a single rr_t structure using pkg_malloc
240
+ */
241
+int duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r)
242
+{
243
+	return do_duplicate_rr(_m, _new, _r, 0);
244
+}
245
+
246
+
247
+/*
248
+ * Duplicate a single rr_t structure using pkg_malloc
249
+ */
250
+int shm_duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r)
251
+{
252
+	return do_duplicate_rr(_m, _new, _r, 1);
253
+}
... ...
@@ -63,6 +63,13 @@ void free_rr(rr_t** _r);
63 63
 
64 64
 
65 65
 /*
66
+ * Free list of rr
67
+ * _c is head of the list
68
+ */
69
+void shm_free_rr(rr_t** _r);
70
+
71
+
72
+/*
66 73
  * Print list of rrs, just for debugging
67 74
  */
68 75
 void print_rr(rr_t* _r);
... ...
@@ -74,4 +81,10 @@ void print_rr(rr_t* _r);
74 74
 int duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r);
75 75
 
76 76
 
77
+/*
78
+ * Duplicate a single rr_t structure using pkg_malloc
79
+ */
80
+int shm_duplicate_rr(struct sip_msg* _m, rr_t** _new, rr_t* _r);
81
+
82
+
77 83
 #endif /* PARSE_RR_H */