- 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)
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,87 +0,0 @@ |
1 |
-/* |
|
2 |
- * |
|
3 |
- * Copyright (C) 2001-2003 FhG Fokus |
|
4 |
- * |
|
5 |
- * This file is part of Kamailio, a free SIP server. |
|
6 |
- * |
|
7 |
- * Kamailio is free software; you can redistribute it and/or modify |
|
8 |
- * it under the terms of the GNU General Public License as published by |
|
9 |
- * the Free Software Foundation; either version 2 of the License, or |
|
10 |
- * (at your option) any later version |
|
11 |
- * |
|
12 |
- * Kamailio is distributed in the hope that it will be useful, |
|
13 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
- * GNU General Public License for more details. |
|
16 |
- * |
|
17 |
- * You should have received a copy of the GNU General Public License |
|
18 |
- * along with this program; if not, write to the Free Software |
|
19 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
20 |
- */ |
|
21 |
- |
|
22 |
-/*! |
|
23 |
-* \file |
|
24 |
-* \brief Kamailio core :: Kamailio locking library |
|
25 |
-* \ingroup core |
|
26 |
-* \author andrei |
|
27 |
-* Module: \ref core |
|
28 |
- * |
|
29 |
- * |
|
30 |
-Implements (in lock_ops.h & lock_alloc.h): |
|
31 |
- |
|
32 |
- simple locks: |
|
33 |
- ------------- |
|
34 |
- type: gen_lock_t |
|
35 |
- gen_lock_t* lock_alloc(); - allocates a lock in shared mem. |
|
36 |
- gen_lock_t* lock_init(gen_lock_t* lock); - inits the lock |
|
37 |
- void lock_destroy(gen_lock_t* lock); - removes the lock (e.g sysv rmid) |
|
38 |
- void lock_dealloc(gen_lock_t* lock); - deallocates the lock's shared m. |
|
39 |
- void lock_get(gen_lock_t* lock); - lock (mutex down) |
|
40 |
- void lock_release(gen_lock_t* lock); - unlock (mutex up) |
|
41 |
- |
|
42 |
- lock sets: |
|
43 |
- ---------- |
|
44 |
- type: gen_lock_set_t |
|
45 |
- gen_lock_set_t* lock_set_alloc(no) - allocs a lock set in shm. |
|
46 |
- gen_lock_set_t* lock_set_init(gen_lock_set_t* set); - inits the lock set |
|
47 |
- void lock_set_destroy(gen_lock_set_t* s); - removes the lock set |
|
48 |
- void lock_set_dealloc(gen_lock_set_t* s); - deallocs the lock set shm. |
|
49 |
- void lock_set_get(gen_lock_set_t* s, int i); - locks sem i from the set |
|
50 |
- void lock_set_release(gen_lock_set_t* s, int i) - unlocks sem i from the set |
|
51 |
- |
|
52 |
- recursive locks: |
|
53 |
- ------------- |
|
54 |
- type: rec_lock_t |
|
55 |
- rec_lock_t* rec_lock_alloc(); - allocates a lock in shared mem. |
|
56 |
- rec_lock_t* rec_lock_init(rec_lock_t* lock); - inits the lock |
|
57 |
- void rec_lock_destroy(rec_lock_t* lock); - removes the lock (e.g sysv rmid) |
|
58 |
- void rec_lock_dealloc(rec_lock_t* lock); - deallocates the lock's shared m. |
|
59 |
- void rec_lock_get(rec_lock_t* lock); - lock (mutex down) |
|
60 |
- void rec_lock_release(rec_lock_t* lock); - unlock (mutex up) |
|
61 |
- |
|
62 |
-WARNING: - lock_set_init may fail for large number of sems (e.g. sysv). |
|
63 |
- - signals are not treated! (some locks are "awakened" by the signals) |
|
64 |
-*/ |
|
65 |
- |
|
66 |
-#ifndef _locking_h |
|
67 |
-#define _locking_h |
|
68 |
- |
|
69 |
-/* the order is important */ |
|
70 |
-#include "lock_ops.h" |
|
71 |
-#include "lock_alloc.h" |
|
72 |
-#include "atomic_ops.h" |
|
73 |
- |
|
74 |
-typedef struct rec_lock { |
|
75 |
- gen_lock_t lock; /* mutex to access items in the slot */ |
|
76 |
- atomic_t locker_pid; /* pid of the process that holds the lock */ |
|
77 |
- int rec_lock_level; /* recursive lock count */ |
|
78 |
-} rec_lock_t; |
|
79 |
- |
|
80 |
-rec_lock_t* rec_lock_alloc(); |
|
81 |
-rec_lock_t* rec_lock_init(rec_lock_t* lock); |
|
82 |
-void rec_lock_destroy(rec_lock_t* lock); |
|
83 |
-void rec_lock_dealloc(rec_lock_t* lock); |
|
84 |
-void rec_lock_get(rec_lock_t* lock); |
|
85 |
-void rec_lock_release(rec_lock_t* lock); |
|
86 |
- |
|
87 |
-#endif |
- new structure rec_lock_t
- api functions:
- rec_lock_alloc()
- rec_lock_init(rlock)
- rec_lock_destroy(rlock)
- rec_lock_dealloc(rlock)
- rec_lock_get(rlock)
- rec_lock_release(rlock)
... | ... |
@@ -14,8 +14,8 @@ |
14 | 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | 15 |
* GNU General Public License for more details. |
16 | 16 |
* |
17 |
- * You should have received a copy of the GNU General Public License |
|
18 |
- * along with this program; if not, write to the Free Software |
|
17 |
+ * You should have received a copy of the GNU General Public License |
|
18 |
+ * along with this program; if not, write to the Free Software |
|
19 | 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | 20 |
*/ |
21 | 21 |
|
... | ... |
@@ -38,7 +38,7 @@ Implements (in lock_ops.h & lock_alloc.h): |
38 | 38 |
void lock_dealloc(gen_lock_t* lock); - deallocates the lock's shared m. |
39 | 39 |
void lock_get(gen_lock_t* lock); - lock (mutex down) |
40 | 40 |
void lock_release(gen_lock_t* lock); - unlock (mutex up) |
41 |
- |
|
41 |
+ |
|
42 | 42 |
lock sets: |
43 | 43 |
---------- |
44 | 44 |
type: gen_lock_set_t |
... | ... |
@@ -49,7 +49,17 @@ Implements (in lock_ops.h & lock_alloc.h): |
49 | 49 |
void lock_set_get(gen_lock_set_t* s, int i); - locks sem i from the set |
50 | 50 |
void lock_set_release(gen_lock_set_t* s, int i) - unlocks sem i from the set |
51 | 51 |
|
52 |
-WARNING: - lock_set_init may fail for large number of sems (e.g. sysv). |
|
52 |
+ recursive locks: |
|
53 |
+ ------------- |
|
54 |
+ type: rec_lock_t |
|
55 |
+ rec_lock_t* rec_lock_alloc(); - allocates a lock in shared mem. |
|
56 |
+ rec_lock_t* rec_lock_init(rec_lock_t* lock); - inits the lock |
|
57 |
+ void rec_lock_destroy(rec_lock_t* lock); - removes the lock (e.g sysv rmid) |
|
58 |
+ void rec_lock_dealloc(rec_lock_t* lock); - deallocates the lock's shared m. |
|
59 |
+ void rec_lock_get(rec_lock_t* lock); - lock (mutex down) |
|
60 |
+ void rec_lock_release(rec_lock_t* lock); - unlock (mutex up) |
|
61 |
+ |
|
62 |
+WARNING: - lock_set_init may fail for large number of sems (e.g. sysv). |
|
53 | 63 |
- signals are not treated! (some locks are "awakened" by the signals) |
54 | 64 |
*/ |
55 | 65 |
|
... | ... |
@@ -58,6 +68,20 @@ WARNING: - lock_set_init may fail for large number of sems (e.g. sysv). |
58 | 68 |
|
59 | 69 |
/* the order is important */ |
60 | 70 |
#include "lock_ops.h" |
61 |
-#include "lock_alloc.h" |
|
71 |
+#include "lock_alloc.h" |
|
72 |
+#include "atomic_ops.h" |
|
73 |
+ |
|
74 |
+typedef struct rec_lock { |
|
75 |
+ gen_lock_t lock; /* mutex to access items in the slot */ |
|
76 |
+ atomic_t locker_pid; /* pid of the process that holds the lock */ |
|
77 |
+ int rec_lock_level; /* recursive lock count */ |
|
78 |
+} rec_lock_t; |
|
79 |
+ |
|
80 |
+rec_lock_t* rec_lock_alloc(); |
|
81 |
+rec_lock_t* rec_lock_init(rec_lock_t* lock); |
|
82 |
+void rec_lock_destroy(rec_lock_t* lock); |
|
83 |
+void rec_lock_dealloc(rec_lock_t* lock); |
|
84 |
+void rec_lock_get(rec_lock_t* lock); |
|
85 |
+void rec_lock_release(rec_lock_t* lock); |
|
62 | 86 |
|
63 | 87 |
#endif |
... | ... |
@@ -1,21 +1,15 @@ |
1 |
-/* $Id$ */ |
|
2 | 1 |
/* |
3 | 2 |
* |
4 | 3 |
* Copyright (C) 2001-2003 FhG Fokus |
5 | 4 |
* |
6 |
- * This file is part of ser, a free SIP server. |
|
5 |
+ * This file is part of Kamailio, a free SIP server. |
|
7 | 6 |
* |
8 |
- * ser is free software; you can redistribute it and/or modify |
|
7 |
+ * Kamailio is free software; you can redistribute it and/or modify |
|
9 | 8 |
* it under the terms of the GNU General Public License as published by |
10 | 9 |
* the Free Software Foundation; either version 2 of the License, or |
11 | 10 |
* (at your option) any later version |
12 | 11 |
* |
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, |
|
12 |
+ * Kamailio is distributed in the hope that it will be useful, |
|
19 | 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 | 15 |
* GNU General Public License for more details. |
... | ... |
@@ -25,17 +19,13 @@ |
25 | 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
26 | 20 |
*/ |
27 | 21 |
|
28 |
-/* |
|
29 |
- * ser locking library |
|
22 |
+/*! |
|
23 |
+* \file |
|
24 |
+* \brief Kamailio core :: Kamailio locking library |
|
25 |
+* \ingroup core |
|
26 |
+* \author andrei |
|
27 |
+* Module: \ref core |
|
30 | 28 |
* |
31 |
- * 2002-12-16 created by andrei |
|
32 |
- * 2003-02-20 s/gen_lock_t/gen_lock_t/ to avoid a type conflict |
|
33 |
- * on solaris (andrei) |
|
34 |
- * 2003-03-05 lock set support added for FAST_LOCK & SYSV (andrei) |
|
35 |
- * 2003-03-06 split in two: lock_ops.h & lock_alloc.h, to avoid |
|
36 |
- * shm_mem.h<->locking.h interdependency (andrei) |
|
37 |
- * 2004-07-28 s/lock_set_t/gen_lock_set_t/ because of a type conflict |
|
38 |
- * on darwin (andrei) |
|
39 | 29 |
* |
40 | 30 |
Implements (in lock_ops.h & lock_alloc.h): |
41 | 31 |
|
... | ... |
@@ -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 |
/* |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
/* $Id$ */ |
2 | 2 |
/* |
3 | 3 |
* |
4 |
- * Copyright (C) 2001-2003 Fhg Fokus |
|
4 |
+ * Copyright (C) 2001-2003 FhG Fokus |
|
5 | 5 |
* |
6 | 6 |
* This file is part of ser, a free SIP server. |
7 | 7 |
* |
... | ... |
@@ -32,7 +32,7 @@ |
32 | 32 |
* 2003-02-20 s/gen_lock_t/gen_lock_t/ to avoid a type conflict |
33 | 33 |
* on solaris (andrei) |
34 | 34 |
* 2003-03-05 lock set support added for FAST_LOCK & SYSV (andrei) |
35 |
- * 2003-03-06 splited in two: lock_ops.h & lock_alloc.h, to avoid |
|
35 |
+ * 2003-03-06 split in two: lock_ops.h & lock_alloc.h, to avoid |
|
36 | 36 |
* shm_mem.h<->locking.h interdependency (andrei) |
37 | 37 |
* 2004-07-28 s/lock_set_t/gen_lock_set_t/ because of a type conflict |
38 | 38 |
* on darwin (andrei) |
... | ... |
@@ -34,6 +34,8 @@ |
34 | 34 |
* 2003-03-05 lock set support added for FAST_LOCK & SYSV (andrei) |
35 | 35 |
* 2003-03-06 splited in two: lock_ops.h & lock_alloc.h, to avoid |
36 | 36 |
* shm_mem.h<->locking.h interdependency (andrei) |
37 |
+ * 2004-07-28 s/lock_set_t/gen_lock_set_t/ because of a type conflict |
|
38 |
+ * on darwin (andrei) |
|
37 | 39 |
* |
38 | 40 |
Implements (in lock_ops.h & lock_alloc.h): |
39 | 41 |
|
... | ... |
@@ -49,13 +51,13 @@ Implements (in lock_ops.h & lock_alloc.h): |
49 | 51 |
|
50 | 52 |
lock sets: |
51 | 53 |
---------- |
52 |
- type: lock_set_t |
|
53 |
- lock_set_t* lock_set_alloc(no) - allocs a lock set in shm. |
|
54 |
- lock_set_t* lock_set_init(lock_set_t* set); - inits the lock set |
|
55 |
- void lock_set_destroy(lock_set_t* s); - removes the lock set |
|
56 |
- void lock_set_dealloc(lock_set_t* s); - deallocs the lock set shm. |
|
57 |
- void lock_set_get(lock_set_t* s, int i); - locks sem i from the set |
|
58 |
- void lock_set_release(lock_set_t* s, int i) - unlocks sem i from the set |
|
54 |
+ type: gen_lock_set_t |
|
55 |
+ gen_lock_set_t* lock_set_alloc(no) - allocs a lock set in shm. |
|
56 |
+ gen_lock_set_t* lock_set_init(gen_lock_set_t* set); - inits the lock set |
|
57 |
+ void lock_set_destroy(gen_lock_set_t* s); - removes the lock set |
|
58 |
+ void lock_set_dealloc(gen_lock_set_t* s); - deallocs the lock set shm. |
|
59 |
+ void lock_set_get(gen_lock_set_t* s, int i); - locks sem i from the set |
|
60 |
+ void lock_set_release(gen_lock_set_t* s, int i) - unlocks sem i from the set |
|
59 | 61 |
|
60 | 62 |
WARNING: - lock_set_init may fail for large number of sems (e.g. sysv). |
61 | 63 |
- signals are not treated! (some locks are "awakened" by the signals) |
... | ... |
@@ -57,7 +57,8 @@ Implements (in lock_ops.h & lock_alloc.h): |
57 | 57 |
void lock_set_get(lock_set_t* s, int i); - locks sem i from the set |
58 | 58 |
void lock_set_release(lock_set_t* s, int i) - unlocks sem i from the set |
59 | 59 |
|
60 |
-WARNING: signals are not treated! (some locks are "awakened" by the signals) |
|
60 |
+WARNING: - lock_set_init may fail for large number of sems (e.g. sysv). |
|
61 |
+ - signals are not treated! (some locks are "awakened" by the signals) |
|
61 | 62 |
*/ |
62 | 63 |
|
63 | 64 |
#ifndef _locking_h |
... | ... |
@@ -39,6 +39,7 @@ Implements (in lock_ops.h & lock_alloc.h): |
39 | 39 |
|
40 | 40 |
simple locks: |
41 | 41 |
------------- |
42 |
+ type: gen_lock_t |
|
42 | 43 |
gen_lock_t* lock_alloc(); - allocates a lock in shared mem. |
43 | 44 |
gen_lock_t* lock_init(gen_lock_t* lock); - inits the lock |
44 | 45 |
void lock_destroy(gen_lock_t* lock); - removes the lock (e.g sysv rmid) |
... | ... |
@@ -46,8 +47,9 @@ Implements (in lock_ops.h & lock_alloc.h): |
46 | 47 |
void lock_get(gen_lock_t* lock); - lock (mutex down) |
47 | 48 |
void lock_release(gen_lock_t* lock); - unlock (mutex up) |
48 | 49 |
|
49 |
- lock sets: [implemented only for FL & SYSV so far] |
|
50 |
+ lock sets: |
|
50 | 51 |
---------- |
52 |
+ type: lock_set_t |
|
51 | 53 |
lock_set_t* lock_set_alloc(no) - allocs a lock set in shm. |
52 | 54 |
lock_set_t* lock_set_init(lock_set_t* set); - inits the lock set |
53 | 55 |
void lock_set_destroy(lock_set_t* s); - removes the lock set |
... | ... |
@@ -31,155 +31,38 @@ |
31 | 31 |
* 2002-12-16 created by andrei |
32 | 32 |
* 2003-02-20 s/gen_lock_t/gen_lock_t/ to avoid a type conflict |
33 | 33 |
* on solaris (andrei) |
34 |
+ * 2003-03-05 lock set support added for FAST_LOCK & SYSV (andrei) |
|
35 |
+ * 2003-03-06 splited in two: lock_ops.h & lock_alloc.h, to avoid |
|
36 |
+ * shm_mem.h<->locking.h interdependency (andrei) |
|
34 | 37 |
* |
35 |
-Implements: |
|
36 |
- |
|
37 |
- gen_lock_t* lock_alloc(); - allocates a lock in shared mem. |
|
38 |
- gen_lock_t* lock_init(gen_lock_t* lock); - inits the lock |
|
39 |
- void lock_destroy(gen_lock_t* lock); - removes the lock (e.g sysv rmid) |
|
40 |
- void lock_dealloc(gen_lock_t* lock); - deallocates the lock's shared m. |
|
41 |
- void lock_get(gen_lock_t* lock); - lock (mutex down) |
|
42 |
- void lock_release(gen_lock_t* lock); - unlock (mutex up) |
|
38 |
+Implements (in lock_ops.h & lock_alloc.h): |
|
39 |
+ |
|
40 |
+ simple locks: |
|
41 |
+ ------------- |
|
42 |
+ gen_lock_t* lock_alloc(); - allocates a lock in shared mem. |
|
43 |
+ gen_lock_t* lock_init(gen_lock_t* lock); - inits the lock |
|
44 |
+ void lock_destroy(gen_lock_t* lock); - removes the lock (e.g sysv rmid) |
|
45 |
+ void lock_dealloc(gen_lock_t* lock); - deallocates the lock's shared m. |
|
46 |
+ void lock_get(gen_lock_t* lock); - lock (mutex down) |
|
47 |
+ void lock_release(gen_lock_t* lock); - unlock (mutex up) |
|
48 |
+ |
|
49 |
+ lock sets: [implemented only for FL & SYSV so far] |
|
50 |
+ ---------- |
|
51 |
+ lock_set_t* lock_set_alloc(no) - allocs a lock set in shm. |
|
52 |
+ lock_set_t* lock_set_init(lock_set_t* set); - inits the lock set |
|
53 |
+ void lock_set_destroy(lock_set_t* s); - removes the lock set |
|
54 |
+ void lock_set_dealloc(lock_set_t* s); - deallocs the lock set shm. |
|
55 |
+ void lock_set_get(lock_set_t* s, int i); - locks sem i from the set |
|
56 |
+ void lock_set_release(lock_set_t* s, int i) - unlocks sem i from the set |
|
57 |
+ |
|
58 |
+WARNING: signals are not treated! (some locks are "awakened" by the signals) |
|
43 | 59 |
*/ |
44 | 60 |
|
45 | 61 |
#ifndef _locking_h |
46 | 62 |
#define _locking_h |
47 | 63 |
|
48 |
- |
|
49 |
-#ifdef FAST_LOCK |
|
50 |
-#include "fastlock.h" |
|
51 |
- |
|
52 |
-typedef fl_lock_t gen_lock_t; |
|
53 |
- |
|
54 |
-#define lock_alloc() shm_malloc(sizeof(gen_lock_t)) |
|
55 |
-#define lock_destroy(lock) /* do nothing */ |
|
56 |
-#define lock_dealloc(lock) shm_free(lock) |
|
57 |
- |
|
58 |
-inline static gen_lock_t* lock_init(gen_lock_t* lock) |
|
59 |
-{ |
|
60 |
- init_lock(*lock); |
|
61 |
- return lock; |
|
62 |
-} |
|
63 |
- |
|
64 |
-#define lock_get(lock) get_lock(lock) |
|
65 |
-#define lock_release(lock) release_lock(lock) |
|
66 |
- |
|
67 |
- |
|
68 |
- |
|
69 |
-#elif defined USE_PTHREAD_MUTEX |
|
70 |
-#include <pthread.h> |
|
71 |
- |
|
72 |
-typedef pthread_mutex_t gen_lock_t; |
|
73 |
- |
|
74 |
-#define lock_alloc() shm_malloc(sizeof(gen_lock_t)) |
|
75 |
-#define lock_destroy(lock) /* do nothing */ |
|
76 |
-#define lock_dealloc(lock) shm_free(lock) |
|
77 |
- |
|
78 |
-inline static gen_lock_t* lock_init(gen_lock_t* lock) |
|
79 |
-{ |
|
80 |
- if (pthread_mutex_init(lock, 0)==0) return lock; |
|
81 |
- else return 0; |
|
82 |
-} |
|
83 |
- |
|
84 |
-#define lock_get(lock) pthread_mutex_lock(lock) |
|
85 |
-#define lock_release(lock) pthread_mutex_unlock(lock) |
|
86 |
- |
|
87 |
- |
|
88 |
- |
|
89 |
-#elif defined USE_POSIX_SEM |
|
90 |
-#include <semaphore.h> |
|
91 |
- |
|
92 |
-typedef sem_t gen_lock_t; |
|
93 |
- |
|
94 |
-#define lock_alloc() shm_malloc(sizeof(gen_lock_t)) |
|
95 |
-#define lock_destroy(lock) /* do nothing */ |
|
96 |
-#define lock_dealloc(lock) shm_free(lock) |
|
97 |
- |
|
98 |
-inline static gen_lock_t* lock_init(gen_lock_t* lock) |
|
99 |
-{ |
|
100 |
- if (sem_init(lock, 1, 1)<0) return 0; |
|
101 |
- return lock; |
|
102 |
-} |
|
103 |
- |
|
104 |
-#define lock_get(lock) sem_wait(lock) |
|
105 |
-#define lock_release(lock) sem_post(lock) |
|
106 |
- |
|
107 |
- |
|
108 |
-#elif defined USE_SYSV_SEM |
|
109 |
-#include <sys/ipc.h> |
|
110 |
-#include <sys/sem.h> |
|
111 |
- |
|
112 |
-#if ((defined(HAVE_UNION_SEMUN) || defined(__GNU_LIBRARY__) )&& !defined(_SEM_SEMUN_UNDEFINED)) |
|
113 |
- |
|
114 |
- /* union semun is defined by including sem.h */ |
|
115 |
-#else |
|
116 |
- /* according to X/OPEN we have to define it ourselves */ |
|
117 |
- union semun { |
|
118 |
- int val; /* value for SETVAL */ |
|
119 |
- struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ |
|
120 |
- unsigned short int *array; /* array for GETALL, SETALL */ |
|
121 |
- struct seminfo *__buf; /* buffer for IPC_INFO */ |
|
122 |
- }; |
|
123 |
-#endif |
|
124 |
- |
|
125 |
-typedef int gen_lock_t; |
|
126 |
- |
|
127 |
-#define lock_alloc() shm_malloc(sizeof(gen_lock_t)) |
|
128 |
-#define lock_dealloc(lock) shm_free(lock) |
|
129 |
- |
|
130 |
- |
|
131 |
-inline static gen_lock_t* lock_init(gen_lock_t* lock) |
|
132 |
-{ |
|
133 |
- union semun su; |
|
134 |
- |
|
135 |
- *lock=semget(IPC_PRIVATE, 1, 0700); |
|
136 |
- if (*lock==-1) return 0; |
|
137 |
- su.val=1; |
|
138 |
- if (semctl(*lock, 0, SETVAL, su)==-1){ |
|
139 |
- /* init error*/ |
|
140 |
- return 0; |
|
141 |
- } |
|
142 |
- return lock; |
|
143 |
-} |
|
144 |
- |
|
145 |
-inline static void lock_destroy(gen_lock_t* lock) |
|
146 |
-{ |
|
147 |
- semctl(*lock, 0, IPC_RMID, (union semun)(int)0); |
|
148 |
-} |
|
149 |
- |
|
150 |
-#define lock_dealloc(lock) shm_free(lock) |
|
151 |
- |
|
152 |
-inline static void lock_get(gen_lock_t* lock) |
|
153 |
-{ |
|
154 |
- struct sembuf sop; |
|
155 |
- |
|
156 |
- sop.sem_num=0; |
|
157 |
- sop.sem_op=-1; /* down */ |
|
158 |
- sop.sem_flg=0; /*SEM_UNDO*/ |
|
159 |
- semop(*lock, &sop, 1); |
|
160 |
-} |
|
161 |
- |
|
162 |
-inline static void lock_release(gen_lock_t* lock) |
|
163 |
-{ |
|
164 |
- struct sembuf sop; |
|
165 |
- |
|
166 |
- sop.sem_num=0; |
|
167 |
- sop.sem_op=1; /* up */ |
|
168 |
- sop.sem_flg=0; /* SEM_UNDO*/ |
|
169 |
- semop(*lock, &sop, 1); |
|
170 |
-} |
|
171 |
- |
|
172 |
-#else |
|
173 |
-#error "no locking method selected" |
|
174 |
-#endif |
|
175 |
- |
|
176 |
- |
|
177 |
-/*shm_{malloc, free}*/ |
|
178 |
-#include "mem/mem.h" |
|
179 |
-#ifdef SHM_MEM |
|
180 |
-#include "mem/shm_mem.h" |
|
181 |
-#else |
|
182 |
-#error "locking requires shared memroy support" |
|
183 |
-#endif |
|
64 |
+/* the order is important */ |
|
65 |
+#include "lock_ops.h" |
|
66 |
+#include "lock_alloc.h" |
|
184 | 67 |
|
185 | 68 |
#endif |
... | ... |
@@ -28,17 +28,18 @@ |
28 | 28 |
/* |
29 | 29 |
* ser locking library |
30 | 30 |
* |
31 |
- * 2002-12-16 created by andrei |
|
32 |
- * |
|
31 |
+ * 2002-12-16 created by andrei |
|
32 |
+ * 2003-02-20 s/gen_lock_t/gen_lock_t/ to avoid a type conflict |
|
33 |
+ * on solaris (andrei) |
|
33 | 34 |
* |
34 | 35 |
Implements: |
35 | 36 |
|
36 |
- lock_t* lock_alloc(); - allocates a lock in shared mem. |
|
37 |
- lock_t* lock_init(lock_t* lock); - inits the lock |
|
38 |
- void lock_destroy(lock_t* lock); - removes the lock (e.g sysv rmid) |
|
39 |
- void lock_dealloc(lock_t* lock); - deallocates the lock's shared m. |
|
40 |
- void lock_get(lock_t* lock); - lock (mutex down) |
|
41 |
- void lock_release(lock_t* lock); - unlock (mutex up) |
|
37 |
+ gen_lock_t* lock_alloc(); - allocates a lock in shared mem. |
|
38 |
+ gen_lock_t* lock_init(gen_lock_t* lock); - inits the lock |
|
39 |
+ void lock_destroy(gen_lock_t* lock); - removes the lock (e.g sysv rmid) |
|
40 |
+ void lock_dealloc(gen_lock_t* lock); - deallocates the lock's shared m. |
|
41 |
+ void lock_get(gen_lock_t* lock); - lock (mutex down) |
|
42 |
+ void lock_release(gen_lock_t* lock); - unlock (mutex up) |
|
42 | 43 |
*/ |
43 | 44 |
|
44 | 45 |
#ifndef _locking_h |
... | ... |
@@ -48,13 +49,13 @@ Implements: |
48 | 49 |
#ifdef FAST_LOCK |
49 | 50 |
#include "fastlock.h" |
50 | 51 |
|
51 |
-typedef fl_lock_t lock_t; |
|
52 |
+typedef fl_lock_t gen_lock_t; |
|
52 | 53 |
|
53 |
-#define lock_alloc() shm_malloc(sizeof(lock_t)) |
|
54 |
+#define lock_alloc() shm_malloc(sizeof(gen_lock_t)) |
|
54 | 55 |
#define lock_destroy(lock) /* do nothing */ |
55 | 56 |
#define lock_dealloc(lock) shm_free(lock) |
56 | 57 |
|
57 |
-inline static lock_t* lock_init(lock_t* lock) |
|
58 |
+inline static gen_lock_t* lock_init(gen_lock_t* lock) |
|
58 | 59 |
{ |
59 | 60 |
init_lock(*lock); |
60 | 61 |
return lock; |
... | ... |
@@ -68,13 +69,13 @@ inline static lock_t* lock_init(lock_t* lock) |
68 | 69 |
#elif defined USE_PTHREAD_MUTEX |
69 | 70 |
#include <pthread.h> |
70 | 71 |
|
71 |
-typedef pthread_mutex_t lock_t; |
|
72 |
+typedef pthread_mutex_t gen_lock_t; |
|
72 | 73 |
|
73 |
-#define lock_alloc() shm_malloc(sizeof(lock_t)) |
|
74 |
+#define lock_alloc() shm_malloc(sizeof(gen_lock_t)) |
|
74 | 75 |
#define lock_destroy(lock) /* do nothing */ |
75 | 76 |
#define lock_dealloc(lock) shm_free(lock) |
76 | 77 |
|
77 |
-inline static lock_t* lock_init(lock_t* lock) |
|
78 |
+inline static gen_lock_t* lock_init(gen_lock_t* lock) |
|
78 | 79 |
{ |
79 | 80 |
if (pthread_mutex_init(lock, 0)==0) return lock; |
80 | 81 |
else return 0; |
... | ... |
@@ -88,13 +89,13 @@ inline static lock_t* lock_init(lock_t* lock) |
88 | 89 |
#elif defined USE_POSIX_SEM |
89 | 90 |
#include <semaphore.h> |
90 | 91 |
|
91 |
-typedef sem_t lock_t; |
|
92 |
+typedef sem_t gen_lock_t; |
|
92 | 93 |
|
93 |
-#define lock_alloc() shm_malloc(sizeof(lock_t)) |
|
94 |
+#define lock_alloc() shm_malloc(sizeof(gen_lock_t)) |
|
94 | 95 |
#define lock_destroy(lock) /* do nothing */ |
95 | 96 |
#define lock_dealloc(lock) shm_free(lock) |
96 | 97 |
|
97 |
-inline static lock_t* lock_init(lock_t* lock) |
|
98 |
+inline static gen_lock_t* lock_init(gen_lock_t* lock) |
|
98 | 99 |
{ |
99 | 100 |
if (sem_init(lock, 1, 1)<0) return 0; |
100 | 101 |
return lock; |
... | ... |
@@ -121,13 +122,13 @@ inline static lock_t* lock_init(lock_t* lock) |
121 | 122 |
}; |
122 | 123 |
#endif |
123 | 124 |
|
124 |
-typedef int lock_t; |
|
125 |
+typedef int gen_lock_t; |
|
125 | 126 |
|
126 |
-#define lock_alloc() shm_malloc(sizeof(lock_t)) |
|
127 |
+#define lock_alloc() shm_malloc(sizeof(gen_lock_t)) |
|
127 | 128 |
#define lock_dealloc(lock) shm_free(lock) |
128 | 129 |
|
129 | 130 |
|
130 |
-inline static lock_t* lock_init(lock_t* lock) |
|
131 |
+inline static gen_lock_t* lock_init(gen_lock_t* lock) |
|
131 | 132 |
{ |
132 | 133 |
union semun su; |
133 | 134 |
|
... | ... |
@@ -141,14 +142,14 @@ inline static lock_t* lock_init(lock_t* lock) |
141 | 142 |
return lock; |
142 | 143 |
} |
143 | 144 |
|
144 |
-inline static void lock_destroy(lock_t* lock) |
|
145 |
+inline static void lock_destroy(gen_lock_t* lock) |
|
145 | 146 |
{ |
146 | 147 |
semctl(*lock, 0, IPC_RMID, (union semun)(int)0); |
147 | 148 |
} |
148 | 149 |
|
149 | 150 |
#define lock_dealloc(lock) shm_free(lock) |
150 | 151 |
|
151 |
-inline static void lock_get(lock_t* lock) |
|
152 |
+inline static void lock_get(gen_lock_t* lock) |
|
152 | 153 |
{ |
153 | 154 |
struct sembuf sop; |
154 | 155 |
|
... | ... |
@@ -158,7 +159,7 @@ inline static void lock_get(lock_t* lock) |
158 | 159 |
semop(*lock, &sop, 1); |
159 | 160 |
} |
160 | 161 |
|
161 |
-inline static void lock_release(lock_t* lock) |
|
162 |
+inline static void lock_release(gen_lock_t* lock) |
|
162 | 163 |
{ |
163 | 164 |
struct sembuf sop; |
164 | 165 |
|
... | ... |
@@ -44,12 +44,6 @@ Implements: |
44 | 44 |
#ifndef _locking_h |
45 | 45 |
#define _locking_h |
46 | 46 |
|
47 |
-#include "mem/mem.h" |
|
48 |
-#ifdef SHM_MEM |
|
49 |
-#include "mem/shm_mem.h" |
|
50 |
-#else |
|
51 |
-#error "locking requires shared memroy support" |
|
52 |
-#endif |
|
53 | 47 |
|
54 | 48 |
#ifdef FAST_LOCK |
55 | 49 |
#include "fastlock.h" |
... | ... |
@@ -179,5 +173,12 @@ inline static void lock_release(lock_t* lock) |
179 | 173 |
#endif |
180 | 174 |
|
181 | 175 |
|
176 |
+/*shm_{malloc, free}*/ |
|
177 |
+#include "mem/mem.h" |
|
178 |
+#ifdef SHM_MEM |
|
179 |
+#include "mem/shm_mem.h" |
|
180 |
+#else |
|
181 |
+#error "locking requires shared memroy support" |
|
182 |
+#endif |
|
182 | 183 |
|
183 | 184 |
#endif |
... | ... |
@@ -26,9 +26,11 @@ |
26 | 26 |
*/ |
27 | 27 |
|
28 | 28 |
/* |
29 |
- ser locking library |
|
30 |
- - created 16.12.2003 (andrei) |
|
31 |
- |
|
29 |
+ * ser locking library |
|
30 |
+ * |
|
31 |
+ * 2002-12-16 created by andrei |
|
32 |
+ * |
|
33 |
+ * |
|
32 | 34 |
Implements: |
33 | 35 |
|
34 | 36 |
lock_t* lock_alloc(); - allocates a lock in shared mem. |
... | ... |
@@ -100,7 +102,7 @@ typedef sem_t lock_t; |
100 | 102 |
|
101 | 103 |
inline static lock_t* lock_init(lock_t* lock) |
102 | 104 |
{ |
103 |
- if (sem_init(lock, 0, 1)<0) return 0; |
|
105 |
+ if (sem_init(lock, 1, 1)<0) return 0; |
|
104 | 106 |
return lock; |
105 | 107 |
} |
106 | 108 |
|
... | ... |
@@ -105,7 +105,7 @@ inline static lock_t* lock_init(lock_t* lock) |
105 | 105 |
} |
106 | 106 |
|
107 | 107 |
#define lock_get(lock) sem_wait(lock) |
108 |
-#define lock_release(lock) sem_release(lock) |
|
108 |
+#define lock_release(lock) sem_post(lock) |
|
109 | 109 |
|
110 | 110 |
|
111 | 111 |
#elif defined USE_SYSV_SEM |
... | ... |
@@ -127,21 +127,16 @@ inline static lock_t* lock_init(lock_t* lock) |
127 | 127 |
|
128 | 128 |
typedef int lock_t; |
129 | 129 |
|
130 |
-inline static lock_t* lock_alloc() |
|
131 |
-{ |
|
132 |
- lock_t* l; |
|
133 |
- |
|
134 |
- l=shm_malloc(sizeof(lock_t)); |
|
135 |
- if (l==0) return 0; |
|
136 |
- *l=semget(IPC_PRIVATE, 1, 0700); |
|
137 |
- if (*l==-1) return 0; |
|
138 |
- return l; |
|
139 |
-} |
|
130 |
+#define lock_alloc() shm_malloc(sizeof(lock_t)) |
|
131 |
+#define lock_dealloc(lock) shm_free(lock) |
|
140 | 132 |
|
141 | 133 |
|
142 | 134 |
inline static lock_t* lock_init(lock_t* lock) |
143 | 135 |
{ |
144 | 136 |
union semun su; |
137 |
+ |
|
138 |
+ *lock=semget(IPC_PRIVATE, 1, 0700); |
|
139 |
+ if (*lock==-1) return 0; |
|
145 | 140 |
su.val=1; |
146 | 141 |
if (semctl(*lock, 0, SETVAL, su)==-1){ |
147 | 142 |
/* init error*/ |
... | ... |
@@ -157,7 +152,7 @@ inline static void lock_destroy(lock_t* lock) |
157 | 152 |
|
158 | 153 |
#define lock_dealloc(lock) shm_free(lock) |
159 | 154 |
|
160 |
-inline void lock_get(lock_t* lock) |
|
155 |
+inline static void lock_get(lock_t* lock) |
|
161 | 156 |
{ |
162 | 157 |
struct sembuf sop; |
163 | 158 |
|
... | ... |
@@ -167,7 +162,7 @@ inline void lock_get(lock_t* lock) |
167 | 162 |
semop(*lock, &sop, 1); |
168 | 163 |
} |
169 | 164 |
|
170 |
-inline void lock_release(lock_t* lock) |
|
165 |
+inline static void lock_release(lock_t* lock) |
|
171 | 166 |
{ |
172 | 167 |
struct sembuf sop; |
173 | 168 |
|
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,186 @@ |
1 |
+/* $Id$ */ |
|
2 |
+/* |
|
3 |
+ * |
|
4 |
+ * Copyright (C) 2001-2003 Fhg Fokus |
|
5 |
+ * |
|
6 |
+ * This file is part of ser, a free SIP server. |
|
7 |
+ * |
|
8 |
+ * ser is free software; you can redistribute it and/or modify |
|
9 |
+ * it under the terms of the GNU General Public License as published by |
|
10 |
+ * the Free Software Foundation; either version 2 of the License, or |
|
11 |
+ * (at your option) any later version |
|
12 |
+ * |
|
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, |
|
19 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21 |
+ * GNU General Public License for more details. |
|
22 |
+ * |
|
23 |
+ * You should have received a copy of the GNU General Public License |
|
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 |
|
26 |
+ */ |
|
27 |
+ |
|
28 |
+/* |
|
29 |
+ ser locking library |
|
30 |
+ - created 16.12.2003 (andrei) |
|
31 |
+ |
|
32 |
+Implements: |
|
33 |
+ |
|
34 |
+ lock_t* lock_alloc(); - allocates a lock in shared mem. |
|
35 |
+ lock_t* lock_init(lock_t* lock); - inits the lock |
|
36 |
+ void lock_destroy(lock_t* lock); - removes the lock (e.g sysv rmid) |
|
37 |
+ void lock_dealloc(lock_t* lock); - deallocates the lock's shared m. |
|
38 |
+ void lock_get(lock_t* lock); - lock (mutex down) |
|
39 |
+ void lock_release(lock_t* lock); - unlock (mutex up) |
|
40 |
+*/ |
|
41 |
+ |
|
42 |
+#ifndef _locking_h |
|
43 |
+#define _locking_h |
|
44 |
+ |
|
45 |
+#include "mem/mem.h" |
|
46 |
+#ifdef SHM_MEM |
|
47 |
+#include "mem/shm_mem.h" |
|
48 |
+#else |
|
49 |
+#error "locking requires shared memroy support" |
|
50 |
+#endif |
|
51 |
+ |
|
52 |
+#ifdef FAST_LOCK |
|
53 |
+#include "fastlock.h" |
|
54 |
+ |
|
55 |
+typedef fl_lock_t lock_t; |
|
56 |
+ |
|
57 |
+#define lock_alloc() shm_malloc(sizeof(lock_t)) |
|
58 |
+#define lock_destroy(lock) /* do nothing */ |
|
59 |
+#define lock_dealloc(lock) shm_free(lock) |
|
60 |
+ |
|
61 |
+inline static lock_t* lock_init(lock_t* lock) |
|
62 |
+{ |
|
63 |
+ init_lock(*lock); |
|
64 |
+ return lock; |
|
65 |
+} |
|
66 |
+ |
|
67 |
+#define lock_get(lock) get_lock(lock) |
|
68 |
+#define lock_release(lock) release_lock(lock) |
|
69 |
+ |
|
70 |
+ |
|
71 |
+ |
|
72 |
+#elif defined USE_PTHREAD_MUTEX |
|
73 |
+#include <pthread.h> |
|
74 |
+ |
|
75 |
+typedef pthread_mutex_t lock_t; |
|
76 |
+ |
|
77 |
+#define lock_alloc() shm_malloc(sizeof(lock_t)) |
|
78 |
+#define lock_destroy(lock) /* do nothing */ |
|
79 |
+#define lock_dealloc(lock) shm_free(lock) |
|
80 |
+ |
|
81 |
+inline static lock_t* lock_init(lock_t* lock) |
|
82 |
+{ |
|
83 |
+ if (pthread_mutex_init(lock, 0)==0) return lock; |
|
84 |
+ else return 0; |
|
85 |
+} |
|
86 |
+ |
|
87 |
+#define lock_get(lock) pthread_mutex_lock(lock) |
|
88 |
+#define lock_release(lock) pthread_mutex_unlock(lock) |
|
89 |
+ |
|
90 |
+ |
|
91 |
+ |
|
92 |
+#elif defined USE_POSIX_SEM |
|
93 |
+#include <semaphore.h> |
|
94 |
+ |
|
95 |
+typedef sem_t lock_t; |
|
96 |
+ |
|
97 |
+#define lock_alloc() shm_malloc(sizeof(lock_t)) |
|
98 |
+#define lock_destroy(lock) /* do nothing */ |
|
99 |
+#define lock_dealloc(lock) shm_free(lock) |
|
100 |
+ |
|
101 |
+inline static lock_t* lock_init(lock_t* lock) |
|
102 |
+{ |
|
103 |
+ if (sem_init(lock, 0, 1)<0) return 0; |
|
104 |
+ return lock; |
|
105 |
+} |
|
106 |
+ |
|
107 |
+#define lock_get(lock) sem_wait(lock) |
|
108 |
+#define lock_release(lock) sem_release(lock) |
|
109 |
+ |
|
110 |
+ |
|
111 |
+#elif defined USE_SYSV_SEM |
|
112 |
+#include <sys/ipc.h> |
|
113 |
+#include <sys/sem.h> |
|
114 |
+ |
|
115 |
+#if ((defined(HAVE_UNION_SEMUN) || defined(__GNU_LIBRARY__) )&& !defined(_SEM_SEMUN_UNDEFINED)) |
|
116 |
+ |
|
117 |
+ /* union semun is defined by including sem.h */ |
|
118 |
+#else |
|
119 |
+ /* according to X/OPEN we have to define it ourselves */ |
|
120 |
+ union semun { |
|
121 |
+ int val; /* value for SETVAL */ |
|
122 |
+ struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ |
|
123 |
+ unsigned short int *array; /* array for GETALL, SETALL */ |
|
124 |
+ struct seminfo *__buf; /* buffer for IPC_INFO */ |
|
125 |
+ }; |
|
126 |
+#endif |
|
127 |
+ |
|
128 |
+typedef int lock_t; |
|
129 |
+ |
|
130 |
+inline static lock_t* lock_alloc() |
|
131 |
+{ |
|
132 |
+ lock_t* l; |
|
133 |
+ |
|
134 |
+ l=shm_malloc(sizeof(lock_t)); |
|
135 |
+ if (l==0) return 0; |
|
136 |
+ *l=semget(IPC_PRIVATE, 1, 0700); |
|
137 |
+ if (*l==-1) return 0; |
|
138 |
+ return l; |
|
139 |
+} |
|
140 |
+ |
|
141 |
+ |
|
142 |
+inline static lock_t* lock_init(lock_t* lock) |
|
143 |
+{ |
|
144 |
+ union semun su; |
|
145 |
+ su.val=1; |
|
146 |
+ if (semctl(*lock, 0, SETVAL, su)==-1){ |
|
147 |
+ /* init error*/ |
|
148 |
+ return 0; |
|
149 |
+ } |
|
150 |
+ return lock; |
|
151 |
+} |
|
152 |
+ |
|
153 |
+inline static void lock_destroy(lock_t* lock) |
|
154 |
+{ |
|
155 |
+ semctl(*lock, 0, IPC_RMID, (union semun)(int)0); |
|
156 |
+} |
|
157 |
+ |
|
158 |
+#define lock_dealloc(lock) shm_free(lock) |
|
159 |
+ |
|
160 |
+inline void lock_get(lock_t* lock) |
|
161 |
+{ |
|
162 |
+ struct sembuf sop; |
|
163 |
+ |
|
164 |
+ sop.sem_num=0; |
|
165 |
+ sop.sem_op=-1; /* down */ |
|
166 |
+ sop.sem_flg=0; /*SEM_UNDO*/ |
|
167 |
+ semop(*lock, &sop, 1); |
|
168 |
+} |
|
169 |
+ |
|
170 |
+inline void lock_release(lock_t* lock) |
|
171 |
+{ |
|
172 |
+ struct sembuf sop; |
|
173 |
+ |
|
174 |
+ sop.sem_num=0; |
|
175 |
+ sop.sem_op=1; /* up */ |
|
176 |
+ sop.sem_flg=0; /* SEM_UNDO*/ |
|
177 |
+ semop(*lock, &sop, 1); |
|
178 |
+} |
|
179 |
+ |
|
180 |
+#else |
|
181 |
+#error "no locking method selected" |
|
182 |
+#endif |
|
183 |
+ |
|
184 |
+ |
|
185 |
+ |
|
186 |
+#endif |