… | |
… | |
36 | |
36 | |
37 | #include <stdio.h> |
37 | #include <stdio.h> |
38 | |
38 | |
39 | #include <assert.h> |
39 | #include <assert.h> |
40 | #include <errno.h> |
40 | #include <errno.h> |
|
|
41 | #include <sys/types.h> |
|
|
42 | #include <sys/wait.h> |
41 | #include <sys/time.h> |
43 | #include <sys/time.h> |
42 | #include <time.h> |
44 | #include <time.h> |
43 | |
45 | |
44 | #ifndef HAVE_MONOTONIC |
46 | #ifndef HAVE_MONOTONIC |
45 | # ifdef CLOCK_MONOTONIC |
47 | # ifdef CLOCK_MONOTONIC |
… | |
… | |
59 | # define HAVE_REALTIME 1 /* posix requirement, but might be slower */ |
61 | # define HAVE_REALTIME 1 /* posix requirement, but might be slower */ |
60 | #endif |
62 | #endif |
61 | |
63 | |
62 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
64 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
63 | #define MAX_BLOCKTIME 60. |
65 | #define MAX_BLOCKTIME 60. |
|
|
66 | #define PID_HASHSIZE 16 /* size of pid hahs table, must be power of two */ |
64 | |
67 | |
65 | #include "ev.h" |
68 | #include "ev.h" |
66 | |
69 | |
67 | typedef struct ev_watcher *W; |
70 | typedef struct ev_watcher *W; |
68 | typedef struct ev_watcher_list *WL; |
71 | typedef struct ev_watcher_list *WL; |
… | |
… | |
332 | static struct ev_check **checks; |
335 | static struct ev_check **checks; |
333 | static int checkmax, checkcnt; |
336 | static int checkmax, checkcnt; |
334 | |
337 | |
335 | /*****************************************************************************/ |
338 | /*****************************************************************************/ |
336 | |
339 | |
|
|
340 | static struct ev_child *childs [PID_HASHSIZE]; |
|
|
341 | static struct ev_signal childev; |
|
|
342 | |
|
|
343 | #ifndef WCONTINUED |
|
|
344 | # define WCONTINUED 0 |
|
|
345 | #endif |
|
|
346 | |
|
|
347 | static void |
|
|
348 | childcb (struct ev_signal *sw, int revents) |
|
|
349 | { |
|
|
350 | struct ev_child *w; |
|
|
351 | int pid, status; |
|
|
352 | |
|
|
353 | while ((pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)) != -1) |
|
|
354 | for (w = childs [pid & (PID_HASHSIZE - 1)]; w; w = w->next) |
|
|
355 | if (w->pid == pid || w->pid == -1) |
|
|
356 | { |
|
|
357 | w->status = status; |
|
|
358 | event ((W)w, EV_CHILD); |
|
|
359 | } |
|
|
360 | } |
|
|
361 | |
|
|
362 | /*****************************************************************************/ |
|
|
363 | |
337 | #if HAVE_EPOLL |
364 | #if HAVE_EPOLL |
338 | # include "ev_epoll.c" |
365 | # include "ev_epoll.c" |
339 | #endif |
366 | #endif |
340 | #if HAVE_SELECT |
367 | #if HAVE_SELECT |
341 | # include "ev_select.c" |
368 | # include "ev_select.c" |
… | |
… | |
368 | |
395 | |
369 | if (ev_method) |
396 | if (ev_method) |
370 | { |
397 | { |
371 | evw_init (&sigev, sigcb); |
398 | evw_init (&sigev, sigcb); |
372 | siginit (); |
399 | siginit (); |
|
|
400 | |
|
|
401 | evsignal_init (&childev, childcb, SIGCHLD); |
|
|
402 | evsignal_start (&childev); |
373 | } |
403 | } |
374 | |
404 | |
375 | return ev_method; |
405 | return ev_method; |
376 | } |
406 | } |
377 | |
407 | |
… | |
… | |
876 | ev_clear ((W)w); |
906 | ev_clear ((W)w); |
877 | if (ev_is_active (w)) |
907 | if (ev_is_active (w)) |
878 | return; |
908 | return; |
879 | |
909 | |
880 | checks [w->active - 1] = checks [--checkcnt]; |
910 | checks [w->active - 1] = checks [--checkcnt]; |
|
|
911 | ev_stop ((W)w); |
|
|
912 | } |
|
|
913 | |
|
|
914 | void evchild_start (struct ev_child *w) |
|
|
915 | { |
|
|
916 | if (ev_is_active (w)) |
|
|
917 | return; |
|
|
918 | |
|
|
919 | ev_start ((W)w, 1); |
|
|
920 | wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
|
|
921 | } |
|
|
922 | |
|
|
923 | void evchild_stop (struct ev_child *w) |
|
|
924 | { |
|
|
925 | ev_clear ((W)w); |
|
|
926 | if (ev_is_active (w)) |
|
|
927 | return; |
|
|
928 | |
|
|
929 | wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
881 | ev_stop ((W)w); |
930 | ev_stop ((W)w); |
882 | } |
931 | } |
883 | |
932 | |
884 | /*****************************************************************************/ |
933 | /*****************************************************************************/ |
885 | |
934 | |