sedna 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGES → CHANGES.rdoc} +9 -0
- data/{README → README.rdoc} +23 -25
- data/Rakefile +32 -9
- data/ext/{extconf.rb → sedna/extconf.rb} +33 -21
- data/ext/{sedna.c → sedna/sedna.c} +48 -40
- data/test/sedna_test.rb +9 -9
- data/vendor/sedna/AUTHORS +18 -0
- data/vendor/sedna/COPYRIGHT +90 -0
- data/vendor/sedna/LICENSE +202 -0
- data/vendor/sedna/Makefile.include +423 -0
- data/vendor/sedna/Makefile.platform +31 -0
- data/vendor/sedna/depend.sed +48 -0
- data/vendor/sedna/driver/c/Makefile +98 -0
- data/vendor/sedna/driver/c/libsedna.c +1998 -0
- data/vendor/sedna/driver/c/libsedna.h +199 -0
- data/vendor/sedna/driver/c/sednamt.def +21 -0
- data/vendor/sedna/driver/c/sp_defs.h +186 -0
- data/vendor/sedna/kernel/common/FastXptrHash.cpp +101 -0
- data/vendor/sedna/kernel/common/IntHash.h +314 -0
- data/vendor/sedna/kernel/common/IntList.h +224 -0
- data/vendor/sedna/kernel/common/Makefile +30 -0
- data/vendor/sedna/kernel/common/SSMMsg.cpp +459 -0
- data/vendor/sedna/kernel/common/SSMMsg.h +142 -0
- data/vendor/sedna/kernel/common/XptrHash.h +435 -0
- data/vendor/sedna/kernel/common/argtable.c +972 -0
- data/vendor/sedna/kernel/common/argtable.h +896 -0
- data/vendor/sedna/kernel/common/base.cpp +339 -0
- data/vendor/sedna/kernel/common/base.h +226 -0
- data/vendor/sedna/kernel/common/bit_set.cpp +157 -0
- data/vendor/sedna/kernel/common/bit_set.h +55 -0
- data/vendor/sedna/kernel/common/commutil.h +67 -0
- data/vendor/sedna/kernel/common/config.h +62 -0
- data/vendor/sedna/kernel/common/counted_ptr.h +74 -0
- data/vendor/sedna/kernel/common/errdbg/ErrorCodes.java +1056 -0
- data/vendor/sedna/kernel/common/errdbg/Makefile +34 -0
- data/vendor/sedna/kernel/common/errdbg/assert.c +133 -0
- data/vendor/sedna/kernel/common/errdbg/d_printf.c +150 -0
- data/vendor/sedna/kernel/common/errdbg/d_printf.h +91 -0
- data/vendor/sedna/kernel/common/errdbg/error.codes +1743 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes.c +531 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes.h +549 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes_scm.scm +527 -0
- data/vendor/sedna/kernel/common/errdbg/event_log.c +956 -0
- data/vendor/sedna/kernel/common/errdbg/event_log.h +226 -0
- data/vendor/sedna/kernel/common/errdbg/exceptions.cpp +155 -0
- data/vendor/sedna/kernel/common/errdbg/exceptions.h +559 -0
- data/vendor/sedna/kernel/common/errdbg/gen_error_codes +0 -0
- data/vendor/sedna/kernel/common/errdbg/gen_error_codes.c +345 -0
- data/vendor/sedna/kernel/common/gmm.cpp +192 -0
- data/vendor/sedna/kernel/common/gmm.h +29 -0
- data/vendor/sedna/kernel/common/ipc_ops.cpp +435 -0
- data/vendor/sedna/kernel/common/ipc_ops.h +51 -0
- data/vendor/sedna/kernel/common/lfsGlobals.h +12 -0
- data/vendor/sedna/kernel/common/lm_base.h +90 -0
- data/vendor/sedna/kernel/common/mmgr/Makefile +11 -0
- data/vendor/sedna/kernel/common/mmgr/aset.c +1185 -0
- data/vendor/sedna/kernel/common/mmgr/mcxt.c +741 -0
- data/vendor/sedna/kernel/common/mmgr/memnodes.h +70 -0
- data/vendor/sedna/kernel/common/mmgr/memutils.h +145 -0
- data/vendor/sedna/kernel/common/mmgr/se_alloc.h +321 -0
- data/vendor/sedna/kernel/common/mmgr/track.c +214 -0
- data/vendor/sedna/kernel/common/pping.cpp +672 -0
- data/vendor/sedna/kernel/common/pping.h +119 -0
- data/vendor/sedna/kernel/common/rcv_test.cpp +273 -0
- data/vendor/sedna/kernel/common/rcv_test.h +19 -0
- data/vendor/sedna/kernel/common/sedna.c +128 -0
- data/vendor/sedna/kernel/common/sedna.h +49 -0
- data/vendor/sedna/kernel/common/sedna_ef.h +52 -0
- data/vendor/sedna/kernel/common/sm_vmm_data.h +144 -0
- data/vendor/sedna/kernel/common/sp.c +93 -0
- data/vendor/sedna/kernel/common/sp.h +36 -0
- data/vendor/sedna/kernel/common/st/Makefile +20 -0
- data/vendor/sedna/kernel/common/st/os_linux/stacktrace.c +213 -0
- data/vendor/sedna/kernel/common/st/os_nt/stacktrace.c +338 -0
- data/vendor/sedna/kernel/common/st/os_other/stacktrace.c +39 -0
- data/vendor/sedna/kernel/common/st/stacktrace.h +72 -0
- data/vendor/sedna/kernel/common/st/stacktrfmt.c +64 -0
- data/vendor/sedna/kernel/common/tr_debug.cpp +112 -0
- data/vendor/sedna/kernel/common/tr_debug.h +22 -0
- data/vendor/sedna/kernel/common/u/Makefile +14 -0
- data/vendor/sedna/kernel/common/u/u.c +268 -0
- data/vendor/sedna/kernel/common/u/u.h +715 -0
- data/vendor/sedna/kernel/common/u/uatomic.h +12 -0
- data/vendor/sedna/kernel/common/u/udl.h +31 -0
- data/vendor/sedna/kernel/common/u/uevent.c +406 -0
- data/vendor/sedna/kernel/common/u/uevent.h +71 -0
- data/vendor/sedna/kernel/common/u/ugnames.cpp +330 -0
- data/vendor/sedna/kernel/common/u/ugnames.h +134 -0
- data/vendor/sedna/kernel/common/u/uhash_map.h +77 -0
- data/vendor/sedna/kernel/common/u/uhdd.c +1018 -0
- data/vendor/sedna/kernel/common/u/uhdd.h +206 -0
- data/vendor/sedna/kernel/common/u/ummap.cpp +268 -0
- data/vendor/sedna/kernel/common/u/ummap.h +60 -0
- data/vendor/sedna/kernel/common/u/umutex.c +145 -0
- data/vendor/sedna/kernel/common/u/umutex.h +65 -0
- data/vendor/sedna/kernel/common/u/upipe.cpp +244 -0
- data/vendor/sedna/kernel/common/u/upipe.h +74 -0
- data/vendor/sedna/kernel/common/u/uprocess.c +767 -0
- data/vendor/sedna/kernel/common/u/uprocess.h +91 -0
- data/vendor/sedna/kernel/common/u/usafesync.h +41 -0
- data/vendor/sedna/kernel/common/u/usecurity.c +150 -0
- data/vendor/sedna/kernel/common/u/usecurity.h +55 -0
- data/vendor/sedna/kernel/common/u/usem.c +891 -0
- data/vendor/sedna/kernel/common/u/usem.h +83 -0
- data/vendor/sedna/kernel/common/u/ushm.c +222 -0
- data/vendor/sedna/kernel/common/u/ushm.h +46 -0
- data/vendor/sedna/kernel/common/u/usocket.c +541 -0
- data/vendor/sedna/kernel/common/u/usocket.h +118 -0
- data/vendor/sedna/kernel/common/u/usystem.c +57 -0
- data/vendor/sedna/kernel/common/u/usystem.h +46 -0
- data/vendor/sedna/kernel/common/u/uthread.c +259 -0
- data/vendor/sedna/kernel/common/u/uthread.h +95 -0
- data/vendor/sedna/kernel/common/u/utime.c +65 -0
- data/vendor/sedna/kernel/common/u/utime.h +40 -0
- data/vendor/sedna/kernel/common/u/uutils.c +142 -0
- data/vendor/sedna/kernel/common/u/uutils.h +65 -0
- data/vendor/sedna/kernel/common/ugc.cpp +156 -0
- data/vendor/sedna/kernel/common/ugc.h +15 -0
- data/vendor/sedna/kernel/common/utils.cpp +156 -0
- data/vendor/sedna/kernel/common/utils.h +133 -0
- data/vendor/sedna/kernel/common/version.c +16 -0
- data/vendor/sedna/kernel/common/version.h +21 -0
- data/vendor/sedna/kernel/common/wustructures.h +18 -0
- data/vendor/sedna/kernel/common/wutypes.h +34 -0
- data/vendor/sedna/kernel/common/xptr.cpp +17 -0
- data/vendor/sedna/kernel/common/xptr.h +211 -0
- data/vendor/sedna/ver +1 -0
- metadata +142 -14
@@ -0,0 +1,30 @@
|
|
1
|
+
#
|
2
|
+
# Makefile for common_files
|
3
|
+
#
|
4
|
+
|
5
|
+
PP = ../..
|
6
|
+
|
7
|
+
include $(PP)/Makefile.include
|
8
|
+
|
9
|
+
OBJS = argtable$(OBJ_EXT) base$(OBJ_EXT) bit_set$(OBJ_EXT) gmm$(OBJ_EXT) ipc_ops$(OBJ_EXT) \
|
10
|
+
pping$(OBJ_EXT) rcv_test$(OBJ_EXT) sp$(OBJ_EXT) SSMMsg$(OBJ_EXT) \
|
11
|
+
tr_debug$(OBJ_EXT) ugc$(OBJ_EXT) utils$(OBJ_EXT) version$(OBJ_EXT) \
|
12
|
+
xptr$(OBJ_EXT) sedna$(OBJ_EXT)
|
13
|
+
SUBDIRS = errdbg mmgr u
|
14
|
+
|
15
|
+
ifeq ($(EL_DEBUG),1)
|
16
|
+
SUBDIRS += st
|
17
|
+
endif
|
18
|
+
|
19
|
+
LIB_NAME = common_files
|
20
|
+
|
21
|
+
|
22
|
+
include $(PP)/Makefile.ordlib
|
23
|
+
|
24
|
+
|
25
|
+
ifneq ($(findstring clean, $(MAKECMDGOALS)), clean)
|
26
|
+
$(OBJS:$(OBJ_EXT)=.d): errdbg/errdbg$(LIST_EXT)
|
27
|
+
$(OBJS): errdbg/errdbg$(LIST_EXT)
|
28
|
+
mmgr-recursive ph-recursive u-recursive: errdbg-recursive
|
29
|
+
endif
|
30
|
+
|
@@ -0,0 +1,459 @@
|
|
1
|
+
/*
|
2
|
+
* File: SSMMsg.cpp
|
3
|
+
* Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
4
|
+
*/
|
5
|
+
|
6
|
+
|
7
|
+
#include <assert.h>
|
8
|
+
#include "common/SSMMsg.h"
|
9
|
+
#include "common/utils.h"
|
10
|
+
#include "common/errdbg/d_printf.h"
|
11
|
+
#include "common/u/ugnames.h"
|
12
|
+
|
13
|
+
using namespace std;
|
14
|
+
|
15
|
+
// SSMMsg stands for Simple Shared Memory Messages Client/Server Architecture
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
#define SSMMSG_PAGE_SIZE 4096
|
20
|
+
#define MESSAGES_IN_QUEUE 100
|
21
|
+
|
22
|
+
#ifdef _WIN32
|
23
|
+
#define PROCESS_METHOD_THREAD_STACK_SIZE (1024 * 10)
|
24
|
+
#else
|
25
|
+
#define PROCESS_METHOD_THREAD_STACK_SIZE (1024 * 100)
|
26
|
+
#endif
|
27
|
+
|
28
|
+
#define SSMMSG_SHMEM_SUFFIX "shmem"
|
29
|
+
#define SSMMSG_SEMS_SUFFIX "sems"
|
30
|
+
|
31
|
+
|
32
|
+
#define sem_clients 0
|
33
|
+
#define sem_servers 1
|
34
|
+
#define sem_mutex 2
|
35
|
+
#define sem_pact 3
|
36
|
+
#define sem_pact_written 4
|
37
|
+
#define sem_pact_read 5
|
38
|
+
|
39
|
+
#define NAMED_SEMS_NUM 6
|
40
|
+
|
41
|
+
#define sem_data_written NAMED_SEMS_NUM
|
42
|
+
#define sem_data_processed (NAMED_SEMS_NUM + servers_amount)
|
43
|
+
#define sem_data_read (NAMED_SEMS_NUM + 2 * servers_amount)
|
44
|
+
|
45
|
+
#define sem_data_processed2(s) (NAMED_SEMS_NUM + (s)->servers_amount)
|
46
|
+
#define sem_data_read2(s) (NAMED_SEMS_NUM + 2 * (s)->servers_amount)
|
47
|
+
|
48
|
+
struct SSMMsgNames
|
49
|
+
{
|
50
|
+
global_name memory;
|
51
|
+
global_name sems;
|
52
|
+
};
|
53
|
+
|
54
|
+
static void InitSSMMsgNames(SSMMsgNames *names, global_name name, char *buf, size_t bufSz)
|
55
|
+
{
|
56
|
+
assert(names);
|
57
|
+
if ((names->memory = UGlobalNameFromCompoundName(name, 0, buf, bufSz)))
|
58
|
+
{
|
59
|
+
size_t consumed = strlen(names->memory)+1;
|
60
|
+
buf+=consumed; bufSz-=consumed;
|
61
|
+
}
|
62
|
+
names->sems = UGlobalNameFromCompoundName(name, 0, buf, bufSz);
|
63
|
+
}
|
64
|
+
|
65
|
+
SSMMsg::SSMMsg(mode _m_,
|
66
|
+
int _msg_size_,
|
67
|
+
global_name _g_name_,
|
68
|
+
int _servers_amount_,
|
69
|
+
unsigned int _millisec_)
|
70
|
+
{
|
71
|
+
m = _m_;
|
72
|
+
msg_size = _msg_size_;
|
73
|
+
servers_amount = _servers_amount_;
|
74
|
+
|
75
|
+
real_block_size = 0;
|
76
|
+
shared_memory_size = 0;
|
77
|
+
waiting = NULL;
|
78
|
+
slot = NULL;
|
79
|
+
process_messages = NULL;
|
80
|
+
busy_servers_amount = NULL;
|
81
|
+
shar_mem = NULL;
|
82
|
+
buf_addr = NULL;
|
83
|
+
sysinf_addr = NULL;
|
84
|
+
sems_num = NAMED_SEMS_NUM + 3 * servers_amount;
|
85
|
+
|
86
|
+
SSMMsgNames names = {};
|
87
|
+
InitSSMMsgNames(&names, _g_name_, g_names__buf__, 256);
|
88
|
+
g_name_shmem = names.memory;
|
89
|
+
g_name_sems = names.sems;
|
90
|
+
|
91
|
+
server_param = NULL;
|
92
|
+
|
93
|
+
millisec = _millisec_;
|
94
|
+
|
95
|
+
thread_handles = NULL;
|
96
|
+
sh_mem = 0;
|
97
|
+
sems = 0;
|
98
|
+
|
99
|
+
|
100
|
+
real_block_size = msg_size % SSMMSG_PAGE_SIZE == 0 ? msg_size : (msg_size / SSMMSG_PAGE_SIZE + 1) * SSMMSG_PAGE_SIZE;
|
101
|
+
// the idea is that first page is for system purposes (it contains system
|
102
|
+
// data)
|
103
|
+
shared_memory_size = SSMMSG_PAGE_SIZE + real_block_size * servers_amount;
|
104
|
+
|
105
|
+
shutdown_server_proc = false;
|
106
|
+
}
|
107
|
+
|
108
|
+
|
109
|
+
int SSMMsg::init()
|
110
|
+
{
|
111
|
+
//d_printf1("!!!!!!!! SSMMsg::init() !!!!!!!\n");
|
112
|
+
|
113
|
+
if (m == Server)
|
114
|
+
{
|
115
|
+
if (0 != uCreateShMem(&sh_mem, g_name_shmem, shared_memory_size, NULL, __sys_call_error))
|
116
|
+
{
|
117
|
+
d_printf1("uCreateShMem failed\n");
|
118
|
+
return 1;
|
119
|
+
}
|
120
|
+
|
121
|
+
shar_mem = uAttachShMem(sh_mem, NULL, shared_memory_size, __sys_call_error);
|
122
|
+
if (shar_mem == NULL)
|
123
|
+
{
|
124
|
+
d_printf1("uAttachShMem failed\n");
|
125
|
+
return 1;
|
126
|
+
}
|
127
|
+
|
128
|
+
//d_printf2("shar_mem 0x%x\n", shar_mem);
|
129
|
+
//d_printf2("shared_memory_size %d\n", shared_memory_size);
|
130
|
+
|
131
|
+
int *init_values = se_new int[sems_num];
|
132
|
+
|
133
|
+
init_values[sem_clients] = 0;
|
134
|
+
init_values[sem_servers] = 0;
|
135
|
+
init_values[sem_mutex] = 1;
|
136
|
+
init_values[sem_pact] = 1;
|
137
|
+
init_values[sem_pact_written] = 0;
|
138
|
+
init_values[sem_pact_read] = 0;
|
139
|
+
int i = 0;
|
140
|
+
for (i = NAMED_SEMS_NUM; i < sems_num; i++)
|
141
|
+
init_values[i] = 0;
|
142
|
+
|
143
|
+
if (0 != USemaphoreArrCreate(&sems, sems_num, init_values, g_name_sems, NULL, __sys_call_error))
|
144
|
+
{
|
145
|
+
d_printf1("USemaphoreArrCreate failed\n");
|
146
|
+
return 1;
|
147
|
+
}
|
148
|
+
|
149
|
+
delete [] init_values;
|
150
|
+
|
151
|
+
|
152
|
+
sysinf_addr = shar_mem;
|
153
|
+
buf_addr = (void*)((char*)shar_mem + SSMMSG_PAGE_SIZE);
|
154
|
+
|
155
|
+
waiting = (int*)sysinf_addr;
|
156
|
+
slot = (int*)sysinf_addr + 1;
|
157
|
+
process_messages = (int*)sysinf_addr + 2;
|
158
|
+
busy_servers_amount = (int*)sysinf_addr + 3;
|
159
|
+
|
160
|
+
*waiting = 0;
|
161
|
+
*slot = 0;
|
162
|
+
*process_messages = 1;
|
163
|
+
*busy_servers_amount = 0;
|
164
|
+
}
|
165
|
+
else if (m == Client)
|
166
|
+
{
|
167
|
+
//d_printf1("!!!!!!!!!!! Client initialization !!!!!!!!!!!!!!!!!!!!!!!!!\n");
|
168
|
+
|
169
|
+
if (0 != uOpenShMem(&sh_mem, g_name_shmem, shared_memory_size, __sys_call_error))
|
170
|
+
{
|
171
|
+
d_printf1("uOpenShMem failed\n");
|
172
|
+
return 1;
|
173
|
+
}
|
174
|
+
|
175
|
+
shar_mem = uAttachShMem(sh_mem, NULL, shared_memory_size, __sys_call_error);
|
176
|
+
if (shar_mem == NULL)
|
177
|
+
{
|
178
|
+
d_printf1("uAttachShMem failed\n");
|
179
|
+
return 1;
|
180
|
+
}
|
181
|
+
|
182
|
+
//d_printf2("shar_mem 0x%x\n", shar_mem);
|
183
|
+
//d_printf2("shared_memory_size %d\n", shared_memory_size);
|
184
|
+
|
185
|
+
if (0 != USemaphoreArrOpen(&sems, sems_num, g_name_sems, __sys_call_error))
|
186
|
+
{
|
187
|
+
d_printf1("USemaphoreArrOpen failed\n");
|
188
|
+
return 1;
|
189
|
+
}
|
190
|
+
|
191
|
+
sysinf_addr = shar_mem;
|
192
|
+
buf_addr = (void*)((char*)shar_mem + SSMMSG_PAGE_SIZE);
|
193
|
+
|
194
|
+
waiting = (int*)sysinf_addr;
|
195
|
+
slot = (int*)sysinf_addr + 1;
|
196
|
+
process_messages = (int*)sysinf_addr + 2;
|
197
|
+
busy_servers_amount = (int*)sysinf_addr + 3;
|
198
|
+
}
|
199
|
+
else return 1;
|
200
|
+
|
201
|
+
return 0;
|
202
|
+
}
|
203
|
+
|
204
|
+
|
205
|
+
int SSMMsg::shutdown()
|
206
|
+
{
|
207
|
+
if (0 != uDettachShMem(sh_mem, shar_mem, __sys_call_error))
|
208
|
+
{
|
209
|
+
d_printf1("uDettachShMem failed\n");
|
210
|
+
return 1;
|
211
|
+
}
|
212
|
+
|
213
|
+
if (m == Server)
|
214
|
+
{
|
215
|
+
if (0 != uReleaseShMem(sh_mem, __sys_call_error))
|
216
|
+
{
|
217
|
+
d_printf1("uReleaseShMem failed\n");
|
218
|
+
return 1;
|
219
|
+
}
|
220
|
+
|
221
|
+
if (0 != USemaphoreArrRelease(sems, sems_num, __sys_call_error))
|
222
|
+
{
|
223
|
+
d_printf1("USemaphoreArrRelease failed\n");
|
224
|
+
return 1;
|
225
|
+
}
|
226
|
+
}
|
227
|
+
else if (m == Client)
|
228
|
+
{
|
229
|
+
if (0 != uCloseShMem(sh_mem, __sys_call_error))
|
230
|
+
{
|
231
|
+
d_printf1("uCloseShMem failed\n");
|
232
|
+
return 1;
|
233
|
+
}
|
234
|
+
|
235
|
+
if (0 != USemaphoreArrClose(sems, sems_num, __sys_call_error))
|
236
|
+
{
|
237
|
+
d_printf1("USemaphoreArrClose failed\n");
|
238
|
+
return 1;
|
239
|
+
}
|
240
|
+
}
|
241
|
+
else return 1;
|
242
|
+
|
243
|
+
delete server_param;
|
244
|
+
delete [] thread_handles;
|
245
|
+
|
246
|
+
return 0;
|
247
|
+
}
|
248
|
+
|
249
|
+
|
250
|
+
#define down1(sems, idx, ret) if (0 != USemaphoreArrDown(sems, idx, __sys_call_error)) \
|
251
|
+
{ \
|
252
|
+
d_printf1("USemaphoreArrDown1 failed\n"); \
|
253
|
+
return ret; \
|
254
|
+
}
|
255
|
+
|
256
|
+
#define down2(sems, idx, ms, ret) if (0 != USemaphoreArrDown(sems, idx/*, ms*/, __sys_call_error)) \
|
257
|
+
{ \
|
258
|
+
d_printf1("USemaphoreArrDown2 failed\n"); \
|
259
|
+
return ret; \
|
260
|
+
}
|
261
|
+
|
262
|
+
#define up(sems, idx, ret) if (0 != USemaphoreArrUp(sems, idx, __sys_call_error)) \
|
263
|
+
{ \
|
264
|
+
d_printf1("USemaphoreArrUp failed\n"); \
|
265
|
+
return ret; \
|
266
|
+
}
|
267
|
+
|
268
|
+
|
269
|
+
int SSMMsg::send_msg(void * buf)
|
270
|
+
{
|
271
|
+
// static int i = 0;
|
272
|
+
|
273
|
+
// d_printf2("send_msg called %d times\n", ++i); fflush(stdout);
|
274
|
+
|
275
|
+
int server_num = 0;
|
276
|
+
|
277
|
+
// d_printf2("down sem_mutex %d\n", (int)sem_mutex); fflush(stdout);
|
278
|
+
down2(sems, sem_mutex, millisec, 1);
|
279
|
+
// d_printf2("down sem_mutex %d\n", (int)sem_mutex); fflush(stdout);
|
280
|
+
if (*waiting < MESSAGES_IN_QUEUE && *process_messages == 1)
|
281
|
+
{
|
282
|
+
*waiting += 1;
|
283
|
+
|
284
|
+
// d_printf2("*waiting = %d\n", *waiting); fflush(stdout);
|
285
|
+
// d_printf2("*process_messages = %d\n", *process_messages); fflush(stdout);
|
286
|
+
|
287
|
+
up(sems, sem_clients, 1);
|
288
|
+
up(sems, sem_mutex, 1);
|
289
|
+
// d_printf1("down sem_servers\n"); fflush(stdout);
|
290
|
+
down2(sems, sem_servers, millisec, 1);
|
291
|
+
|
292
|
+
// d_printf1("down sem_pact_written\n"); fflush(stdout);
|
293
|
+
down2(sems, sem_pact_written, millisec, 1);
|
294
|
+
server_num = *slot;
|
295
|
+
up(sems, sem_pact_read, 1);
|
296
|
+
|
297
|
+
// d_printf2("server_num %d\n", server_num); fflush(stdout);
|
298
|
+
// d_printf2("cell 0x%x\n", (void*)((char*)buf_addr + server_num * real_block_size)); fflush(stdout);
|
299
|
+
memcpy((void*)((char*)buf_addr + server_num * real_block_size), buf, msg_size);
|
300
|
+
up(sems, sem_data_written + server_num, 1);
|
301
|
+
// d_printf2("down sem_data_processed[%d]\n", server_num); fflush(stdout);
|
302
|
+
down2(sems, sem_data_processed + server_num, millisec, 1);
|
303
|
+
// d_printf1("after down sem_data_processed\n");
|
304
|
+
memcpy(buf, (void*)((char*)buf_addr + server_num * real_block_size), msg_size);
|
305
|
+
// d_printf2("up sem_data_read[%d]\n", server_num); fflush(stdout);
|
306
|
+
up(sems, sem_data_read + server_num, 1);
|
307
|
+
|
308
|
+
// d_printf1("client: msg sent\n"); fflush(stdout);
|
309
|
+
}
|
310
|
+
else
|
311
|
+
{
|
312
|
+
// if (!(*waiting < MESSAGES_IN_QUEUE)) d_printf2("Deny of service: server is busy (queue is too long) %d\n", *waiting);
|
313
|
+
// if (!(*process_messages == 1)) d_printf2("Deny of service: server is being shutdown %d\n", *process_messages);
|
314
|
+
up(sems, sem_mutex, 1);
|
315
|
+
// d_printf1("Deny of service: server is busy or is being shutdown\n");
|
316
|
+
return 1;
|
317
|
+
}
|
318
|
+
|
319
|
+
return 0;
|
320
|
+
}
|
321
|
+
|
322
|
+
#ifdef _WIN32
|
323
|
+
#define THREAD_FUN_RET_TYPE DWORD
|
324
|
+
#else
|
325
|
+
#define THREAD_FUN_RET_TYPE void*
|
326
|
+
#endif
|
327
|
+
|
328
|
+
|
329
|
+
U_THREAD_PROC(SSMMsg_server_proc, arg)
|
330
|
+
{
|
331
|
+
if (uThreadBlockAllSignals(__sys_call_error) != 0)
|
332
|
+
d_printf1("Failed to block signals for SSMMsg_server_proc");
|
333
|
+
|
334
|
+
int i = ((SSMMsg_server_thread_param*)arg)->i;
|
335
|
+
process_msg_func func = ((SSMMsg_server_thread_param*)arg)->func;
|
336
|
+
SSMMsg *ssmmsg = ((SSMMsg_server_thread_param*)arg)->ssmmsg;
|
337
|
+
|
338
|
+
while (true)
|
339
|
+
{
|
340
|
+
//d_printf1("cycle iteration\n"); fflush(stdout);
|
341
|
+
up(ssmmsg->sems, sem_servers, (THREAD_FUN_RET_TYPE)-1);
|
342
|
+
down1(ssmmsg->sems, sem_clients, (THREAD_FUN_RET_TYPE)-1);
|
343
|
+
if (ssmmsg->shutdown_server_proc) break;
|
344
|
+
down1(ssmmsg->sems, sem_mutex, (THREAD_FUN_RET_TYPE)-1);
|
345
|
+
*(ssmmsg->waiting) -= 1;
|
346
|
+
*(ssmmsg->busy_servers_amount) += 1;
|
347
|
+
up(ssmmsg->sems, sem_mutex, (THREAD_FUN_RET_TYPE)-1);
|
348
|
+
|
349
|
+
down1(ssmmsg->sems, sem_pact, (THREAD_FUN_RET_TYPE)-1);
|
350
|
+
*(ssmmsg->slot) = i;
|
351
|
+
up(ssmmsg->sems, sem_pact_written, (THREAD_FUN_RET_TYPE)-1);
|
352
|
+
down1(ssmmsg->sems, sem_pact_read, (THREAD_FUN_RET_TYPE)-1);
|
353
|
+
up(ssmmsg->sems, sem_pact, (THREAD_FUN_RET_TYPE)-1);
|
354
|
+
|
355
|
+
down1(ssmmsg->sems, sem_data_written + i, (THREAD_FUN_RET_TYPE)-1);
|
356
|
+
|
357
|
+
// user activity
|
358
|
+
func((void*)((char*)(ssmmsg->buf_addr) + i * ssmmsg->real_block_size));
|
359
|
+
|
360
|
+
// d_printf2("up sem_data_processed[%d]\n", i); fflush(stdout);
|
361
|
+
up(ssmmsg->sems, sem_data_processed2(ssmmsg) + i, (THREAD_FUN_RET_TYPE)-1);
|
362
|
+
// d_printf2("down sem_data_read[%d]\n", i); fflush(stdout);
|
363
|
+
down1(ssmmsg->sems, sem_data_read2(ssmmsg) + i, (THREAD_FUN_RET_TYPE)-1);
|
364
|
+
|
365
|
+
down1(ssmmsg->sems, sem_mutex, (THREAD_FUN_RET_TYPE)-1);
|
366
|
+
*(ssmmsg->busy_servers_amount) -= 1;
|
367
|
+
up(ssmmsg->sems, sem_mutex, (THREAD_FUN_RET_TYPE)-1);
|
368
|
+
}
|
369
|
+
|
370
|
+
return 0;
|
371
|
+
}
|
372
|
+
|
373
|
+
int SSMMsg::serve_clients(process_msg_func func)
|
374
|
+
{
|
375
|
+
shutdown_server_proc = false;
|
376
|
+
|
377
|
+
server_param = se_new SSMMsg_server_thread_param;
|
378
|
+
server_param->func = func;
|
379
|
+
server_param->ssmmsg = this;
|
380
|
+
thread_handles = se_new UTHANDLE[servers_amount];
|
381
|
+
for (int i = 0; i < servers_amount; i++)
|
382
|
+
{
|
383
|
+
//d_printf2("server thread number %d started\n", i);
|
384
|
+
UTHANDLE id;
|
385
|
+
server_param->i = i;
|
386
|
+
uResVal res = uCreateThread(SSMMsg_server_proc, server_param, &id, PROCESS_METHOD_THREAD_STACK_SIZE, NULL, __sys_call_error);
|
387
|
+
if (res != 0)
|
388
|
+
{
|
389
|
+
d_printf1("Failed to create thread\n");
|
390
|
+
return 1;
|
391
|
+
}
|
392
|
+
thread_handles[i] = id;
|
393
|
+
}
|
394
|
+
|
395
|
+
return 0;
|
396
|
+
}
|
397
|
+
|
398
|
+
int SSMMsg::stop_serve_clients()
|
399
|
+
{
|
400
|
+
down1(sems, sem_mutex, 1);
|
401
|
+
*process_messages = 0;
|
402
|
+
up(sems, sem_mutex, 1);
|
403
|
+
|
404
|
+
while (true)
|
405
|
+
{
|
406
|
+
down1(sems, sem_mutex, 1);
|
407
|
+
if (*waiting == 0 && *busy_servers_amount == 0)
|
408
|
+
{
|
409
|
+
int i = 0;
|
410
|
+
|
411
|
+
up(sems, sem_mutex, 1);
|
412
|
+
|
413
|
+
shutdown_server_proc = true;
|
414
|
+
for (i = 0; i < servers_amount; i++)
|
415
|
+
up(sems, sem_clients, 1);
|
416
|
+
|
417
|
+
for (i = 0; i < servers_amount; i++)
|
418
|
+
{
|
419
|
+
if (uThreadJoin(thread_handles[i], __sys_call_error) != 0)
|
420
|
+
{
|
421
|
+
d_printf1("uThreadJoin failed\n");
|
422
|
+
return 1;
|
423
|
+
}
|
424
|
+
|
425
|
+
if (uCloseThreadHandle(thread_handles[i], __sys_call_error) != 0)
|
426
|
+
{
|
427
|
+
d_printf1("uCloseThreadHandle failed\n");
|
428
|
+
return 1;
|
429
|
+
}
|
430
|
+
}
|
431
|
+
|
432
|
+
break;
|
433
|
+
}
|
434
|
+
else up(sems, sem_mutex, 1);
|
435
|
+
|
436
|
+
uSleep(1, __sys_call_error);
|
437
|
+
}
|
438
|
+
|
439
|
+
return 0;
|
440
|
+
}
|
441
|
+
|
442
|
+
void SSMMsg::ipc_cleanup(global_name name)
|
443
|
+
{
|
444
|
+
USemaphoreArr sems;
|
445
|
+
UShMem memory;
|
446
|
+
SSMMsgNames names;
|
447
|
+
char buf[256];
|
448
|
+
|
449
|
+
InitSSMMsgNames(&names, name, buf, sizeof buf);
|
450
|
+
if (uOpenShMem(&memory, names.memory, 8192, __sys_call_error) == 0)
|
451
|
+
{
|
452
|
+
uReleaseShMem(memory, __sys_call_error);
|
453
|
+
}
|
454
|
+
if (USemaphoreArrOpen(&sems, 9, names.sems, __sys_call_error) == 0)
|
455
|
+
{
|
456
|
+
USemaphoreArrRelease(sems, 9, __sys_call_error);
|
457
|
+
}
|
458
|
+
}
|
459
|
+
|