ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.69 by root, Tue Nov 6 00:10:04 2007 UTC vs.
Revision 1.70 by root, Tue Nov 6 00:52:32 2007 UTC

153volatile double SIGFPE_REQ = 0.0f; 153volatile double SIGFPE_REQ = 0.0f;
154#endif 154#endif
155 155
156/*****************************************************************************/ 156/*****************************************************************************/
157 157
158static void (*syserr_cb)(void); 158static void (*syserr_cb)(const char *msg);
159 159
160void ev_set_syserr_cb (void (*cb)(void)) 160void ev_set_syserr_cb (void (*cb)(const char *msg))
161{ 161{
162 syserr_cb = cb; 162 syserr_cb = cb;
163} 163}
164 164
165static void 165static void
166syserr (void) 166syserr (const char *msg)
167{ 167{
168 if (!msg)
169 msg = "(libev) system error";
170
168 if (syserr_cb) 171 if (syserr_cb)
169 syserr_cb (); 172 syserr_cb (msg);
170 else 173 else
171 { 174 {
172 perror ("libev"); 175 perror (msg);
173 abort (); 176 abort ();
174 } 177 }
175} 178}
176 179
177static void *(*alloc)(void *ptr, long size); 180static void *(*alloc)(void *ptr, long size);
378} 381}
379 382
380static void 383static void
381fd_change (EV_P_ int fd) 384fd_change (EV_P_ int fd)
382{ 385{
383 if (anfds [fd].reify || fdchangecnt < 0) 386 if (anfds [fd].reify)
384 return; 387 return;
385 388
386 anfds [fd].reify = 1; 389 anfds [fd].reify = 1;
387 390
388 ++fdchangecnt; 391 ++fdchangecnt;
426 fd_kill (EV_A_ fd); 429 fd_kill (EV_A_ fd);
427 return; 430 return;
428 } 431 }
429} 432}
430 433
431/* susually called after fork if method needs to re-arm all fds from scratch */ 434/* usually called after fork if method needs to re-arm all fds from scratch */
432static void 435static void
433fd_rearm_all (EV_P) 436fd_rearm_all (EV_P)
434{ 437{
435 int fd; 438 int fd;
436 439
693 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); 696 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods);
694#endif 697#endif
695#if EV_USE_SELECT 698#if EV_USE_SELECT
696 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); 699 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods);
697#endif 700#endif
701
702 ev_watcher_init (&sigev, sigcb);
703 ev_set_priority (&sigev, EV_MAXPRI);
698 } 704 }
699} 705}
700 706
701void 707void
702loop_destroy (EV_P) 708loop_destroy (EV_P)
728 array_free (idle, ); 734 array_free (idle, );
729 array_free (prepare, ); 735 array_free (prepare, );
730 array_free (check, ); 736 array_free (check, );
731 737
732 method = 0; 738 method = 0;
733 /*TODO*/
734} 739}
735 740
736void 741static void
737loop_fork (EV_P) 742loop_fork (EV_P)
738{ 743{
739 /*TODO*/
740#if EV_USE_EPOLL 744#if EV_USE_EPOLL
741 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); 745 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A);
742#endif 746#endif
743#if EV_USE_KQUEUE 747#if EV_USE_KQUEUE
744 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); 748 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A);
745#endif 749#endif
750
751 if (ev_is_active (&sigev))
752 {
753 /* default loop */
754
755 ev_ref (EV_A);
756 ev_io_stop (EV_A_ &sigev);
757 close (sigpipe [0]);
758 close (sigpipe [1]);
759
760 while (pipe (sigpipe))
761 syserr ("(libev) error creating pipe");
762
763 siginit (EV_A);
764 }
765
766 postfork = 0;
746} 767}
747 768
748#if EV_MULTIPLICITY 769#if EV_MULTIPLICITY
749struct ev_loop * 770struct ev_loop *
750ev_loop_new (int methods) 771ev_loop_new (int methods)
769} 790}
770 791
771void 792void
772ev_loop_fork (EV_P) 793ev_loop_fork (EV_P)
773{ 794{
774 loop_fork (EV_A); 795 postfork = 1;
775} 796}
776 797
777#endif 798#endif
778 799
779#if EV_MULTIPLICITY 800#if EV_MULTIPLICITY
802 823
803 loop_init (EV_A_ methods); 824 loop_init (EV_A_ methods);
804 825
805 if (ev_method (EV_A)) 826 if (ev_method (EV_A))
806 { 827 {
807 ev_watcher_init (&sigev, sigcb);
808 ev_set_priority (&sigev, EV_MAXPRI);
809 siginit (EV_A); 828 siginit (EV_A);
810 829
811#ifndef WIN32 830#ifndef WIN32
812 ev_signal_init (&childev, childcb, SIGCHLD); 831 ev_signal_init (&childev, childcb, SIGCHLD);
813 ev_set_priority (&childev, EV_MAXPRI); 832 ev_set_priority (&childev, EV_MAXPRI);
846{ 865{
847#if EV_MULTIPLICITY 866#if EV_MULTIPLICITY
848 struct ev_loop *loop = default_loop; 867 struct ev_loop *loop = default_loop;
849#endif 868#endif
850 869
851 loop_fork (EV_A); 870 if (method)
852 871 postfork = 1;
853 ev_io_stop (EV_A_ &sigev);
854 close (sigpipe [0]);
855 close (sigpipe [1]);
856 pipe (sigpipe);
857
858 ev_ref (EV_A); /* signal watcher */
859 siginit (EV_A);
860} 872}
861 873
862/*****************************************************************************/ 874/*****************************************************************************/
863 875
864static void 876static void
1042 { 1054 {
1043 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 1055 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
1044 call_pending (EV_A); 1056 call_pending (EV_A);
1045 } 1057 }
1046 1058
1059 /* we might have forked, so reify kernel state if necessary */
1060 if (expect_false (postfork))
1061 loop_fork (EV_A);
1062
1047 /* update fd-related kernel structures */ 1063 /* update fd-related kernel structures */
1048 fd_reify (EV_A); 1064 fd_reify (EV_A);
1049 1065
1050 /* calculate blocking time */ 1066 /* calculate blocking time */
1051 1067

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines