Browse code

performance and bug fixes

Jiri Kuthan authored on 07/01/2002 04:39:49
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,160 +0,0 @@
1
-/* $Id$*
2
- *
3
- * shared mem stuff
4
- */
5
-
6
-#ifdef SHM_MEM
7
-
8
-#ifndef shm_mem_h
9
-#define shm_mem_h
10
-
11
-#include <string.h>
12
-#include <errno.h>
13
-#include <sys/types.h>
14
-#include <sys/ipc.h>
15
-
16
-#ifndef SHM_MMAP
17
-
18
-#include <sys/shm.h>
19
-
20
-#endif
21
-
22
-#include <sys/sem.h>
23
-#include <string.h>
24
-#include <errno.h>
25
-
26
-
27
-
28
-#include "q_malloc.h"
29
-#include "dprint.h"
30
-
31
-extern struct qm_block* shm_block;
32
-extern int shm_semid;
33
-
34
-int shm_mem_init();
35
-void shm_mem_destroy();
36
-
37
-
38
-
39
-inline static void shm_lock()
40
-{
41
-	struct sembuf sop;
42
-	
43
-	sop.sem_num=0;
44
-	sop.sem_op=-1; /*down*/
45
-	sop.sem_flg=0 /*SEM_UNDO*/;
46
-again:
47
-	semop(shm_semid, &sop, 1);
48
-#if 0
49
-	switch(ret){
50
-		case 0: /*ok*/
51
-			break;
52
-		case EINTR: /*interrupted by signal, try again*/
53
-			DBG("sh_lock: interrupted by signal, trying again...\n");
54
-			goto again;
55
-		default:
56
-			LOG(L_ERR, "ERROR: sh_lock: error waiting on semaphore: %s\n",
57
-					strerror(errno));
58
-	}
59
-#endif
60
-}
61
-
62
-
63
-
64
-inline static void shm_unlock()
65
-{
66
-	struct sembuf sop;
67
-	
68
-	sop.sem_num=0;
69
-	sop.sem_op=1; /*up*/
70
-	sop.sem_flg=0 /*SEM_UNDO*/;
71
-again:
72
-	semop(shm_semid, &sop, 1);
73
-#if 0
74
-	/*should ret immediately*/
75
-	switch(ret){
76
-		case 0: /*ok*/
77
-			break;
78
-		case EINTR: /*interrupted by signal, try again*/
79
-			DBG("sh_lock: interrupted by signal, trying again...\n");
80
-			goto again;
81
-		default:
82
-			LOG(L_ERR, "ERROR: sh_lock: error waiting on semaphore: %s\n",
83
-					strerror(errno));
84
-	}
85
-#endif
86
-}
87
-
88
-
89
-
90
-#ifdef DBG_QM_MALLOC
91
-#define shm_malloc(size) \
92
-({\
93
-	void *p;\
94
-	\
95
-	/*if (shm_lock()==0){*/\
96
-		shm_lock();\
97
-		p=qm_malloc(shm_block, (size), __FILE__, __FUNCTION__, __LINE__);\
98
-		shm_unlock();\
99
-	/* \
100
-	}else{ \
101
-		p=0;\
102
-	}*/ \
103
-	 p; \
104
-})
105
-
106
-
107
-
108
-#define shm_free(p) \
109
-do { \
110
-		shm_lock(); \
111
-		qm_free(shm_block, (p), __FILE__, __FUNCTION__, __LINE__); \
112
-		shm_unlock(); \
113
-}while(0)
114
-
115
-
116
-#else
117
-
118
-
119
-#define shm_malloc(size) \
120
-({\
121
-	void *p;\
122
-	\
123
-	/*if (shm_lock()==0){*/\
124
-		shm_lock();\
125
-		p=qm_malloc(shm_block, (size));\
126
-		shm_unlock();\
127
-	/* \
128
-	}else{ \
129
-		p=0;\
130
-	}*/ \
131
-	 p; \
132
-})
133
-
134
-
135
-
136
-#define shm_free(p) \
137
-do { \
138
-		shm_lock(); \
139
-		qm_free(shm_block, (p)); \
140
-		shm_unlock(); \
141
-}while(0)
142
-
143
-
144
-#endif
145
-
146
-
147
-#define shm_status() \
148
-do { \
149
-		shm_lock(); \
150
-		qm_status(shm_block); \
151
-		shm_unlock(); \
152
-}while(0)
153
-
154
-
155
-	
156
-
157
-#endif
158
-
159
-#endif
160
-
Browse code

- fixed minor Makefile bugs - added mmap shm support (-DSHM_MMAP) - etc

Andrei Pelinescu-Onciul authored on 11/12/2001 02:14:00
Showing 1 changed files
... ...
@@ -12,7 +12,13 @@
12 12
 #include <errno.h>
13 13
 #include <sys/types.h>
14 14
 #include <sys/ipc.h>
15
+
16
+#ifndef SHM_MMAP
17
+
15 18
 #include <sys/shm.h>
19
+
20
+#endif
21
+
16 22
 #include <sys/sem.h>
17 23
 #include <string.h>
18 24
 #include <errno.h>
Browse code

- added DBG_QM_MALLOC, when defined qm_malloc & friends (pkg_, shm_) record and display a lot of debuging info (line no, file name, function name); also some extra checks are done (trying to free a pointer twice, trying to free a pointer allocated by other malloc)

Andrei Pelinescu-Onciul authored on 04/12/2001 18:10:50
Showing 1 changed files
... ...
@@ -80,31 +80,63 @@ again:
80 80
 }
81 81
 
82 82
 
83
-inline static void* shm_malloc(unsigned int size)
84
-{
85
-	void *p;
86
-	
87
-	/*if (shm_lock()==0){*/
88
-		shm_lock();
89
-		p=qm_malloc(shm_block, size);
90
-		shm_unlock();
91
-	/*
92
-	}else{
93
-		p=0;
94
-	}*/
95
-	return p;
96
-}
83
+
84
+#ifdef DBG_QM_MALLOC
85
+#define shm_malloc(size) \
86
+({\
87
+	void *p;\
88
+	\
89
+	/*if (shm_lock()==0){*/\
90
+		shm_lock();\
91
+		p=qm_malloc(shm_block, (size), __FILE__, __FUNCTION__, __LINE__);\
92
+		shm_unlock();\
93
+	/* \
94
+	}else{ \
95
+		p=0;\
96
+	}*/ \
97
+	 p; \
98
+})
99
+
100
+
101
+
102
+#define shm_free(p) \
103
+do { \
104
+		shm_lock(); \
105
+		qm_free(shm_block, (p), __FILE__, __FUNCTION__, __LINE__); \
106
+		shm_unlock(); \
107
+}while(0)
108
+
109
+
110
+#else
111
+
112
+
113
+#define shm_malloc(size) \
114
+({\
115
+	void *p;\
116
+	\
117
+	/*if (shm_lock()==0){*/\
118
+		shm_lock();\
119
+		p=qm_malloc(shm_block, (size));\
120
+		shm_unlock();\
121
+	/* \
122
+	}else{ \
123
+		p=0;\
124
+	}*/ \
125
+	 p; \
126
+})
97 127
 
98 128
 
99 129
 
100 130
 #define shm_free(p) \
101 131
 do { \
102 132
 		shm_lock(); \
103
-		qm_free(shm_block, p); \
133
+		qm_free(shm_block, (p)); \
104 134
 		shm_unlock(); \
105 135
 }while(0)
106 136
 
107 137
 
138
+#endif
139
+
108 140
 
109 141
 #define shm_status() \
110 142
 do { \
Browse code

- enabled locking in shm_malloc/free/... - added locking test program

Andrei Pelinescu-Onciul authored on 03/12/2001 21:45:59
Showing 1 changed files
... ...
@@ -38,7 +38,7 @@ inline static void shm_lock()
38 38
 	sop.sem_op=-1; /*down*/
39 39
 	sop.sem_flg=0 /*SEM_UNDO*/;
40 40
 again:
41
-//	semop(shm_semid, &sop, 1);
41
+	semop(shm_semid, &sop, 1);
42 42
 #if 0
43 43
 	switch(ret){
44 44
 		case 0: /*ok*/
... ...
@@ -63,7 +63,7 @@ inline static void shm_unlock()
63 63
 	sop.sem_op=1; /*up*/
64 64
 	sop.sem_flg=0 /*SEM_UNDO*/;
65 65
 again:
66
-//	semop(shm_semid, &sop, 1);
66
+	semop(shm_semid, &sop, 1);
67 67
 #if 0
68 68
 	/*should ret immediately*/
69 69
 	switch(ret){
Browse code

- small but essential fixes

Andrei Pelinescu-Onciul authored on 30/11/2001 01:03:02
Showing 1 changed files
... ...
@@ -30,7 +30,7 @@ void shm_mem_destroy();
30 30
 
31 31
 
32 32
 
33
-inline static void sh_lock()
33
+inline static void shm_lock()
34 34
 {
35 35
 	struct sembuf sop;
36 36
 	
... ...
@@ -55,7 +55,7 @@ again:
55 55
 
56 56
 
57 57
 
58
-inline static void sh_unlock()
58
+inline static void shm_unlock()
59 59
 {
60 60
 	struct sembuf sop;
61 61
 	
... ...
@@ -80,14 +80,14 @@ again:
80 80
 }
81 81
 
82 82
 
83
-inline static void* sh_malloc(unsigned int size)
83
+inline static void* shm_malloc(unsigned int size)
84 84
 {
85 85
 	void *p;
86 86
 	
87
-	/*if (sh_lock()==0){*/
88
-		sh_lock();
87
+	/*if (shm_lock()==0){*/
88
+		shm_lock();
89 89
 		p=qm_malloc(shm_block, size);
90
-		sh_unlock();
90
+		shm_unlock();
91 91
 	/*
92 92
 	}else{
93 93
 		p=0;
... ...
@@ -97,20 +97,20 @@ inline static void* sh_malloc(unsigned int size)
97 97
 
98 98
 
99 99
 
100
-#define sh_free(p) \
100
+#define shm_free(p) \
101 101
 do { \
102
-		sh_lock(); \
102
+		shm_lock(); \
103 103
 		qm_free(shm_block, p); \
104
-		sh_unlock(); \
104
+		shm_unlock(); \
105 105
 }while(0)
106 106
 
107 107
 
108 108
 
109
-#define sh_status() \
109
+#define shm_status() \
110 110
 do { \
111
-		sh_lock(); \
111
+		shm_lock(); \
112 112
 		qm_status(shm_block); \
113
-		sh_unlock(); \
113
+		shm_unlock(); \
114 114
 }while(0)
115 115
 
116 116
 
Browse code

- updated INSTALL - fixed MKDEP in Makefile - added shm_mem.{c,h} = shared memory + shared malloc (sh_malloc)

Andrei Pelinescu-Onciul authored on 26/11/2001 23:31:03
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,122 @@
1
+/* $Id$*
2
+ *
3
+ * shared mem stuff
4
+ */
5
+
6
+#ifdef SHM_MEM
7
+
8
+#ifndef shm_mem_h
9
+#define shm_mem_h
10
+
11
+#include <string.h>
12
+#include <errno.h>
13
+#include <sys/types.h>
14
+#include <sys/ipc.h>
15
+#include <sys/shm.h>
16
+#include <sys/sem.h>
17
+#include <string.h>
18
+#include <errno.h>
19
+
20
+
21
+
22
+#include "q_malloc.h"
23
+#include "dprint.h"
24
+
25
+extern struct qm_block* shm_block;
26
+extern int shm_semid;
27
+
28
+int shm_mem_init();
29
+void shm_mem_destroy();
30
+
31
+
32
+
33
+inline static void sh_lock()
34
+{
35
+	struct sembuf sop;
36
+	
37
+	sop.sem_num=0;
38
+	sop.sem_op=-1; /*down*/
39
+	sop.sem_flg=0 /*SEM_UNDO*/;
40
+again:
41
+//	semop(shm_semid, &sop, 1);
42
+#if 0
43
+	switch(ret){
44
+		case 0: /*ok*/
45
+			break;
46
+		case EINTR: /*interrupted by signal, try again*/
47
+			DBG("sh_lock: interrupted by signal, trying again...\n");
48
+			goto again;
49
+		default:
50
+			LOG(L_ERR, "ERROR: sh_lock: error waiting on semaphore: %s\n",
51
+					strerror(errno));
52
+	}
53
+#endif
54
+}
55
+
56
+
57
+
58
+inline static void sh_unlock()
59
+{
60
+	struct sembuf sop;
61
+	
62
+	sop.sem_num=0;
63
+	sop.sem_op=1; /*up*/
64
+	sop.sem_flg=0 /*SEM_UNDO*/;
65
+again:
66
+//	semop(shm_semid, &sop, 1);
67
+#if 0
68
+	/*should ret immediately*/
69
+	switch(ret){
70
+		case 0: /*ok*/
71
+			break;
72
+		case EINTR: /*interrupted by signal, try again*/
73
+			DBG("sh_lock: interrupted by signal, trying again...\n");
74
+			goto again;
75
+		default:
76
+			LOG(L_ERR, "ERROR: sh_lock: error waiting on semaphore: %s\n",
77
+					strerror(errno));
78
+	}
79
+#endif
80
+}
81
+
82
+
83
+inline static void* sh_malloc(unsigned int size)
84
+{
85
+	void *p;
86
+	
87
+	/*if (sh_lock()==0){*/
88
+		sh_lock();
89
+		p=qm_malloc(shm_block, size);
90
+		sh_unlock();
91
+	/*
92
+	}else{
93
+		p=0;
94
+	}*/
95
+	return p;
96
+}
97
+
98
+
99
+
100
+#define sh_free(p) \
101
+do { \
102
+		sh_lock(); \
103
+		qm_free(shm_block, p); \
104
+		sh_unlock(); \
105
+}while(0)
106
+
107
+
108
+
109
+#define sh_status() \
110
+do { \
111
+		sh_lock(); \
112
+		qm_status(shm_block); \
113
+		sh_unlock(); \
114
+}while(0)
115
+
116
+
117
+	
118
+
119
+#endif
120
+
121
+#endif
122
+