… | |
… | |
41 | } |
41 | } |
42 | |
42 | |
43 | static void |
43 | static void |
44 | asynccheck_hook (void *data) |
44 | asynccheck_hook (void *data) |
45 | { |
45 | { |
46 | /* ceding from C means allocating a stack, but we assume this is a rare case */ |
46 | /* this loops as long as we have _other_ coros with the same or higher priority */ |
|
|
47 | while (CORO_NREADY && CORO_CEDE) |
|
|
48 | ; |
|
|
49 | } |
|
|
50 | |
|
|
51 | static double |
|
|
52 | prepare_hook (void *data) |
|
|
53 | { |
|
|
54 | /* this yields once to another coro with any priority */ |
47 | while (CORO_NREADY) |
55 | if (CORO_NREADY) |
48 | CORO_CEDE; |
56 | { |
|
|
57 | CORO_CEDE_NOTSELF; |
|
|
58 | /* |
|
|
59 | * timers might have changed, and Event fails to notice this |
|
|
60 | * so we have to assume the worst. If Event didn't have that bug, |
|
|
61 | * we would only need to do this if CORO_NREADY is != 0 now. |
|
|
62 | */ |
|
|
63 | return 0.; |
|
|
64 | } |
|
|
65 | else |
|
|
66 | return 85197.73; /* this is as good as any value, but it factors badly with common values */ |
49 | } |
67 | } |
50 | |
68 | |
51 | MODULE = Coro::Event PACKAGE = Coro::Event |
69 | MODULE = Coro::Event PACKAGE = Coro::Event |
52 | |
70 | |
53 | PROTOTYPES: ENABLE |
71 | PROTOTYPES: ENABLE |
… | |
… | |
56 | { |
74 | { |
57 | I_EVENT_API ("Coro::Event"); |
75 | I_EVENT_API ("Coro::Event"); |
58 | I_CORO_API ("Coro::Event"); |
76 | I_CORO_API ("Coro::Event"); |
59 | |
77 | |
60 | GEventAPI->add_hook ("asynccheck", (void *)asynccheck_hook, 0); |
78 | GEventAPI->add_hook ("asynccheck", (void *)asynccheck_hook, 0); |
|
|
79 | GEventAPI->add_hook ("prepare", (void *)prepare_hook, 0); |
61 | } |
80 | } |
62 | |
81 | |
63 | void |
82 | void |
64 | _install_std_cb (SV *self, int type) |
83 | _install_std_cb (SV *self, int type) |
65 | CODE: |
84 | CODE: |