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

Comparing libev/ev.c (file contents):
Revision 1.77 by root, Thu Nov 8 00:44:17 2007 UTC vs.
Revision 1.80 by root, Fri Nov 9 15:30:59 2007 UTC

215 int events; 215 int events;
216} ANPENDING; 216} ANPENDING;
217 217
218#if EV_MULTIPLICITY 218#if EV_MULTIPLICITY
219 219
220struct ev_loop 220 struct ev_loop
221{ 221 {
222# define VAR(name,decl) decl; 222 #define VAR(name,decl) decl;
223# include "ev_vars.h" 223 #include "ev_vars.h"
224};
225# undef VAR 224 #undef VAR
225 };
226# include "ev_wrap.h" 226 #include "ev_wrap.h"
227
228 struct ev_loop default_loop_struct;
229 static struct ev_loop *default_loop;
227 230
228#else 231#else
229 232
230# define VAR(name,decl) static decl; 233 #define VAR(name,decl) static decl;
231# include "ev_vars.h" 234 #include "ev_vars.h"
232# undef VAR 235 #undef VAR
236
237 static int default_loop;
233 238
234#endif 239#endif
235 240
236/*****************************************************************************/ 241/*****************************************************************************/
237 242
316 321
317 ++base; 322 ++base;
318 } 323 }
319} 324}
320 325
321static void 326void
322event (EV_P_ W w, int events) 327ev_feed_event (EV_P_ void *w, int revents)
323{ 328{
329 W w_ = (W)w;
330
324 if (w->pending) 331 if (w_->pending)
325 { 332 {
326 pendings [ABSPRI (w)][w->pending - 1].events |= events; 333 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents;
327 return; 334 return;
328 } 335 }
329 336
330 w->pending = ++pendingcnt [ABSPRI (w)]; 337 w_->pending = ++pendingcnt [ABSPRI (w_)];
331 array_needsize (ANPENDING, pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], (void)); 338 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], (void));
332 pendings [ABSPRI (w)][w->pending - 1].w = w; 339 pendings [ABSPRI (w_)][w_->pending - 1].w = w_;
333 pendings [ABSPRI (w)][w->pending - 1].events = events; 340 pendings [ABSPRI (w_)][w_->pending - 1].events = revents;
334} 341}
335 342
336static void 343static void
337queue_events (EV_P_ W *events, int eventcnt, int type) 344queue_events (EV_P_ W *events, int eventcnt, int type)
338{ 345{
339 int i; 346 int i;
340 347
341 for (i = 0; i < eventcnt; ++i) 348 for (i = 0; i < eventcnt; ++i)
342 event (EV_A_ events [i], type); 349 ev_feed_event (EV_A_ events [i], type);
343} 350}
344 351
345static void 352inline void
346fd_event (EV_P_ int fd, int events) 353fd_event (EV_P_ int fd, int revents)
347{ 354{
348 ANFD *anfd = anfds + fd; 355 ANFD *anfd = anfds + fd;
349 struct ev_io *w; 356 struct ev_io *w;
350 357
351 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) 358 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next)
352 { 359 {
353 int ev = w->events & events; 360 int ev = w->events & revents;
354 361
355 if (ev) 362 if (ev)
356 event (EV_A_ (W)w, ev); 363 ev_feed_event (EV_A_ (W)w, ev);
357 } 364 }
365}
366
367void
368ev_feed_fd_event (EV_P_ int fd, int revents)
369{
370 fd_event (EV_A_ fd, revents);
358} 371}
359 372
360/*****************************************************************************/ 373/*****************************************************************************/
361 374
362static void 375static void
403 struct ev_io *w; 416 struct ev_io *w;
404 417
405 while ((w = (struct ev_io *)anfds [fd].head)) 418 while ((w = (struct ev_io *)anfds [fd].head))
406 { 419 {
407 ev_io_stop (EV_A_ w); 420 ev_io_stop (EV_A_ w);
408 event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); 421 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE);
409 } 422 }
410} 423}
411 424
412static int 425static int
413fd_valid (int fd) 426fd_valid (int fd)
550#endif 563#endif
551 errno = old_errno; 564 errno = old_errno;
552 } 565 }
553} 566}
554 567
568void
569ev_feed_signal_event (EV_P_ int signum)
570{
571 WL w;
572
573#if EV_MULTIPLICITY
574 assert (("feeding signal events is only supported in the default loop", loop == default_loop));
575#endif
576
577 --signum;
578
579 if (signum < 0 || signum >= signalmax)
580 return;
581
582 signals [signum].gotsig = 0;
583
584 for (w = signals [signum].head; w; w = w->next)
585 ev_feed_event (EV_A_ (W)w, EV_SIGNAL);
586}
587
555static void 588static void
556sigcb (EV_P_ struct ev_io *iow, int revents) 589sigcb (EV_P_ struct ev_io *iow, int revents)
557{ 590{
558 WL w;
559 int signum; 591 int signum;
560 592
561#ifdef WIN32 593#ifdef WIN32
562 recv (sigpipe [0], &revents, 1, MSG_DONTWAIT); 594 recv (sigpipe [0], &revents, 1, MSG_DONTWAIT);
563#else 595#else
565#endif 597#endif
566 gotsig = 0; 598 gotsig = 0;
567 599
568 for (signum = signalmax; signum--; ) 600 for (signum = signalmax; signum--; )
569 if (signals [signum].gotsig) 601 if (signals [signum].gotsig)
570 { 602 ev_feed_signal_event (EV_A_ signum + 1);
571 signals [signum].gotsig = 0;
572
573 for (w = signals [signum].head; w; w = w->next)
574 event (EV_A_ (W)w, EV_SIGNAL);
575 }
576} 603}
577 604
578static void 605static void
579siginit (EV_P) 606siginit (EV_P)
580{ 607{
613 if (w->pid == pid || !w->pid) 640 if (w->pid == pid || !w->pid)
614 { 641 {
615 ev_priority (w) = ev_priority (sw); /* need to do it *now* */ 642 ev_priority (w) = ev_priority (sw); /* need to do it *now* */
616 w->rpid = pid; 643 w->rpid = pid;
617 w->rstatus = status; 644 w->rstatus = status;
618 event (EV_A_ (W)w, EV_CHILD); 645 ev_feed_event (EV_A_ (W)w, EV_CHILD);
619 } 646 }
620} 647}
621 648
622static void 649static void
623childcb (EV_P_ struct ev_signal *sw, int revents) 650childcb (EV_P_ struct ev_signal *sw, int revents)
625 int pid, status; 652 int pid, status;
626 653
627 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) 654 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)))
628 { 655 {
629 /* make sure we are called again until all childs have been reaped */ 656 /* make sure we are called again until all childs have been reaped */
630 event (EV_A_ (W)sw, EV_SIGNAL); 657 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
631 658
632 child_reap (EV_A_ sw, pid, pid, status); 659 child_reap (EV_A_ sw, pid, pid, status);
633 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */ 660 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */
634 } 661 }
635} 662}
820} 847}
821 848
822#endif 849#endif
823 850
824#if EV_MULTIPLICITY 851#if EV_MULTIPLICITY
825struct ev_loop default_loop_struct;
826static struct ev_loop *default_loop;
827
828struct ev_loop * 852struct ev_loop *
829#else 853#else
830static int default_loop;
831
832int 854int
833#endif 855#endif
834ev_default_loop (int methods) 856ev_default_loop (int methods)
835{ 857{
836 if (sigpipe [0] == sigpipe [1]) 858 if (sigpipe [0] == sigpipe [1])
946 downheap ((WT *)timers, timercnt, 0); 968 downheap ((WT *)timers, timercnt, 0);
947 } 969 }
948 else 970 else
949 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ 971 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
950 972
951 event (EV_A_ (W)w, EV_TIMEOUT); 973 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT);
952 } 974 }
953} 975}
954 976
955static void 977static void
956periodics_reify (EV_P) 978periodics_reify (EV_P)
976 downheap ((WT *)periodics, periodiccnt, 0); 998 downheap ((WT *)periodics, periodiccnt, 0);
977 } 999 }
978 else 1000 else
979 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ 1001 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
980 1002
981 event (EV_A_ (W)w, EV_PERIODIC); 1003 ev_feed_event (EV_A_ (W)w, EV_PERIODIC);
982 } 1004 }
983} 1005}
984 1006
985static void 1007static void
986periodics_reschedule (EV_P) 1008periodics_reschedule (EV_P)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines