• R/O
  • SSH
  • HTTPS

neurocache-dev: Commit


Commit MetaInfo

Revision2 (tree)
Time2019-12-02 20:28:31
Authorhyw3

Log Message

Upgraded to NeuroCache version 1.2.2.

Change Summary

Incremental Difference

--- libneural/sel_poll.c (revision 1)
+++ libneural/sel_poll.c (revision 2)
@@ -64,6 +64,16 @@
6464 NEURAL_LISTENER *listener;
6565 } obj;
6666 unsigned char what;
67+ /* This looks like this:
68+ * 0 = unused
69+ * 1 = conn
70+ * 2 = listener
71+ * In particular we use token/idx conversion on the neural
72+ * selector implementations so that we can invoke this in a way
73+ * they callback to us whilst processing their hooks and use
74+ * the following logic for pre/post neural select.
75+ */
76+ unsigned int idx_init, idx_total;
6777 } sel_obj;
6878
6979 typedef struct st_sel_ctx {
@@ -71,11 +81,16 @@
7181 unsigned int pfds_used, pfds_size;
7282 sel_obj *obj_table;
7383 unsigned int obj_used, obj_size;
84+ /* Ensure that we only get callbacks for tokens of the object we're
85+ * hooking during both pre and post neural select */
7486 NEURAL_SELECTOR_TOKEN hook_current;
7587 } sel_ctx;
7688
7789 #define OBJ_TABLE_START 32
7890 #define POLLFD_TABLE_START 4
91+/* Use uintptr_t to cast to long pointer instead of unsigned int */
92+#define TOKENIFY(idx) (NEURAL_SELECTOR_TOKEN)((uintptr_t)idx | 0x8000)
93+#define IDXIFY(tok) ((uintptr_t)tok & 0x7FFF)
7994
8095 static void obj_table_zilch(sel_obj *items, unsigned int num)
8196 {
@@ -157,6 +172,36 @@
157172 return loop;
158173 }
159174
175+static NEURAL_SELECTOR_TOKEN obj_table_add_listener(sel_ctx *ctx,
176+ NEURAL_LISTENER *listener)
177+{
178+ int loc = obj_table_add(ctx);
179+ if(loc < 0) return NEURAL_SELECTOR_TOKEN_NULL;
180+ ctx->obj_table[loc].what = 2;
181+ ctx->obj_table[loc].obj.listener = listener;
182+ return TOKENIFY(loc);
183+}
184+
185+static NEURAL_SELECTOR_TOKEN obj_table_add_connection(sel_ctx *ctx,
186+ NEURAL_CONNECTION *conn)
187+{
188+ int loc = obj_table_add(ctx);
189+ if(loc < 0) return NEURAL_SELECTOR_TOKEN_NULL;
190+ ctx->obj_table[loc].what = 1;
191+ ctx->obj_table[loc].obj.conn = conn;
192+ return TOKENIFY(loc);
193+}
194+
195+static void obj_table_del(sel_ctx *ctx, NEURAL_SELECTOR_TOKEN tok)
196+{
197+ unsigned int idx = IDXIFY(tok);
198+ assert(idx < ctx->obj_size);
199+ assert(ctx->obj_table[idx].what != 0);
200+ assert(ctx->obj_used > 0);
201+ ctx->obj_table[idx].what = 0;
202+ ctx->obj_used--;
203+}
204+
160205 static void obj_table_pre_select(sel_ctx *ctx);
161206 static void obj_table_post_select(sel_ctx *ctx);
162207 static int sel_on_create(NEURAL_SELECTOR *);
@@ -221,13 +266,13 @@
221266 }
222267
223268 static int sel_select(NEURAL_SELECTOR *sel, unsigned long usec_timeout,
224- int use_timeout)
269+ int use_timeout)
225270 {
226271 int res;
227272 sel_ctx *ctx = neural_selector_get_vtdata(sel);
228273 obj_table_pre_select(ctx);
229274 res = poll(ctx->pollfds, ctx->pfds_used, use_timeout ?
230- (int)(usec_timeout / 1000) : -1);
275+ (int)(usec_timeout / 1000) : -1);
231276 if(res > 0) obj_table_post_select(ctx);
232277 return res;
233278 }
@@ -239,27 +284,31 @@
239284 }
240285
241286 static NEURAL_SELECTOR_TOKEN sel_add_listener(NEURAL_SELECTOR *sel,
242- NEURAL_LISTENER *listener)
287+ NEURAL_LISTENER *listener)
243288 {
244289 sel_ctx *ctx = neural_selector_get_vtdata(sel);
290+ return obj_table_add_listener(ctx, listener);
245291 }
246292
247293 static NEURAL_SELECTOR_TOKEN sel_add_connection(NEURAL_SELECTOR *sel,
248- NEURAL_CONNECTION *conn)
294+ NEURAL_CONNECTION *conn)
249295 {
250296 sel_ctx *ctx = neural_selector_get_vtdata(sel);
297+ return obj_table_add_connection(ctx, conn);
251298 }
252299
253300 static void sel_del_listener(NEURAL_SELECTOR *sel, NEURAL_LISTENER *listener,
254- NEURAL_SELECTOR_TOKEN token)
301+ NEURAL_SELECTOR_TOKEN token)
255302 {
256303 sel_ctx *ctx = neural_selector_get_vtdata(sel);
304+ obj_table_del(ctx, token);
257305 }
258306
259307 static void sel_del_connection(NEURAL_SELECTOR *sel, NEURAL_CONNECTION *conn,
260- NEURAL_SELECTOR_TOKEN token)
308+ NEURAL_SELECTOR_TOKEN token)
261309 {
262310 sel_ctx *ctx = neural_selector_get_vtdata(sel);
311+ obj_table_del(ctx, token);
263312 }
264313
265314 static void obj_table_pre_select(sel_ctx *ctx)
@@ -268,6 +317,9 @@
268317 sel_obj *item = ctx->obj_table;
269318 ctx->pfds_used = 0;
270319 while(loop < ctx->obj_size) {
320+ item->idx_init = ctx->pfds_used;
321+ item->idx_total = 0;
322+ ctx->hook_current = TOKENIFY(loop);
271323 switch(item->what) {
272324 case 1:
273325 neural_connection_pre_select(item->obj.conn);
@@ -278,6 +330,9 @@
278330 default:
279331 break;
280332 }
333+ if(item->idx_total) {
334+ assert(item->idx_init + item->idx_total == ctx->pfds_used);
335+ }
281336 item++;
282337 loop++;
283338 }
@@ -288,21 +343,78 @@
288343 unsigned int loop = 0;
289344 sel_obj *item = ctx->obj_table;
290345 while(loop < ctx->obj_size) {
291- switch(item->what) {
292- case 1:
293- neural_connection_post_select(item->obj.conn);
294- break;
295- case 2:
296- neural_listener_post_select(item->obj.listener);
297- break;
298- default:
299- break;
300- }
301- item++;
302- loop++;
346+ if(item->idx_total) {
347+ ctx->hook_current = TOKENIFY(loop);
348+ switch(item->what) {
349+ case 1:
350+ neural_connection_post_select(item->obj.conn);
351+ break;
352+ case 2:
353+ neural_listener_post_select(item->obj.listener);
354+ break;
355+ default:
356+ break;
357+ }
358+ }
359+ item++;
360+ loop++;
303361 }
304362 }
305363
364+static void sel_fd_set(NEURAL_SELECTOR *sel, NEURAL_SELECTOR_TOKEN token,
365+ int fd, unsigned char flags)
366+{
367+ struct pollfd *pfd;
368+ sel_ctx *ctx = neural_selector_get_vtdata(sel);
369+ unsigned int idx = IDXIFY(token);
370+ sel_obj *obj = ctx->obj_table + idx;
371+ assert(token == ctx->hook_current);
372+ assert(idx < ctx->obj_size);
373+ assert((obj->what == 1) || (obj->what == 2));
374+ if(!pollfds_expand(ctx)) {
375+ SYS_fprintf(SYS_stderr, "Warning, expansion for fd_set failed\n");
376+ return;
377+ }
378+ assert(obj->idx_init + obj->idx_total == ctx->pfds_used);
379+ pfd = ctx->pollfds + (obj->idx_init + obj->idx_total++);
380+ pfd->fd = fd;
381+ pfd->events = ((flags & SELECTOR_FLAG_READ) ? POLLIN : 0) |
382+ ((flags & SELECTOR_FLAG_SEND) ? POLLOUT : 0) |
383+ ((flags & SELECTOR_FLAG_EXCEPT) ?
384+ POLLERR | POLLHUP | POLLNVAL : 0);
385+ ctx->pfds_used++;
386+}
387+
388+static unsigned char sel_fd_test(const NEURAL_SELECTOR *sel,
389+ NEURAL_SELECTOR_TOKEN token, int fd)
390+{
391+ unsigned int loop = 0;
392+ sel_ctx *ctx = neural_selector_get_vtdata(sel);
393+ unsigned int idx = IDXIFY(token);
394+ sel_obj *obj = ctx->obj_table + idx;
395+ assert(token == ctx->hook_current);
396+ assert(idx < ctx->obj_size);
397+ assert((obj->what == 1) || (obj->what == 2));
398+ assert(!obj->idx_total ||
399+ ((obj->idx_init + obj->idx_total) <= ctx->pfds_used));
400+ while(loop < obj->idx_total) {
401+ struct pollfd *pfd = ctx->pollfds +
402+ (obj->idx_init + loop++);
403+ if(pfd->fd == fd) {
404+ unsigned char flags = 0;
405+ if(pfd->revents & POLLIN)
406+ flags |= SELECTOR_FLAG_READ;
407+ if(pfd->revents & POLLOUT)
408+ flags |= SELECTOR_FLAG_SEND;
409+ if(!flags && (pfd->revents & (POLLERR|POLLHUP|POLLNVAL)))
410+ flags = SELECTOR_FLAG_EXCEPT;
411+ return flags;
412+ }
413+ }
414+ assert(NULL == "sel_fd_test had no collision!");
415+ return 0;
416+}
417+
306418 static int sel_ctrl(NEURAL_SELECTOR *sel, int cmd, void *p)
307419 {
308420 switch(cmd) {
@@ -309,11 +421,13 @@
309421 case NEURAL_FD_CTRL_FDSET:
310422 {
311423 NEURAL_FD_FDSET *args = p;
424+ sel_fd_set(sel, args->token, args->fd, args->flags);
312425 }
313426 break;
314427 case NEURAL_FD_CTRL_FDTEST:
315428 {
316429 NEURAL_FD_FDTEST *args = p;
430+ args->flags = sel_fd_test(sel, args->token, args->fd);
317431 }
318432 break;
319433 default:
--- libneural/sel_select.c (revision 1)
+++ libneural/sel_select.c (revision 2)
@@ -81,6 +81,9 @@
8181 } sel_ctx;
8282
8383 #define OBJ_TABLE_START 32
84+/* Use uintptr_t to cast to long pointer instead of unsigned int */
85+#define TOKENIFY(idx) (NEURAL_SELECTOR_TOKEN)((uintptr_t)idx | 0x8000)
86+#define IDXIFY(tok) ((uintptr_t)tok & 0x7FFF)
8487
8588 static void obj_table_zilch(sel_obj *items, unsigned int num)
8689 {
@@ -136,6 +139,7 @@
136139 if(loc < 0) return NEURAL_SELECTOR_TOKEN_NULL;
137140 ctx->obj_table[loc].what = 2;
138141 ctx->obj_table[loc].obj.listener = listener;
142+ return TOKENIFY(loc);
139143 }
140144
141145 static NEURAL_SELECTOR_TOKEN obj_table_add_connection(sel_ctx *ctx,
@@ -145,8 +149,19 @@
145149 if(loc < 0) return NEURAL_SELECTOR_TOKEN_NULL;
146150 ctx->obj_table[loc].what = 1;
147151 ctx->obj_table[loc].obj.conn = conn;
152+ return TOKENIFY(loc);
148153 }
149154
155+static void obj_table_del(sel_ctx *ctx, NEURAL_SELECTOR_TOKEN tok)
156+{
157+ unsigned int idx = IDXIFY(tok);
158+ assert(idx < ctx->obj_size);
159+ assert(ctx->obj_table[idx].what != 0);
160+ assert(ctx->obj_used > 0);
161+ ctx->obj_table[idx].what = 0;
162+ ctx->obj_used--;
163+}
164+
150165 static void obj_table_pre_select(sel_ctx *ctx)
151166 {
152167 unsigned int loop = 0;
@@ -327,6 +342,7 @@
327342 NEURAL_SELECTOR_TOKEN token)
328343 {
329344 sel_ctx *ctx = neural_selector_get_vtdata(sel);
345+ obj_table_del(ctx, token);
330346 }
331347
332348 static void sel_del_connection(NEURAL_SELECTOR *sel, NEURAL_CONNECTION *conn,
@@ -333,6 +349,7 @@
333349 NEURAL_SELECTOR_TOKEN token)
334350 {
335351 sel_ctx *ctx = neural_selector_get_vtdata(sel);
352+ obj_table_del(ctx, token);
336353 }
337354
338355 static void sel_fd_set(NEURAL_SELECTOR *sel, NEURAL_SELECTOR_TOKEN token,
--- configure (revision 1)
+++ configure (revision 2)
@@ -1,6 +1,6 @@
11 #! /bin/sh
22 # Guess values for system-dependent variables and create Makefiles.
3-# Generated by GNU Autoconf 2.59 for neurocache 1.0.1.
3+# Generated by GNU Autoconf 2.59 for neurocache 1.2.2.
44 #
55 # Report bugs to <contributing@hyang.org>.
66 #
@@ -423,8 +423,8 @@
423423 # Identity of this package.
424424 PACKAGE_NAME='neurocache'
425425 PACKAGE_TARNAME='neurocache'
426-PACKAGE_VERSION='1.0.1'
427-PACKAGE_STRING='neurocache 1.0.1'
426+PACKAGE_VERSION='1.2.2'
427+PACKAGE_STRING='neurocache 1.2.2'
428428 PACKAGE_BUGREPORT='contributing@hyang.org'
429429
430430 ac_unique_file="ncsess-server/server.c"
@@ -1166,7 +1166,7 @@
11661166 test -n "$ac_init_help" && exit 0
11671167 if $ac_init_version; then
11681168 cat <<\_ACEOF
1169-Neurocache 1.0.1 configure
1169+Neurocache 1.2.2 configure
11701170 Generated by GNU Autoconf 2.59
11711171
11721172 Copyright (C) 2003 Free Software Foundation, Inc.
@@ -1180,7 +1180,7 @@
11801180 This file contains any messages produced by compilers while
11811181 running configure, to aid debugging if configure makes a mistake.
11821182
1183-It was created by neurocache $as_me 1.0.1, which was
1183+It was created by neurocache $as_me 1.2.2, which was
11841184 generated by GNU Autoconf 2.59. Invocation command line was
11851185
11861186 $ $0 $@
@@ -1742,7 +1742,7 @@
17421742
17431743 # Define the identity of the package.
17441744 PACKAGE=neurocache
1745-VERSION=1.0.1
1745+VERSION=1.2.2
17461746
17471747 cat >>confdefs.h <<_ACEOF
17481748 #define PACKAGE "$PACKAGE"
@@ -21468,7 +21468,7 @@
2146821468 } >&5
2146921469 cat >&5 <<_CSEOF
2147021470
21471-This file was extended by neurocache $as_me 1.0.1, which was
21471+This file was extended by neurocache $as_me 1.2.2, which was
2147221472 generated by GNU Autoconf 2.59. Invocation command line was
2147321473
2147421474 CONFIG_FILES = $CONFIG_FILES
@@ -21531,7 +21531,7 @@
2153121531
2153221532 cat >>$CONFIG_STATUS <<_ACEOF
2153321533 ac_cs_version="\\
21534-neurocache config.status 1.0.1
21534+neurocache config.status 1.2.2
2153521535 configured by $0, generated by GNU Autoconf 2.59,
2153621536 with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
2153721537
Show on old repository browser