Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,279 +0,0 @@
1
-/*
2
- * Copyright (C) 2001-2003 FhG Fokus
3
- *
4
- * This file is part of Kamailio, a free SIP server.
5
- *
6
- * Kamailio is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version
10
- *
11
- * Kamailio is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License 
17
- * along with this program; if not, write to the Free Software 
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
- */
20
-
21
-
22
-#include "defs.h"
23
-
24
-
25
-#include <errno.h>
26
-
27
-#include "lock.h"
28
-#include "../../dprint.h"
29
-
30
-
31
-
32
-#ifndef GEN_LOCK_T_PREFERED 
33
-/* semaphore probing limits */
34
-#define SEM_MIN		16
35
-#define SEM_MAX		4096
36
-
37
-/* we implement mutex here using lock sets; as the number of
38
-   semaphores may be limited (e.g. sysv) and number of synchronized 
39
-   elements high, we partition the synced SER elements and share 
40
-   semaphores in each of the partitions; we try to use as many 
41
-   semaphores as OS gives us for finest granularity. 
42
-
43
-   we allocate the locks according to the following plans:
44
-
45
-   1) we allocate a semaphore set for hash_entries and
46
-      try to use as many semaphores in it as OS allows;
47
-      we partition the hash_entries by available
48
-      semaphores which are shared  in each partition
49
-   2) cells get always the same semaphore as its hash
50
-      entry in which they live
51
-
52
-*/
53
-
54
-/* and the maximum number of semaphores in the entry_semaphore set */
55
-static int sem_nr;
56
-gen_lock_set_t* entry_semaphore=0;
57
-gen_lock_set_t* reply_semaphore=0;
58
-#ifdef ENABLE_ASYNC_MUTEX
59
-gen_lock_set_t* async_semaphore=0;
60
-#endif
61
-#endif
62
-
63
-
64
-/* initialize the locks; return 0 on success, -1 otherwise
65
-*/
66
-int lock_initialize()
67
-{
68
-#ifndef GEN_LOCK_T_PREFERED
69
-	int i;
70
-	int probe_run;
71
-#endif
72
-
73
-	/* first try allocating semaphore sets with fixed number of semaphores */
74
-	DBG("DEBUG: lock_initialize: lock initialization started\n");
75
-
76
-#ifndef GEN_LOCK_T_PREFERED
77
-	i=SEM_MIN;
78
-	/* probing phase: 0=initial, 1=after the first failure */
79
-	probe_run=0;
80
-again:
81
-	do {
82
-		if (entry_semaphore!=0){ /* clean-up previous attempt */
83
-			lock_set_destroy(entry_semaphore);
84
-			lock_set_dealloc(entry_semaphore);
85
-		}
86
-		if (reply_semaphore!=0){
87
-			lock_set_destroy(reply_semaphore);
88
-			lock_set_dealloc(reply_semaphore);
89
-		}
90
-#ifdef ENABLE_ASYNC_MUTEX
91
-		if (async_semaphore!=0){
92
-			lock_set_destroy(async_semaphore);
93
-			lock_set_dealloc(async_semaphore);
94
-		}
95
-#endif
96
-		if (i==0){
97
-			LOG(L_CRIT, "lock_initialize: could not allocate semaphore"
98
-					" sets\n");
99
-			goto error;
100
-		}
101
-		
102
-		if (((entry_semaphore=lock_set_alloc(i))==0)||
103
-			(lock_set_init(entry_semaphore)==0)) {
104
-			DBG("DEBUG: lock_initialize: entry semaphore "
105
-					"initialization failure:  %s\n", strerror( errno ) );
106
-			if (entry_semaphore){
107
-				lock_set_dealloc(entry_semaphore);
108
-				entry_semaphore=0;
109
-			}
110
-			/* first time: step back and try again */
111
-			if (probe_run==0) {
112
-					DBG("DEBUG: lock_initialize: first time "
113
-								"semaphore allocation failure\n");
114
-					i--;
115
-					probe_run=1;
116
-					continue;
117
-				/* failure after we stepped back; give up */
118
-			} else {
119
-					DBG("DEBUG: lock_initialize:   second time semaphore"
120
-							" allocation failure\n");
121
-					goto error;
122
-			}
123
-		}
124
-		/* allocation succeeded */
125
-		if (probe_run==1) { /* if ok after we stepped back, we're done */
126
-			break;
127
-		} else { /* if ok otherwise, try again with larger set */
128
-			if (i==SEM_MAX) break;
129
-			else {
130
-				i++;
131
-				continue;
132
-			}
133
-		}
134
-	} while(1);
135
-	sem_nr=i;
136
-
137
-	if (((reply_semaphore=lock_set_alloc(i))==0)||
138
-		(lock_set_init(reply_semaphore)==0)){
139
-			if (reply_semaphore){
140
-				lock_set_dealloc(reply_semaphore);
141
-				reply_semaphore=0;
142
-			}
143
-			DBG("DEBUG:lock_initialize: reply semaphore initialization"
144
-				" failure: %s\n", strerror(errno));
145
-			probe_run=1;
146
-			i--;
147
-			goto again;
148
-	}
149
-#ifdef ENABLE_ASYNC_MUTEX
150
-	i++;
151
-	if (((async_semaphore=lock_set_alloc(i))==0)||
152
-		(lock_set_init(async_semaphore)==0)){
153
-			if (async_semaphore){
154
-				lock_set_dealloc(async_semaphore);
155
-				async_semaphore=0;
156
-			}
157
-			DBG("DEBUG:lock_initialize: async semaphore initialization"
158
-				" failure: %s\n", strerror(errno));
159
-			probe_run=1;
160
-			i--;
161
-			goto again;
162
-	}
163
-#endif
164
-
165
-	/* return success */
166
-	LOG(L_INFO, "INFO: semaphore arrays of size %d allocated\n", sem_nr );
167
-#endif /* GEN_LOCK_T_PREFERED*/
168
-	return 0;
169
-#ifndef GEN_LOCK_T_PREFERED
170
-error:
171
-	lock_cleanup();
172
-	return -1;
173
-#endif
174
-}
175
-
176
-
177
-#ifdef GEN_LOCK_T_PREFERED
178
-void lock_cleanup()
179
-{
180
-	/* must check if someone uses them, for now just leave them allocated*/
181
-}
182
-
183
-#else
184
-
185
-/* remove the semaphore set from system */
186
-void lock_cleanup()
187
-{
188
-	/* that's system-wide; all other processes trying to use
189
-	   the semaphore will fail! call only if it is for sure
190
-	   no other process lives 
191
-	*/
192
-
193
-	/* sibling double-check missing here; install a signal handler */
194
-
195
-	if (entry_semaphore !=0){
196
-		lock_set_destroy(entry_semaphore);
197
-		lock_set_dealloc(entry_semaphore);
198
-	};
199
-	if (reply_semaphore !=0) {
200
-		lock_set_destroy(reply_semaphore);
201
-		lock_set_dealloc(reply_semaphore);
202
-	};
203
-#ifdef ENABLE_ASYNC_MUTEX
204
-	if (async_semaphore !=0) {
205
-		lock_set_destroy(async_semaphore);
206
-		lock_set_dealloc(async_semaphore);
207
-	}
208
-	async_semaphore = 0;
209
-#endif
210
-	entry_semaphore =  reply_semaphore = 0;
211
-
212
-}
213
-#endif /*GEN_LOCK_T_PREFERED*/
214
-
215
-
216
-
217
-
218
-
219
-int init_cell_lock( struct cell *cell )
220
-{
221
-#ifdef GEN_LOCK_T_PREFERED
222
-	lock_init(&cell->reply_mutex);
223
-#else
224
-	cell->reply_mutex.semaphore_set=reply_semaphore;
225
-	cell->reply_mutex.semaphore_index = cell->hash_index % sem_nr;
226
-#endif /* GEN_LOCK_T_PREFERED */
227
-	return 0;
228
-}
229
-
230
-int init_entry_lock( struct s_table* ht, struct entry *entry )
231
-{
232
-#ifdef GEN_LOCK_T_PREFERED
233
-	lock_init(&entry->mutex);
234
-#else
235
-	/* just advice which of the available semaphores to use;
236
-	   specifically, all entries are partitioned into as
237
-	   many partitions as number of available semaphores allows
238
-        */
239
-	entry->mutex.semaphore_set=entry_semaphore;
240
-	entry->mutex.semaphore_index = ( ((char *)entry - (char *)(ht->entries ) )
241
-               / sizeof(struct entry) ) % sem_nr;
242
-#endif
243
-	return 0;
244
-}
245
-
246
-int init_async_lock( struct cell *cell )
247
-{
248
-#ifdef ENABLE_ASYNC_MUTEX
249
-
250
-#ifdef GEN_LOCK_T_PREFERED
251
-	lock_init(&cell->async_mutex);
252
-#else
253
-	cell->async_mutex.semaphore_set=async_semaphore;
254
-	cell->async_mutex.semaphore_index = cell->hash_index % sem_nr;
255
-#endif /* GEN_LOCK_T_PREFERED */
256
-
257
-#endif /* ENABLE_ASYNC_MUTEX */
258
-
259
-	return 0;
260
-}
261
-
262
-int release_cell_lock( struct cell *cell )
263
-{
264
-#ifndef GEN_LOCK_T_PREFERED
265
-	/* don't do anything here -- the init_*_lock procedures
266
-	   just advised on usage of shared semaphores but did not
267
-	   generate them
268
-	*/
269
-#endif
270
-	return 0;
271
-}
272
-
273
-
274
-
275
-int release_entry_lock( struct entry *entry )
276
-{
277
-	/* the same as above */
278
-	return 0;
279
-}
Browse code

tm: restore to the disabled async mutex by define

- following commits trying to remove it completely were removing the
internal transaction flags which were not related to mutex at all

Daniel-Constantin Mierla authored on 20/05/2015 19:32:00
Showing 1 changed files
... ...
@@ -55,6 +55,9 @@
55 55
 static int sem_nr;
56 56
 gen_lock_set_t* entry_semaphore=0;
57 57
 gen_lock_set_t* reply_semaphore=0;
58
+#ifdef ENABLE_ASYNC_MUTEX
59
+gen_lock_set_t* async_semaphore=0;
60
+#endif
58 61
 #endif
59 62
 
60 63
 
... ...
@@ -84,6 +87,12 @@ again:
84 87
 			lock_set_destroy(reply_semaphore);
85 88
 			lock_set_dealloc(reply_semaphore);
86 89
 		}
90
+#ifdef ENABLE_ASYNC_MUTEX
91
+		if (async_semaphore!=0){
92
+			lock_set_destroy(async_semaphore);
93
+			lock_set_dealloc(async_semaphore);
94
+		}
95
+#endif
87 96
 		if (i==0){
88 97
 			LOG(L_CRIT, "lock_initialize: could not allocate semaphore"
89 98
 					" sets\n");
... ...
@@ -137,6 +146,22 @@ again:
137 146
 			i--;
138 147
 			goto again;
139 148
 	}
149
+#ifdef ENABLE_ASYNC_MUTEX
150
+	i++;
151
+	if (((async_semaphore=lock_set_alloc(i))==0)||
152
+		(lock_set_init(async_semaphore)==0)){
153
+			if (async_semaphore){
154
+				lock_set_dealloc(async_semaphore);
155
+				async_semaphore=0;
156
+			}
157
+			DBG("DEBUG:lock_initialize: async semaphore initialization"
158
+				" failure: %s\n", strerror(errno));
159
+			probe_run=1;
160
+			i--;
161
+			goto again;
162
+	}
163
+#endif
164
+
140 165
 	/* return success */
141 166
 	LOG(L_INFO, "INFO: semaphore arrays of size %d allocated\n", sem_nr );
142 167
 #endif /* GEN_LOCK_T_PREFERED*/
... ...
@@ -175,7 +200,15 @@ void lock_cleanup()
175 200
 		lock_set_destroy(reply_semaphore);
176 201
 		lock_set_dealloc(reply_semaphore);
177 202
 	};
203
+#ifdef ENABLE_ASYNC_MUTEX
204
+	if (async_semaphore !=0) {
205
+		lock_set_destroy(async_semaphore);
206
+		lock_set_dealloc(async_semaphore);
207
+	}
208
+	async_semaphore = 0;
209
+#endif
178 210
 	entry_semaphore =  reply_semaphore = 0;
211
+
179 212
 }
180 213
 #endif /*GEN_LOCK_T_PREFERED*/
181 214
 
... ...
@@ -210,6 +243,22 @@ int init_entry_lock( struct s_table* ht, struct entry *entry )
210 243
 	return 0;
211 244
 }
212 245
 
246
+int init_async_lock( struct cell *cell )
247
+{
248
+#ifdef ENABLE_ASYNC_MUTEX
249
+
250
+#ifdef GEN_LOCK_T_PREFERED
251
+	lock_init(&cell->async_mutex);
252
+#else
253
+	cell->async_mutex.semaphore_set=async_semaphore;
254
+	cell->async_mutex.semaphore_index = cell->hash_index % sem_nr;
255
+#endif /* GEN_LOCK_T_PREFERED */
256
+
257
+#endif /* ENABLE_ASYNC_MUTEX */
258
+
259
+	return 0;
260
+}
261
+
213 262
 int release_cell_lock( struct cell *cell )
214 263
 {
215 264
 #ifndef GEN_LOCK_T_PREFERED
Browse code

modules/tm: removed no longer needed ASYNC mutex

jaybeepee authored on 13/05/2015 07:14:44
Showing 1 changed files
... ...
@@ -55,9 +55,6 @@
55 55
 static int sem_nr;
56 56
 gen_lock_set_t* entry_semaphore=0;
57 57
 gen_lock_set_t* reply_semaphore=0;
58
-#ifdef ENABLE_ASYNC_MUTEX
59
-gen_lock_set_t* async_semaphore=0;
60
-#endif
61 58
 #endif
62 59
 
63 60
 
... ...
@@ -87,12 +84,6 @@ again:
87 84
 			lock_set_destroy(reply_semaphore);
88 85
 			lock_set_dealloc(reply_semaphore);
89 86
 		}
90
-#ifdef ENABLE_ASYNC_MUTEX
91
-		if (async_semaphore!=0){
92
-			lock_set_destroy(async_semaphore);
93
-			lock_set_dealloc(async_semaphore);
94
-		}
95
-#endif
96 87
 		if (i==0){
97 88
 			LOG(L_CRIT, "lock_initialize: could not allocate semaphore"
98 89
 					" sets\n");
... ...
@@ -146,22 +137,6 @@ again:
146 137
 			i--;
147 138
 			goto again;
148 139
 	}
149
-#ifdef ENABLE_ASYNC_MUTEX
150
-	i++;
151
-	if (((async_semaphore=lock_set_alloc(i))==0)||
152
-		(lock_set_init(async_semaphore)==0)){
153
-			if (async_semaphore){
154
-				lock_set_dealloc(async_semaphore);
155
-				async_semaphore=0;
156
-			}
157
-			DBG("DEBUG:lock_initialize: async semaphore initialization"
158
-				" failure: %s\n", strerror(errno));
159
-			probe_run=1;
160
-			i--;
161
-			goto again;
162
-	}
163
-#endif
164
-
165 140
 	/* return success */
166 141
 	LOG(L_INFO, "INFO: semaphore arrays of size %d allocated\n", sem_nr );
167 142
 #endif /* GEN_LOCK_T_PREFERED*/
... ...
@@ -200,15 +175,7 @@ void lock_cleanup()
200 175
 		lock_set_destroy(reply_semaphore);
201 176
 		lock_set_dealloc(reply_semaphore);
202 177
 	};
203
-#ifdef ENABLE_ASYNC_MUTEX
204
-	if (async_semaphore !=0) {
205
-		lock_set_destroy(async_semaphore);
206
-		lock_set_dealloc(async_semaphore);
207
-	}
208
-	async_semaphore = 0;
209
-#endif
210 178
 	entry_semaphore =  reply_semaphore = 0;
211
-
212 179
 }
213 180
 #endif /*GEN_LOCK_T_PREFERED*/
214 181
 
... ...
@@ -243,22 +210,6 @@ int init_entry_lock( struct s_table* ht, struct entry *entry )
243 210
 	return 0;
244 211
 }
245 212
 
246
-int init_async_lock( struct cell *cell )
247
-{
248
-#ifdef ENABLE_ASYNC_MUTEX
249
-
250
-#ifdef GEN_LOCK_T_PREFERED
251
-	lock_init(&cell->async_mutex);
252
-#else
253
-	cell->async_mutex.semaphore_set=async_semaphore;
254
-	cell->async_mutex.semaphore_index = cell->hash_index % sem_nr;
255
-#endif /* GEN_LOCK_T_PREFERED */
256
-
257
-#endif /* ENABLE_ASYNC_MUTEX */
258
-
259
-	return 0;
260
-}
261
-
262 213
 int release_cell_lock( struct cell *cell )
263 214
 {
264 215
 #ifndef GEN_LOCK_T_PREFERED
Browse code

Revert "modules/tm: removed no longer needed ASYNC mutex"

This reverts commit 7ca0e1e87a84f323bbfbaf1ea4985fbfecec00ed.

jaybeepee authored on 13/05/2015 07:05:07
Showing 1 changed files
... ...
@@ -55,6 +55,9 @@
55 55
 static int sem_nr;
56 56
 gen_lock_set_t* entry_semaphore=0;
57 57
 gen_lock_set_t* reply_semaphore=0;
58
+#ifdef ENABLE_ASYNC_MUTEX
59
+gen_lock_set_t* async_semaphore=0;
60
+#endif
58 61
 #endif
59 62
 
60 63
 
... ...
@@ -84,6 +87,12 @@ again:
84 87
 			lock_set_destroy(reply_semaphore);
85 88
 			lock_set_dealloc(reply_semaphore);
86 89
 		}
90
+#ifdef ENABLE_ASYNC_MUTEX
91
+		if (async_semaphore!=0){
92
+			lock_set_destroy(async_semaphore);
93
+			lock_set_dealloc(async_semaphore);
94
+		}
95
+#endif
87 96
 		if (i==0){
88 97
 			LOG(L_CRIT, "lock_initialize: could not allocate semaphore"
89 98
 					" sets\n");
... ...
@@ -137,6 +146,21 @@ again:
137 146
 			i--;
138 147
 			goto again;
139 148
 	}
149
+#ifdef ENABLE_ASYNC_MUTEX
150
+	i++;
151
+	if (((async_semaphore=lock_set_alloc(i))==0)||
152
+		(lock_set_init(async_semaphore)==0)){
153
+			if (async_semaphore){
154
+				lock_set_dealloc(async_semaphore);
155
+				async_semaphore=0;
156
+			}
157
+			DBG("DEBUG:lock_initialize: async semaphore initialization"
158
+				" failure: %s\n", strerror(errno));
159
+			probe_run=1;
160
+			i--;
161
+			goto again;
162
+	}
163
+#endif
140 164
 
141 165
 	/* return success */
142 166
 	LOG(L_INFO, "INFO: semaphore arrays of size %d allocated\n", sem_nr );
... ...
@@ -176,6 +200,13 @@ void lock_cleanup()
176 200
 		lock_set_destroy(reply_semaphore);
177 201
 		lock_set_dealloc(reply_semaphore);
178 202
 	};
203
+#ifdef ENABLE_ASYNC_MUTEX
204
+	if (async_semaphore !=0) {
205
+		lock_set_destroy(async_semaphore);
206
+		lock_set_dealloc(async_semaphore);
207
+	}
208
+	async_semaphore = 0;
209
+#endif
179 210
 	entry_semaphore =  reply_semaphore = 0;
180 211
 
181 212
 }
... ...
@@ -212,6 +243,22 @@ int init_entry_lock( struct s_table* ht, struct entry *entry )
212 243
 	return 0;
213 244
 }
214 245
 
246
+int init_async_lock( struct cell *cell )
247
+{
248
+#ifdef ENABLE_ASYNC_MUTEX
249
+
250
+#ifdef GEN_LOCK_T_PREFERED
251
+	lock_init(&cell->async_mutex);
252
+#else
253
+	cell->async_mutex.semaphore_set=async_semaphore;
254
+	cell->async_mutex.semaphore_index = cell->hash_index % sem_nr;
255
+#endif /* GEN_LOCK_T_PREFERED */
256
+
257
+#endif /* ENABLE_ASYNC_MUTEX */
258
+
259
+	return 0;
260
+}
261
+
215 262
 int release_cell_lock( struct cell *cell )
216 263
 {
217 264
 #ifndef GEN_LOCK_T_PREFERED
Browse code

modules/tm: removed no longer needed ASYNC mutex

jaybeepee authored on 13/05/2015 06:51:59
Showing 1 changed files
... ...
@@ -55,9 +55,6 @@
55 55
 static int sem_nr;
56 56
 gen_lock_set_t* entry_semaphore=0;
57 57
 gen_lock_set_t* reply_semaphore=0;
58
-#ifdef ENABLE_ASYNC_MUTEX
59
-gen_lock_set_t* async_semaphore=0;
60
-#endif
61 58
 #endif
62 59
 
63 60
 
... ...
@@ -87,12 +84,6 @@ again:
87 84
 			lock_set_destroy(reply_semaphore);
88 85
 			lock_set_dealloc(reply_semaphore);
89 86
 		}
90
-#ifdef ENABLE_ASYNC_MUTEX
91
-		if (async_semaphore!=0){
92
-			lock_set_destroy(async_semaphore);
93
-			lock_set_dealloc(async_semaphore);
94
-		}
95
-#endif
96 87
 		if (i==0){
97 88
 			LOG(L_CRIT, "lock_initialize: could not allocate semaphore"
98 89
 					" sets\n");
... ...
@@ -146,21 +137,6 @@ again:
146 137
 			i--;
147 138
 			goto again;
148 139
 	}
149
-#ifdef ENABLE_ASYNC_MUTEX
150
-	i++;
151
-	if (((async_semaphore=lock_set_alloc(i))==0)||
152
-		(lock_set_init(async_semaphore)==0)){
153
-			if (async_semaphore){
154
-				lock_set_dealloc(async_semaphore);
155
-				async_semaphore=0;
156
-			}
157
-			DBG("DEBUG:lock_initialize: async semaphore initialization"
158
-				" failure: %s\n", strerror(errno));
159
-			probe_run=1;
160
-			i--;
161
-			goto again;
162
-	}
163
-#endif
164 140
 
165 141
 	/* return success */
166 142
 	LOG(L_INFO, "INFO: semaphore arrays of size %d allocated\n", sem_nr );
... ...
@@ -200,13 +176,6 @@ void lock_cleanup()
200 176
 		lock_set_destroy(reply_semaphore);
201 177
 		lock_set_dealloc(reply_semaphore);
202 178
 	};
203
-#ifdef ENABLE_ASYNC_MUTEX
204
-	if (async_semaphore !=0) {
205
-		lock_set_destroy(async_semaphore);
206
-		lock_set_dealloc(async_semaphore);
207
-	}
208
-	async_semaphore = 0;
209
-#endif
210 179
 	entry_semaphore =  reply_semaphore = 0;
211 180
 
212 181
 }
... ...
@@ -243,22 +212,6 @@ int init_entry_lock( struct s_table* ht, struct entry *entry )
243 212
 	return 0;
244 213
 }
245 214
 
246
-int init_async_lock( struct cell *cell )
247
-{
248
-#ifdef ENABLE_ASYNC_MUTEX
249
-
250
-#ifdef GEN_LOCK_T_PREFERED
251
-	lock_init(&cell->async_mutex);
252
-#else
253
-	cell->async_mutex.semaphore_set=async_semaphore;
254
-	cell->async_mutex.semaphore_index = cell->hash_index % sem_nr;
255
-#endif /* GEN_LOCK_T_PREFERED */
256
-
257
-#endif /* ENABLE_ASYNC_MUTEX */
258
-
259
-	return 0;
260
-}
261
-
262 215
 int release_cell_lock( struct cell *cell )
263 216
 {
264 217
 #ifndef GEN_LOCK_T_PREFERED
Browse code

tm: disabled use of dedicated mutex for async continue

- it can be enabled by defining ENABLE_ASYNC_MUTEX
- reply mutex is re-entrant and protects better the transaction
strucutre
- a dedicated lock for async continue exposes a race on removing from
timer when suspended transaction is resument at the same time when the
timer fires expiration event

Daniel-Constantin Mierla authored on 10/05/2015 16:18:00
Showing 1 changed files
... ...
@@ -55,8 +55,10 @@
55 55
 static int sem_nr;
56 56
 gen_lock_set_t* entry_semaphore=0;
57 57
 gen_lock_set_t* reply_semaphore=0;
58
+#ifdef ENABLE_ASYNC_MUTEX
58 59
 gen_lock_set_t* async_semaphore=0;
59 60
 #endif
61
+#endif
60 62
 
61 63
 
62 64
 /* initialize the locks; return 0 on success, -1 otherwise
... ...
@@ -85,11 +87,12 @@ again:
85 87
 			lock_set_destroy(reply_semaphore);
86 88
 			lock_set_dealloc(reply_semaphore);
87 89
 		}
90
+#ifdef ENABLE_ASYNC_MUTEX
88 91
 		if (async_semaphore!=0){
89 92
 			lock_set_destroy(async_semaphore);
90 93
 			lock_set_dealloc(async_semaphore);
91 94
 		}
92
-		
95
+#endif
93 96
 		if (i==0){
94 97
 			LOG(L_CRIT, "lock_initialize: could not allocate semaphore"
95 98
 					" sets\n");
... ...
@@ -143,6 +146,7 @@ again:
143 146
 			i--;
144 147
 			goto again;
145 148
 	}
149
+#ifdef ENABLE_ASYNC_MUTEX
146 150
 	i++;
147 151
 	if (((async_semaphore=lock_set_alloc(i))==0)||
148 152
 		(lock_set_init(async_semaphore)==0)){
... ...
@@ -156,7 +160,7 @@ again:
156 160
 			i--;
157 161
 			goto again;
158 162
 	}
159
-	
163
+#endif
160 164
 
161 165
 	/* return success */
162 166
 	LOG(L_INFO, "INFO: semaphore arrays of size %d allocated\n", sem_nr );
... ...
@@ -196,11 +200,14 @@ void lock_cleanup()
196 200
 		lock_set_destroy(reply_semaphore);
197 201
 		lock_set_dealloc(reply_semaphore);
198 202
 	};
203
+#ifdef ENABLE_ASYNC_MUTEX
199 204
 	if (async_semaphore !=0) {
200 205
 		lock_set_destroy(async_semaphore);
201 206
 		lock_set_dealloc(async_semaphore);
202
-	};
203
-	entry_semaphore =  reply_semaphore = async_semaphore = 0;
207
+	}
208
+	async_semaphore = 0;
209
+#endif
210
+	entry_semaphore =  reply_semaphore = 0;
204 211
 
205 212
 }
206 213
 #endif /*GEN_LOCK_T_PREFERED*/
... ...
@@ -238,12 +245,17 @@ int init_entry_lock( struct s_table* ht, struct entry *entry )
238 245
 
239 246
 int init_async_lock( struct cell *cell )
240 247
 {
248
+#ifdef ENABLE_ASYNC_MUTEX
249
+
241 250
 #ifdef GEN_LOCK_T_PREFERED
242 251
 	lock_init(&cell->async_mutex);
243 252
 #else
244 253
 	cell->async_mutex.semaphore_set=async_semaphore;
245 254
 	cell->async_mutex.semaphore_index = cell->hash_index % sem_nr;
246 255
 #endif /* GEN_LOCK_T_PREFERED */
256
+
257
+#endif /* ENABLE_ASYNC_MUTEX */
258
+
247 259
 	return 0;
248 260
 }
249 261
 
Browse code

tm Remove svn ID, remove history, rename "ser" to "kamailio"

Olle E. Johansson authored on 03/01/2015 15:48:29
Showing 1 changed files
... ...
@@ -1,21 +1,14 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Copyright (C) 2001-2003 FhG Fokus
5 3
  *
6
- * This file is part of ser, a free SIP server.
4
+ * This file is part of Kamailio, a free SIP server.
7 5
  *
8
- * ser is free software; you can redistribute it and/or modify
6
+ * Kamailio is free software; you can redistribute it and/or modify
9 7
  * it under the terms of the GNU General Public License as published by
10 8
  * the Free Software Foundation; either version 2 of the License, or
11 9
  * (at your option) any later version
12 10
  *
13
- * For a license to use the ser software under conditions
14
- * other than those described here, or to purchase support for this
15
- * software, please contact iptel.org by e-mail at the following addresses:
16
- *    info@iptel.org
17
- *
18
- * ser is distributed in the hope that it will be useful,
11
+ * Kamailio is distributed in the hope that it will be useful,
19 12
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 14
  * GNU General Public License for more details.
... ...
@@ -24,15 +17,6 @@
24 17
  * along with this program; if not, write to the Free Software 
25 18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
26 19
  */
27
-/*
28
- * History:
29
- * --------
30
- *  2003-03-17  converted to locking.h (andrei)
31
- *  2004-07-28  s/lock_set_t/gen_lock_set_t/ because of a type conflict
32
- *              on darwin (andrei)
33
- *  2006-03-07  removed timer_semaphore, timer_group_lock and related functions
34
- *              since timers are now handled outside tm (andrei)
35
- */
36 20
 
37 21
 
38 22
 #include "defs.h"
Browse code

all: updated FSF address in GPL text

Anthony Messina authored on 04/07/2014 09:36:37 • Daniel-Constantin Mierla committed on 04/07/2014 09:37:36
Showing 1 changed files
... ...
@@ -22,7 +22,7 @@
22 22
  *
23 23
  * You should have received a copy of the GNU General Public License 
24 24
  * along with this program; if not, write to the Free Software 
25
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
26 26
  */
27 27
 /*
28 28
  * History:
Browse code

modules/tm: extended async usage - enables resuming of tx in orginal route block tx was suspended, not only failure route - dedicated lock to prevent multiple invocations of suspend on tz (reply lock used to be used) - extra flag (T_ASYNC_CONTINUE) to mark a transaction that is being execute post suspend

Jason Penton authored on 30/09/2013 09:14:54
Showing 1 changed files
... ...
@@ -71,6 +71,7 @@
71 71
 static int sem_nr;
72 72
 gen_lock_set_t* entry_semaphore=0;
73 73
 gen_lock_set_t* reply_semaphore=0;
74
+gen_lock_set_t* async_semaphore=0;
74 75
 #endif
75 76
 
76 77
 
... ...
@@ -100,6 +101,10 @@ again:
100 101
 			lock_set_destroy(reply_semaphore);
101 102
 			lock_set_dealloc(reply_semaphore);
102 103
 		}
104
+		if (async_semaphore!=0){
105
+			lock_set_destroy(async_semaphore);
106
+			lock_set_dealloc(async_semaphore);
107
+		}
103 108
 		
104 109
 		if (i==0){
105 110
 			LOG(L_CRIT, "lock_initialize: could not allocate semaphore"
... ...
@@ -154,6 +159,20 @@ again:
154 159
 			i--;
155 160
 			goto again;
156 161
 	}
162
+	i++;
163
+	if (((async_semaphore=lock_set_alloc(i))==0)||
164
+		(lock_set_init(async_semaphore)==0)){
165
+			if (async_semaphore){
166
+				lock_set_dealloc(async_semaphore);
167
+				async_semaphore=0;
168
+			}
169
+			DBG("DEBUG:lock_initialize: async semaphore initialization"
170
+				" failure: %s\n", strerror(errno));
171
+			probe_run=1;
172
+			i--;
173
+			goto again;
174
+	}
175
+	
157 176
 
158 177
 	/* return success */
159 178
 	LOG(L_INFO, "INFO: semaphore arrays of size %d allocated\n", sem_nr );
... ...
@@ -193,7 +212,11 @@ void lock_cleanup()
193 212
 		lock_set_destroy(reply_semaphore);
194 213
 		lock_set_dealloc(reply_semaphore);
195 214
 	};
196
-	entry_semaphore =  reply_semaphore = 0;
215
+	if (async_semaphore !=0) {
216
+		lock_set_destroy(async_semaphore);
217
+		lock_set_dealloc(async_semaphore);
218
+	};
219
+	entry_semaphore =  reply_semaphore = async_semaphore = 0;
197 220
 
198 221
 }
199 222
 #endif /*GEN_LOCK_T_PREFERED*/
... ...
@@ -229,7 +252,16 @@ int init_entry_lock( struct s_table* ht, struct entry *entry )
229 252
 	return 0;
230 253
 }
231 254
 
232
-
255
+int init_async_lock( struct cell *cell )
256
+{
257
+#ifdef GEN_LOCK_T_PREFERED
258
+	lock_init(&cell->async_mutex);
259
+#else
260
+	cell->async_mutex.semaphore_set=async_semaphore;
261
+	cell->async_mutex.semaphore_index = cell->hash_index % sem_nr;
262
+#endif /* GEN_LOCK_T_PREFERED */
263
+	return 0;
264
+}
233 265
 
234 266
 int release_cell_lock( struct cell *cell )
235 267
 {
Browse code

fix typo; 'the the' -> 'the'

Alfred E. Heggestad authored on 12/06/2008 15:47:10
Showing 1 changed files
... ...
@@ -60,7 +60,7 @@
60 60
 
61 61
    1) we allocate a semaphore set for hash_entries and
62 62
       try to use as many semaphores in it as OS allows;
63
-      we partition the the hash_entries by available
63
+      we partition the hash_entries by available
64 64
       semaphores which are shared  in each partition
65 65
    2) cells get always the same semaphore as its hash
66 66
       entry in which they live
Browse code

- changed tm hash bucket lists (simplified & a little bit faster) - inlined some used-a-lot functions - don't allocate space for md5 if syn_branches is on (default) => 32 bytes saved/transaction

Andrei Pelinescu-Onciul authored on 06/06/2007 21:54:04
Showing 1 changed files
... ...
@@ -223,7 +223,7 @@ int init_entry_lock( struct s_table* ht, struct entry *entry )
223 223
 	   many partitions as number of available semaphores allows
224 224
         */
225 225
 	entry->mutex.semaphore_set=entry_semaphore;
226
-	entry->mutex.semaphore_index = ( ((char *)entry - (char *)(ht->entrys ) )
226
+	entry->mutex.semaphore_index = ( ((char *)entry - (char *)(ht->entries ) )
227 227
                / sizeof(struct entry) ) % sem_nr;
228 228
 #endif
229 229
 	return 0;
Browse code

- timer lock cleanups (removed timer related lock stuff since timers are now external, in-core)

Andrei Pelinescu-Onciul authored on 07/03/2006 09:58:11
Showing 1 changed files
... ...
@@ -30,6 +30,8 @@
30 30
  *  2003-03-17  converted to locking.h (andrei)
31 31
  *  2004-07-28  s/lock_set_t/gen_lock_set_t/ because of a type conflict
32 32
  *              on darwin (andrei)
33
+ *  2006-03-07  removed timer_semaphore, timer_group_lock and related functions
34
+ *              since timers are now handled outside tm (andrei)
33 35
  */
34 36
 
35 37
 
... ...
@@ -39,7 +41,6 @@
39 41
 #include <errno.h>
40 42
 
41 43
 #include "lock.h"
42
-#include "timer.h"
43 44
 #include "../../dprint.h"
44 45
 
45 46
 
... ...
@@ -57,69 +58,35 @@
57 58
 
58 59
    we allocate the locks according to the following plans:
59 60
 
60
-   1) transaction timer lists have each a semaphore in
61
-      a semaphore set
62
-   2) retransmission timer lists have each a semaphore
63
-      in a semaphore set
64
-   3) we allocate a semaphore set for hash_entries and
61
+   1) we allocate a semaphore set for hash_entries and
65 62
       try to use as many semaphores in it as OS allows;
66 63
       we partition the the hash_entries by available
67 64
       semaphores which are shared  in each partition
68
-   4) cells get always the same semaphore as its hash
65
+   2) cells get always the same semaphore as its hash
69 66
       entry in which they live
70 67
 
71 68
 */
72 69
 
73 70
 /* and the maximum number of semaphores in the entry_semaphore set */
74 71
 static int sem_nr;
75
-gen_lock_set_t* timer_semaphore=0;
76 72
 gen_lock_set_t* entry_semaphore=0;
77 73
 gen_lock_set_t* reply_semaphore=0;
78 74
 #endif
79 75
 
80
-/* timer group locks */
81
-
82
-
83
-static ser_lock_t* timer_group_lock=0; /* pointer to a TG_NR lock array,
84
-								    it's safer if we alloc this in shared mem 
85
-									( required for fast lock ) */
86 76
 
87 77
 /* initialize the locks; return 0 on success, -1 otherwise
88 78
 */
89 79
 int lock_initialize()
90 80
 {
91
-	int i;
92 81
 #ifndef GEN_LOCK_T_PREFERED
82
+	int i;
93 83
 	int probe_run;
94 84
 #endif
95 85
 
96 86
 	/* first try allocating semaphore sets with fixed number of semaphores */
97 87
 	DBG("DEBUG: lock_initialize: lock initialization started\n");
98 88
 
99
-	timer_group_lock=shm_malloc(TG_NR*sizeof(ser_lock_t));
100
-	if (timer_group_lock==0){
101
-		LOG(L_CRIT, "ERROR: lock_initialize: out of shm mem\n");
102
-		goto error;
103
-	}
104
-#ifdef GEN_LOCK_T_PREFERED
105
-	for(i=0;i<TG_NR;i++) lock_init(&timer_group_lock[i]);
106
-#else
107
-	/* transaction timers */
108
-	if (((timer_semaphore= lock_set_alloc( TG_NR ) ) == 0)||
109
-			(lock_set_init(timer_semaphore)==0)){
110
-		if (timer_semaphore) lock_set_destroy(timer_semaphore);
111
-		LOG(L_CRIT, "ERROR: lock_initialize:  "
112
-			"transaction timer semaphore initialization failure: %s\n",
113
-				strerror(errno));
114