sedna 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/{CHANGES → CHANGES.rdoc} +9 -0
  2. data/{README → README.rdoc} +23 -25
  3. data/Rakefile +32 -9
  4. data/ext/{extconf.rb → sedna/extconf.rb} +33 -21
  5. data/ext/{sedna.c → sedna/sedna.c} +48 -40
  6. data/test/sedna_test.rb +9 -9
  7. data/vendor/sedna/AUTHORS +18 -0
  8. data/vendor/sedna/COPYRIGHT +90 -0
  9. data/vendor/sedna/LICENSE +202 -0
  10. data/vendor/sedna/Makefile.include +423 -0
  11. data/vendor/sedna/Makefile.platform +31 -0
  12. data/vendor/sedna/depend.sed +48 -0
  13. data/vendor/sedna/driver/c/Makefile +98 -0
  14. data/vendor/sedna/driver/c/libsedna.c +1998 -0
  15. data/vendor/sedna/driver/c/libsedna.h +199 -0
  16. data/vendor/sedna/driver/c/sednamt.def +21 -0
  17. data/vendor/sedna/driver/c/sp_defs.h +186 -0
  18. data/vendor/sedna/kernel/common/FastXptrHash.cpp +101 -0
  19. data/vendor/sedna/kernel/common/IntHash.h +314 -0
  20. data/vendor/sedna/kernel/common/IntList.h +224 -0
  21. data/vendor/sedna/kernel/common/Makefile +30 -0
  22. data/vendor/sedna/kernel/common/SSMMsg.cpp +459 -0
  23. data/vendor/sedna/kernel/common/SSMMsg.h +142 -0
  24. data/vendor/sedna/kernel/common/XptrHash.h +435 -0
  25. data/vendor/sedna/kernel/common/argtable.c +972 -0
  26. data/vendor/sedna/kernel/common/argtable.h +896 -0
  27. data/vendor/sedna/kernel/common/base.cpp +339 -0
  28. data/vendor/sedna/kernel/common/base.h +226 -0
  29. data/vendor/sedna/kernel/common/bit_set.cpp +157 -0
  30. data/vendor/sedna/kernel/common/bit_set.h +55 -0
  31. data/vendor/sedna/kernel/common/commutil.h +67 -0
  32. data/vendor/sedna/kernel/common/config.h +62 -0
  33. data/vendor/sedna/kernel/common/counted_ptr.h +74 -0
  34. data/vendor/sedna/kernel/common/errdbg/ErrorCodes.java +1056 -0
  35. data/vendor/sedna/kernel/common/errdbg/Makefile +34 -0
  36. data/vendor/sedna/kernel/common/errdbg/assert.c +133 -0
  37. data/vendor/sedna/kernel/common/errdbg/d_printf.c +150 -0
  38. data/vendor/sedna/kernel/common/errdbg/d_printf.h +91 -0
  39. data/vendor/sedna/kernel/common/errdbg/error.codes +1743 -0
  40. data/vendor/sedna/kernel/common/errdbg/error_codes.c +531 -0
  41. data/vendor/sedna/kernel/common/errdbg/error_codes.h +549 -0
  42. data/vendor/sedna/kernel/common/errdbg/error_codes_scm.scm +527 -0
  43. data/vendor/sedna/kernel/common/errdbg/event_log.c +956 -0
  44. data/vendor/sedna/kernel/common/errdbg/event_log.h +226 -0
  45. data/vendor/sedna/kernel/common/errdbg/exceptions.cpp +155 -0
  46. data/vendor/sedna/kernel/common/errdbg/exceptions.h +559 -0
  47. data/vendor/sedna/kernel/common/errdbg/gen_error_codes +0 -0
  48. data/vendor/sedna/kernel/common/errdbg/gen_error_codes.c +345 -0
  49. data/vendor/sedna/kernel/common/gmm.cpp +192 -0
  50. data/vendor/sedna/kernel/common/gmm.h +29 -0
  51. data/vendor/sedna/kernel/common/ipc_ops.cpp +435 -0
  52. data/vendor/sedna/kernel/common/ipc_ops.h +51 -0
  53. data/vendor/sedna/kernel/common/lfsGlobals.h +12 -0
  54. data/vendor/sedna/kernel/common/lm_base.h +90 -0
  55. data/vendor/sedna/kernel/common/mmgr/Makefile +11 -0
  56. data/vendor/sedna/kernel/common/mmgr/aset.c +1185 -0
  57. data/vendor/sedna/kernel/common/mmgr/mcxt.c +741 -0
  58. data/vendor/sedna/kernel/common/mmgr/memnodes.h +70 -0
  59. data/vendor/sedna/kernel/common/mmgr/memutils.h +145 -0
  60. data/vendor/sedna/kernel/common/mmgr/se_alloc.h +321 -0
  61. data/vendor/sedna/kernel/common/mmgr/track.c +214 -0
  62. data/vendor/sedna/kernel/common/pping.cpp +672 -0
  63. data/vendor/sedna/kernel/common/pping.h +119 -0
  64. data/vendor/sedna/kernel/common/rcv_test.cpp +273 -0
  65. data/vendor/sedna/kernel/common/rcv_test.h +19 -0
  66. data/vendor/sedna/kernel/common/sedna.c +128 -0
  67. data/vendor/sedna/kernel/common/sedna.h +49 -0
  68. data/vendor/sedna/kernel/common/sedna_ef.h +52 -0
  69. data/vendor/sedna/kernel/common/sm_vmm_data.h +144 -0
  70. data/vendor/sedna/kernel/common/sp.c +93 -0
  71. data/vendor/sedna/kernel/common/sp.h +36 -0
  72. data/vendor/sedna/kernel/common/st/Makefile +20 -0
  73. data/vendor/sedna/kernel/common/st/os_linux/stacktrace.c +213 -0
  74. data/vendor/sedna/kernel/common/st/os_nt/stacktrace.c +338 -0
  75. data/vendor/sedna/kernel/common/st/os_other/stacktrace.c +39 -0
  76. data/vendor/sedna/kernel/common/st/stacktrace.h +72 -0
  77. data/vendor/sedna/kernel/common/st/stacktrfmt.c +64 -0
  78. data/vendor/sedna/kernel/common/tr_debug.cpp +112 -0
  79. data/vendor/sedna/kernel/common/tr_debug.h +22 -0
  80. data/vendor/sedna/kernel/common/u/Makefile +14 -0
  81. data/vendor/sedna/kernel/common/u/u.c +268 -0
  82. data/vendor/sedna/kernel/common/u/u.h +715 -0
  83. data/vendor/sedna/kernel/common/u/uatomic.h +12 -0
  84. data/vendor/sedna/kernel/common/u/udl.h +31 -0
  85. data/vendor/sedna/kernel/common/u/uevent.c +406 -0
  86. data/vendor/sedna/kernel/common/u/uevent.h +71 -0
  87. data/vendor/sedna/kernel/common/u/ugnames.cpp +330 -0
  88. data/vendor/sedna/kernel/common/u/ugnames.h +134 -0
  89. data/vendor/sedna/kernel/common/u/uhash_map.h +77 -0
  90. data/vendor/sedna/kernel/common/u/uhdd.c +1018 -0
  91. data/vendor/sedna/kernel/common/u/uhdd.h +206 -0
  92. data/vendor/sedna/kernel/common/u/ummap.cpp +268 -0
  93. data/vendor/sedna/kernel/common/u/ummap.h +60 -0
  94. data/vendor/sedna/kernel/common/u/umutex.c +145 -0
  95. data/vendor/sedna/kernel/common/u/umutex.h +65 -0
  96. data/vendor/sedna/kernel/common/u/upipe.cpp +244 -0
  97. data/vendor/sedna/kernel/common/u/upipe.h +74 -0
  98. data/vendor/sedna/kernel/common/u/uprocess.c +767 -0
  99. data/vendor/sedna/kernel/common/u/uprocess.h +91 -0
  100. data/vendor/sedna/kernel/common/u/usafesync.h +41 -0
  101. data/vendor/sedna/kernel/common/u/usecurity.c +150 -0
  102. data/vendor/sedna/kernel/common/u/usecurity.h +55 -0
  103. data/vendor/sedna/kernel/common/u/usem.c +891 -0
  104. data/vendor/sedna/kernel/common/u/usem.h +83 -0
  105. data/vendor/sedna/kernel/common/u/ushm.c +222 -0
  106. data/vendor/sedna/kernel/common/u/ushm.h +46 -0
  107. data/vendor/sedna/kernel/common/u/usocket.c +541 -0
  108. data/vendor/sedna/kernel/common/u/usocket.h +118 -0
  109. data/vendor/sedna/kernel/common/u/usystem.c +57 -0
  110. data/vendor/sedna/kernel/common/u/usystem.h +46 -0
  111. data/vendor/sedna/kernel/common/u/uthread.c +259 -0
  112. data/vendor/sedna/kernel/common/u/uthread.h +95 -0
  113. data/vendor/sedna/kernel/common/u/utime.c +65 -0
  114. data/vendor/sedna/kernel/common/u/utime.h +40 -0
  115. data/vendor/sedna/kernel/common/u/uutils.c +142 -0
  116. data/vendor/sedna/kernel/common/u/uutils.h +65 -0
  117. data/vendor/sedna/kernel/common/ugc.cpp +156 -0
  118. data/vendor/sedna/kernel/common/ugc.h +15 -0
  119. data/vendor/sedna/kernel/common/utils.cpp +156 -0
  120. data/vendor/sedna/kernel/common/utils.h +133 -0
  121. data/vendor/sedna/kernel/common/version.c +16 -0
  122. data/vendor/sedna/kernel/common/version.h +21 -0
  123. data/vendor/sedna/kernel/common/wustructures.h +18 -0
  124. data/vendor/sedna/kernel/common/wutypes.h +34 -0
  125. data/vendor/sedna/kernel/common/xptr.cpp +17 -0
  126. data/vendor/sedna/kernel/common/xptr.h +211 -0
  127. data/vendor/sedna/ver +1 -0
  128. metadata +142 -14
@@ -0,0 +1,12 @@
1
+ /*
2
+ * File: uatomic.h
3
+ * Copyright (C) 2005 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
4
+ */
5
+
6
+ #ifndef ATOMIC_H
7
+ #define ATOMIC_H
8
+
9
+ #define u_atomic_increment(i) (++i)
10
+ #define u_atomic_decrement(i) (--i)
11
+
12
+ #endif
@@ -0,0 +1,31 @@
1
+ /*
2
+ * File: udl.h
3
+ * Copyright (C) 2005 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
4
+ */
5
+
6
+ #ifndef _U_DL_H
7
+ #define _U_DL_H
8
+
9
+ #ifdef _WIN32
10
+
11
+ typedef HMODULE ULibrary;
12
+ #define UDL_INVALID_LIBRARY NULL
13
+
14
+ #define uLoadLibrary(fname) LoadLibrary(fname)
15
+ #define uFreeLibrary(lib) FreeLibrary(lib)
16
+ #define uGetProcAddress(lib,sym) GetProcAddress(lib,sym)
17
+
18
+ #else //UNIX
19
+
20
+ #include <dlfcn.h>
21
+
22
+ typedef void * ULibrary;
23
+ #define UDL_INVALID_LIBRARY NULL
24
+
25
+ #define uLoadLibrary(fname) dlopen(fname, RTLD_LAZY)
26
+ #define uFreeLibrary(lib) dlclose(lib)
27
+ #define uGetProcAddress(lib,sym) dlsym(lib,sym)
28
+
29
+ #endif
30
+
31
+ #endif //_U_DL_H
@@ -0,0 +1,406 @@
1
+ /*
2
+ * File: uevent.c
3
+ * Copyright (C) 2008 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
4
+ */
5
+
6
+
7
+ #include <assert.h>
8
+ #include "uevent.h"
9
+ #include "common/errdbg/d_printf.h"
10
+ #include "common/u/usecurity.h"
11
+ #include "common/u/ugnames.h"
12
+
13
+ #ifdef _WIN32
14
+
15
+ /* Windows implementation is straight-forward: we create a really thin
16
+ * wrapper around native Win events. Since explicit unlinking of event
17
+ * object is unsupported (the object is destroyed when the last handle
18
+ * is closed) the UnlinkXXX functions aren't fully implemented.
19
+ * Particulary UEventUnlink does nothing except checking for the
20
+ * valid object name (NULL is rejected), and UEventCloseAndUnlink
21
+ * just calls UEventClose. */
22
+
23
+ int UEventUnlink(global_name gn,
24
+ sys_call_error_fun fun)
25
+ {
26
+ int status = -1;
27
+ if (gn == NULL)
28
+ {
29
+ d_printf1("UEventUnlink: NULL is invalid in this context\n");
30
+ }
31
+ else
32
+ {
33
+ status = 0;
34
+ }
35
+ return status;
36
+ }
37
+
38
+ int UEventCreate(UEvent *uEvent,
39
+ USECURITY_ATTRIBUTES* sa,
40
+ int eventType,
41
+ int isSet,
42
+ global_name gn,
43
+ sys_call_error_fun fun)
44
+ {
45
+ int status = -1;
46
+ char buf[128];
47
+ const char *wName = NULL;
48
+ HANDLE handle = NULL;
49
+
50
+ assert(uEvent);
51
+ wName = UWinIPCNameFromGlobalName(gn,buf,sizeof buf);
52
+ if (eventType!=U_AUTORESET_EVENT && eventType!=U_MANUALRESET_EVENT)
53
+ {
54
+ d_printf1("UEventCreate: unrecognised event type requested\n");
55
+ }
56
+ else if (NULL == (handle=CreateEvent(sa, eventType==U_MANUALRESET_EVENT, isSet, wName)))
57
+ {
58
+ SYS_CALL_ERROR(fun, "CreateEvent");
59
+ }
60
+ else
61
+ {
62
+ status = 0;
63
+ }
64
+ uEvent->handle = handle;
65
+ return status;
66
+ }
67
+
68
+ int UEventOpen(UEvent *uEvent,
69
+ global_name gn,
70
+ sys_call_error_fun fun)
71
+ {
72
+ int status = -1;
73
+ char buf[128];
74
+ const char *wName = NULL;
75
+ HANDLE handle = NULL;
76
+
77
+ assert(uEvent);
78
+ wName = UWinIPCNameFromGlobalName(gn,buf,sizeof buf);
79
+ if (NULL == (handle=OpenEvent(EVENT_ALL_ACCESS, FALSE, wName)))
80
+ {
81
+ SYS_CALL_ERROR(fun, "OpenEvent");
82
+ }
83
+ else
84
+ {
85
+ status = 0;
86
+ }
87
+ uEvent->handle = handle;
88
+ return status;
89
+ }
90
+
91
+ int UEventClose(UEvent *uEvent,
92
+ sys_call_error_fun fun)
93
+ {
94
+ int status = -1;
95
+ assert(uEvent);
96
+ if (!CloseHandle(uEvent->handle))
97
+ {
98
+ SYS_CALL_ERROR(fun, "CloseHandle");
99
+ }
100
+ else
101
+ {
102
+ uEvent->handle = NULL;
103
+ status = 0;
104
+ }
105
+ return status;
106
+ }
107
+
108
+ int UEventCloseAndUnlink(UEvent *uEvent,
109
+ sys_call_error_fun fun)
110
+ {
111
+ return UEventClose(uEvent, fun);
112
+ }
113
+
114
+ int UEventSet(UEvent *uEvent,
115
+ sys_call_error_fun fun)
116
+ {
117
+ int status = -1;
118
+ assert(uEvent);
119
+ if (!SetEvent(uEvent->handle))
120
+ {
121
+ SYS_CALL_ERROR(fun, "SetEvent");
122
+ }
123
+ else
124
+ {
125
+ status = 0;
126
+ }
127
+ return status;
128
+ }
129
+
130
+ int UEventReset(UEvent *uEvent,
131
+ sys_call_error_fun fun)
132
+ {
133
+ int status = -1;
134
+ assert(uEvent);
135
+ if (!ResetEvent(uEvent->handle))
136
+ {
137
+ SYS_CALL_ERROR(fun, "ResetEvent");
138
+ }
139
+ else
140
+ {
141
+ status=0;
142
+ }
143
+ return status;
144
+ }
145
+
146
+ int UEventWait(UEvent *uEvent,
147
+ sys_call_error_fun fun)
148
+ {
149
+ int status = -1;
150
+ assert(uEvent);
151
+ if ( WAIT_FAILED == WaitForSingleObject(uEvent->handle, INFINITE))
152
+ {
153
+ SYS_CALL_ERROR(fun, "WaitForSingleObject");
154
+ }
155
+ else
156
+ {
157
+ status=0;
158
+ }
159
+ return status;
160
+ }
161
+
162
+ #else
163
+
164
+ /* On Linux events are implemented using SYS V semaphore arrays.
165
+ * For each event an array of SEMARR_SIZE semaphores is created.
166
+ * The SEMIDX_EVENT_TYPE-th semaphore encodes the event
167
+ * type (either manual-reset [SEMVAL_EVENT_TYPE_MANRESET] or
168
+ * auto-reset [SEMVAL_EVENT_TYPE_AUTORESET]). It is expected
169
+ * that this semaphore is never modified during entire event's
170
+ * lifetime.
171
+ * The SEMIDX_EVENT_STATE-th semaphore holds the current event
172
+ * state (either reset [SEMVAL_EVENT_STATE_RESET] or set
173
+ * [SEMVAL_EVENT_STATE_SET]).
174
+ * Setting/resetting the event is implemented through semctl/SETVAL
175
+ * calls. Waiting on the event implies examination of the
176
+ * SEMIDX_EVENT_TYPE-th semaphore value to determine the proper
177
+ * wait method. Depending on the result of this check either wait
178
+ * (SEMIDX_EVENT_STATE-th unchanged) or wait-and-reset is performed.
179
+ * The later step is performed atomically.
180
+ * SYS V IPC objects has kernel persistence, UnlinkXXX functions
181
+ * were designed to remove an object from the system. Unfortunately
182
+ * the object is removed immediately, it doesn't matter if any
183
+ * process was using the object at the moment the call was made.
184
+ * This is the major deviation between Windows and Linux event
185
+ * implementations. */
186
+
187
+ #include <sys/types.h>
188
+ #include <sys/ipc.h>
189
+ #include <sys/sem.h>
190
+
191
+ #define SEMARR_SIZE 2
192
+
193
+ #define SEMIDX_EVENT_STATE 1
194
+ #define SEMIDX_EVENT_TYPE 0
195
+
196
+ #define SEMVAL_EVENT_STATE_SET (int)7
197
+ #define SEMVAL_EVENT_STATE_RESET (int)3
198
+ #define SEMVAL_EVENT_TYPE_AUTORESET (int)2
199
+ #define SEMVAL_EVENT_TYPE_MANRESET (int)1
200
+
201
+
202
+ int UEventUnlink(global_name gn,
203
+ sys_call_error_fun fun)
204
+ {
205
+ int status = -1;
206
+ UEvent uEvent = {};
207
+
208
+ if (UEventOpen(&uEvent, gn, fun)==0 &&
209
+ UEventCloseAndUnlink(&uEvent, fun)==0)
210
+ {
211
+ status = 0;
212
+ }
213
+ return status;
214
+ }
215
+
216
+ int UEventCreate(UEvent *uEvent,
217
+ USECURITY_ATTRIBUTES* sa,
218
+ int eventType,
219
+ int isSet,
220
+ global_name gn,
221
+ sys_call_error_fun fun)
222
+ {
223
+ int status = -1;
224
+ int semid = -1;
225
+ USECURITY_ATTRIBUTES evmode = U_SEDNA_SEMAPHORE_ACCESS_PERMISSIONS_MASK;
226
+ key_t key = IPC_PRIVATE;
227
+
228
+ assert(uEvent);
229
+ key = USys5IPCKeyFromGlobalName(gn);
230
+ uEvent->semid = -1;
231
+ if (sa) evmode = *sa;
232
+ evmode |= IPC_CREAT | IPC_EXCL;
233
+
234
+ if (eventType != U_AUTORESET_EVENT && eventType != U_MANUALRESET_EVENT)
235
+ {
236
+ d_printf1("UEventCreate: unrecognised event type requested\n");
237
+ }
238
+ else if (semid = semget(key, SEMARR_SIZE, evmode), semid == -1)
239
+ {
240
+ SYS_CALL_ERROR(fun, "semget");
241
+ }
242
+ else
243
+ {
244
+ unsigned short init[SEMARR_SIZE] = {0};
245
+ unsigned short initState = SEMVAL_EVENT_STATE_RESET;
246
+ unsigned short initType = SEMVAL_EVENT_TYPE_MANRESET;
247
+
248
+ if (eventType == U_AUTORESET_EVENT)
249
+ initType = SEMVAL_EVENT_TYPE_AUTORESET;
250
+
251
+ if (isSet)
252
+ initState = SEMVAL_EVENT_STATE_SET;
253
+
254
+ init[SEMIDX_EVENT_TYPE] = initType;
255
+ init[SEMIDX_EVENT_STATE] = initState;
256
+
257
+ if (semctl(semid, 0, SETALL, init) == -1)
258
+ SYS_CALL_ERROR(fun, "semctl");
259
+ else status = 0;
260
+
261
+ }
262
+ if (status == 0) uEvent->semid = semid;
263
+ return status;
264
+ }
265
+
266
+ int UEventOpen(UEvent *uEvent,
267
+ global_name gn,
268
+ sys_call_error_fun fun)
269
+ {
270
+ int status = -1, semid = -1;
271
+ key_t key = IPC_PRIVATE;
272
+
273
+ assert(uEvent);
274
+ key = USys5IPCKeyFromGlobalName(gn);
275
+ if (gn == NULL)
276
+ {
277
+ d_printf1("UEventOpen: NULL invalid in this context\n");
278
+ }
279
+ else if (semid = semget(key, 0, 0), semid==-1)
280
+ {
281
+ SYS_CALL_ERROR(fun,"semget");
282
+ }
283
+ else
284
+ {
285
+ status = 0;
286
+ }
287
+ if (status == 0) uEvent->semid = semid;
288
+ return status;
289
+ }
290
+
291
+ int UEventClose(UEvent *uEvent,
292
+ sys_call_error_fun fun)
293
+ {
294
+ assert(uEvent);
295
+ uEvent->semid = -1;
296
+ return 0;
297
+ }
298
+
299
+ int UEventCloseAndUnlink(UEvent *uEvent,
300
+ sys_call_error_fun fun)
301
+ {
302
+ int status = -1;
303
+
304
+ assert(uEvent);
305
+ if (semctl(uEvent->semid, 0, IPC_RMID) == -1)
306
+ SYS_CALL_ERROR(fun,"semctl");
307
+ else status = 0;
308
+
309
+ return (status==0) ? UEventClose(uEvent, fun) : status;
310
+ }
311
+
312
+
313
+ int UEventSet(UEvent *uEvent,
314
+ sys_call_error_fun fun)
315
+ {
316
+ int status = -1;
317
+
318
+ assert(uEvent);
319
+ if (-1 == semctl(uEvent->semid, SEMIDX_EVENT_STATE, SETVAL, SEMVAL_EVENT_STATE_SET))
320
+ SYS_CALL_ERROR(fun, "semctl");
321
+ else status = 0;
322
+
323
+ return status;
324
+ }
325
+
326
+ int UEventReset(UEvent *uEvent,
327
+ sys_call_error_fun fun)
328
+ {
329
+ int status = -1;
330
+
331
+ assert(uEvent);
332
+ if (-1 == semctl(uEvent->semid, SEMIDX_EVENT_STATE, SETVAL, SEMVAL_EVENT_STATE_RESET))
333
+ SYS_CALL_ERROR(fun, "semctl");
334
+ else status = 0;
335
+
336
+ return status;
337
+ }
338
+
339
+ static
340
+ int EventWait(UEvent *uEvent, sys_call_error_fun fun)
341
+ {
342
+ int status = -1;
343
+ struct sembuf ops[2] = {{0}};
344
+
345
+ assert(uEvent);
346
+ ops[0].sem_num = SEMIDX_EVENT_STATE;
347
+ ops[0].sem_op = -(SEMVAL_EVENT_STATE_SET);
348
+ ops[1].sem_num = SEMIDX_EVENT_STATE;
349
+ ops[1].sem_op = SEMVAL_EVENT_STATE_SET;
350
+
351
+ retry:
352
+ if (-1 == semop(uEvent->semid, ops, 2))
353
+ {
354
+ if (errno == EINTR) goto retry;
355
+ SYS_CALL_ERROR(fun, "semop");
356
+ }
357
+ else status = 0;
358
+
359
+ return status;
360
+ }
361
+
362
+ static
363
+ int EventWaitReset(UEvent *uEvent, sys_call_error_fun fun)
364
+ {
365
+ int status = -1;
366
+ struct sembuf ops[2] = {{0}};
367
+
368
+ assert(uEvent);
369
+ ops[0].sem_num = SEMIDX_EVENT_STATE;
370
+ ops[0].sem_op = -(SEMVAL_EVENT_STATE_SET);
371
+ ops[1].sem_num = SEMIDX_EVENT_STATE;
372
+ ops[1].sem_op = SEMVAL_EVENT_STATE_RESET;
373
+
374
+ retry:
375
+ if (-1 == semop(uEvent->semid, ops, 2))
376
+ {
377
+ if (errno == EINTR) goto retry;
378
+ SYS_CALL_ERROR(fun, "semop");
379
+ }
380
+ else status = 0;
381
+
382
+ return status;
383
+ }
384
+
385
+ int UEventWait(UEvent *uEvent,
386
+ sys_call_error_fun fun)
387
+ {
388
+ int status = -1, evtype = 0;
389
+
390
+ assert(uEvent);
391
+ if (evtype = semctl(uEvent->semid, SEMIDX_EVENT_TYPE, GETVAL),
392
+ evtype != SEMVAL_EVENT_TYPE_MANRESET &&
393
+ evtype != SEMVAL_EVENT_TYPE_AUTORESET)
394
+ {
395
+ d_printf1("UEventWait: unexpected semaphore value (probably wrong semid)\n");
396
+ }
397
+ else if (evtype == SEMVAL_EVENT_TYPE_MANRESET)
398
+ status = EventWait(uEvent, fun);
399
+ else
400
+ status = EventWaitReset(uEvent, fun);
401
+
402
+ return status;
403
+ }
404
+
405
+ #endif
406
+