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

Comparing libev/ev.c (file contents):
Revision 1.182 by root, Wed Dec 12 01:27:08 2007 UTC vs.
Revision 1.186 by root, Sat Dec 15 23:14:38 2007 UTC

202#ifndef CLOCK_REALTIME 202#ifndef CLOCK_REALTIME
203# undef EV_USE_REALTIME 203# undef EV_USE_REALTIME
204# define EV_USE_REALTIME 0 204# define EV_USE_REALTIME 0
205#endif 205#endif
206 206
207#if !EV_STAT_ENABLE
208# undef EV_USE_INOTIFY
209# define EV_USE_INOTIFY 0
210#endif
211
212#if EV_USE_INOTIFY
213# include <sys/inotify.h>
214#endif
215
207#if EV_SELECT_IS_WINSOCKET 216#if EV_SELECT_IS_WINSOCKET
208# include <winsock.h> 217# include <winsock.h>
209#endif
210
211#if !EV_STAT_ENABLE
212# define EV_USE_INOTIFY 0
213#endif
214
215#if EV_USE_INOTIFY
216# include <sys/inotify.h>
217#endif 218#endif
218 219
219/**/ 220/**/
220 221
221/* 222/*
230 231
231#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 232#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
232#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ 233#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */
233/*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds, TODO */ 234/*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds, TODO */
234 235
235#if __GNUC__ >= 3 236#if __GNUC__ >= 4
236# define expect(expr,value) __builtin_expect ((expr),(value)) 237# define expect(expr,value) __builtin_expect ((expr),(value))
237# define noinline __attribute__ ((noinline)) 238# define noinline __attribute__ ((noinline))
238#else 239#else
239# define expect(expr,value) (expr) 240# define expect(expr,value) (expr)
240# define noinline 241# define noinline
533 { 534 {
534 int fd = fdchanges [i]; 535 int fd = fdchanges [i];
535 ANFD *anfd = anfds + fd; 536 ANFD *anfd = anfds + fd;
536 ev_io *w; 537 ev_io *w;
537 538
538 int events = 0; 539 unsigned char events = 0;
539 540
540 for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) 541 for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next)
541 events |= w->events; 542 events |= (unsigned char)w->events;
542 543
543#if EV_SELECT_IS_WINSOCKET 544#if EV_SELECT_IS_WINSOCKET
544 if (events) 545 if (events)
545 { 546 {
546 unsigned long argp; 547 unsigned long argp;
547 anfd->handle = _get_osfhandle (fd); 548 anfd->handle = _get_osfhandle (fd);
548 assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0)); 549 assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0));
549 } 550 }
550#endif 551#endif
551 552
553 {
554 unsigned char o_events = anfd->events;
555 unsigned char o_reify = anfd->reify;
556
552 anfd->reify = 0; 557 anfd->reify = 0;
553
554 backend_modify (EV_A_ fd, anfd->events, events);
555 anfd->events = events; 558 anfd->events = events;
559
560 if (o_events != events || o_reify & EV_IOFDSET)
561 backend_modify (EV_A_ fd, o_events, events);
562 }
556 } 563 }
557 564
558 fdchangecnt = 0; 565 fdchangecnt = 0;
559} 566}
560 567
561void inline_size 568void inline_size
562fd_change (EV_P_ int fd) 569fd_change (EV_P_ int fd, int flags)
563{ 570{
564 if (expect_false (anfds [fd].reify)) 571 unsigned char reify = anfds [fd].reify;
565 return;
566
567 anfds [fd].reify = 1; 572 anfds [fd].reify |= flags;
568 573
574 if (expect_true (!reify))
575 {
569 ++fdchangecnt; 576 ++fdchangecnt;
570 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); 577 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2);
571 fdchanges [fdchangecnt - 1] = fd; 578 fdchanges [fdchangecnt - 1] = fd;
579 }
572} 580}
573 581
574void inline_speed 582void inline_speed
575fd_kill (EV_P_ int fd) 583fd_kill (EV_P_ int fd)
576{ 584{
627 635
628 for (fd = 0; fd < anfdmax; ++fd) 636 for (fd = 0; fd < anfdmax; ++fd)
629 if (anfds [fd].events) 637 if (anfds [fd].events)
630 { 638 {
631 anfds [fd].events = 0; 639 anfds [fd].events = 0;
632 fd_change (EV_A_ fd); 640 fd_change (EV_A_ fd, EV_IOFDSET | 1);
633 } 641 }
634} 642}
635 643
636/*****************************************************************************/ 644/*****************************************************************************/
637 645
1030#if EV_IDLE_ENABLE 1038#if EV_IDLE_ENABLE
1031 array_free (idle, [i]); 1039 array_free (idle, [i]);
1032#endif 1040#endif
1033 } 1041 }
1034 1042
1043 ev_free (anfds); anfdmax = 0;
1044
1035 /* have to use the microsoft-never-gets-it-right macro */ 1045 /* have to use the microsoft-never-gets-it-right macro */
1036 array_free (fdchange, EMPTY); 1046 array_free (fdchange, EMPTY);
1037 array_free (timer, EMPTY); 1047 array_free (timer, EMPTY);
1038#if EV_PERIODIC_ENABLE 1048#if EV_PERIODIC_ENABLE
1039 array_free (periodic, EMPTY); 1049 array_free (periodic, EMPTY);
1040#endif 1050#endif
1041 array_free (prepare, EMPTY); 1051 array_free (prepare, EMPTY);
1042 array_free (check, EMPTY); 1052 array_free (check, EMPTY);
1053 array_free (fork, EMPTY);
1043 1054
1044 backend = 0; 1055 backend = 0;
1045} 1056}
1046 1057
1047void inline_size infy_fork (EV_P); 1058void inline_size infy_fork (EV_P);
1599 1610
1600 ev_start (EV_A_ (W)w, 1); 1611 ev_start (EV_A_ (W)w, 1);
1601 array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init); 1612 array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init);
1602 wlist_add (&anfds[fd].head, (WL)w); 1613 wlist_add (&anfds[fd].head, (WL)w);
1603 1614
1604 fd_change (EV_A_ fd); 1615 fd_change (EV_A_ fd, w->events & EV_IOFDSET | 1);
1616 w->events &= ~EV_IOFDSET;
1605} 1617}
1606 1618
1607void noinline 1619void noinline
1608ev_io_stop (EV_P_ ev_io *w) 1620ev_io_stop (EV_P_ ev_io *w)
1609{ 1621{
1614 assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); 1626 assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax));
1615 1627
1616 wlist_del (&anfds[w->fd].head, (WL)w); 1628 wlist_del (&anfds[w->fd].head, (WL)w);
1617 ev_stop (EV_A_ (W)w); 1629 ev_stop (EV_A_ (W)w);
1618 1630
1619 fd_change (EV_A_ w->fd); 1631 fd_change (EV_A_ w->fd, 1);
1620} 1632}
1621 1633
1622void noinline 1634void noinline
1623ev_timer_start (EV_P_ ev_timer *w) 1635ev_timer_start (EV_P_ ev_timer *w)
1624{ 1636{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines