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

Comparing libev/ev.c (file contents):
Revision 1.79 by root, Fri Nov 9 15:15:20 2007 UTC vs.
Revision 1.84 by root, Fri Nov 9 23:04:35 2007 UTC

126#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 126#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
127#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */ 127#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */
128#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ 128#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */
129/*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */ 129/*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */
130 130
131#ifdef EV_H
132# include EV_H
133#else
131#include "ev.h" 134# include "ev.h"
135#endif
132 136
133#if __GNUC__ >= 3 137#if __GNUC__ >= 3
134# define expect(expr,value) __builtin_expect ((expr),(value)) 138# define expect(expr,value) __builtin_expect ((expr),(value))
135# define inline inline 139# define inline inline
136#else 140#else
215 int events; 219 int events;
216} ANPENDING; 220} ANPENDING;
217 221
218#if EV_MULTIPLICITY 222#if EV_MULTIPLICITY
219 223
220struct ev_loop 224 struct ev_loop
221{ 225 {
222# define VAR(name,decl) decl; 226 #define VAR(name,decl) decl;
223# include "ev_vars.h" 227 #include "ev_vars.h"
224};
225# undef VAR 228 #undef VAR
229 };
226# include "ev_wrap.h" 230 #include "ev_wrap.h"
231
232 struct ev_loop default_loop_struct;
233 static struct ev_loop *default_loop;
227 234
228#else 235#else
229 236
230# define VAR(name,decl) static decl; 237 #define VAR(name,decl) static decl;
231# include "ev_vars.h" 238 #include "ev_vars.h"
232# undef VAR 239 #undef VAR
240
241 static int default_loop;
233 242
234#endif 243#endif
235 244
236/*****************************************************************************/ 245/*****************************************************************************/
237 246
509 518
510 heap [k] = w; 519 heap [k] = w;
511 ((W)heap [k])->active = k + 1; 520 ((W)heap [k])->active = k + 1;
512} 521}
513 522
523inline void
524adjustheap (WT *heap, int N, int k, ev_tstamp at)
525{
526 ev_tstamp old_at = heap [k]->at;
527 heap [k]->at = at;
528
529 if (old_at < at)
530 downheap (heap, N, k);
531 else
532 upheap (heap, k);
533}
534
514/*****************************************************************************/ 535/*****************************************************************************/
515 536
516typedef struct 537typedef struct
517{ 538{
518 WL head; 539 WL head;
561} 582}
562 583
563void 584void
564ev_feed_signal_event (EV_P_ int signum) 585ev_feed_signal_event (EV_P_ int signum)
565{ 586{
587 WL w;
588
566#if EV_MULTIPLICITY 589#if EV_MULTIPLICITY
567 assert (("feeding signal events is only supported in the default loop", loop == default_loop)); 590 assert (("feeding signal events is only supported in the default loop", loop == default_loop));
568#endif 591#endif
569 592
570 --signum; 593 --signum;
579} 602}
580 603
581static void 604static void
582sigcb (EV_P_ struct ev_io *iow, int revents) 605sigcb (EV_P_ struct ev_io *iow, int revents)
583{ 606{
584 WL w;
585 int signum; 607 int signum;
586 608
587#ifdef WIN32 609#ifdef WIN32
588 recv (sigpipe [0], &revents, 1, MSG_DONTWAIT); 610 recv (sigpipe [0], &revents, 1, MSG_DONTWAIT);
589#else 611#else
591#endif 613#endif
592 gotsig = 0; 614 gotsig = 0;
593 615
594 for (signum = signalmax; signum--; ) 616 for (signum = signalmax; signum--; )
595 if (signals [signum].gotsig) 617 if (signals [signum].gotsig)
596 sigevent (EV_A_ signum + 1); 618 ev_feed_signal_event (EV_A_ signum + 1);
597} 619}
598 620
599static void 621static void
600siginit (EV_P) 622siginit (EV_P)
601{ 623{
741#endif 763#endif
742#if EV_USE_SELECT 764#if EV_USE_SELECT
743 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); 765 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods);
744#endif 766#endif
745 767
746 ev_watcher_init (&sigev, sigcb); 768 ev_init (&sigev, sigcb);
747 ev_set_priority (&sigev, EV_MAXPRI); 769 ev_set_priority (&sigev, EV_MAXPRI);
748 } 770 }
749} 771}
750 772
751void 773void
841} 863}
842 864
843#endif 865#endif
844 866
845#if EV_MULTIPLICITY 867#if EV_MULTIPLICITY
846struct ev_loop default_loop_struct;
847static struct ev_loop *default_loop;
848
849struct ev_loop * 868struct ev_loop *
850#else 869#else
851static int default_loop;
852
853int 870int
854#endif 871#endif
855ev_default_loop (int methods) 872ev_default_loop (int methods)
856{ 873{
857 if (sigpipe [0] == sigpipe [1]) 874 if (sigpipe [0] == sigpipe [1])
943 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 960 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
944 961
945 if (p->w) 962 if (p->w)
946 { 963 {
947 p->w->pending = 0; 964 p->w->pending = 0;
948 p->w->cb (EV_A_ p->w, p->events); 965 EV_CB_INVOKE (p->w, p->events);
949 } 966 }
950 } 967 }
951} 968}
952 969
953static void 970static void
1316ev_timer_again (EV_P_ struct ev_timer *w) 1333ev_timer_again (EV_P_ struct ev_timer *w)
1317{ 1334{
1318 if (ev_is_active (w)) 1335 if (ev_is_active (w))
1319 { 1336 {
1320 if (w->repeat) 1337 if (w->repeat)
1321 {
1322 ((WT)w)->at = mn_now + w->repeat;
1323 downheap ((WT *)timers, timercnt, ((W)w)->active - 1); 1338 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1, mn_now + w->repeat);
1324 }
1325 else 1339 else
1326 ev_timer_stop (EV_A_ w); 1340 ev_timer_stop (EV_A_ w);
1327 } 1341 }
1328 else if (w->repeat) 1342 else if (w->repeat)
1329 ev_timer_start (EV_A_ w); 1343 ev_timer_start (EV_A_ w);
1371} 1385}
1372 1386
1373void 1387void
1374ev_periodic_again (EV_P_ struct ev_periodic *w) 1388ev_periodic_again (EV_P_ struct ev_periodic *w)
1375{ 1389{
1390 /* TODO: use adjustheap and recalculation */
1376 ev_periodic_stop (EV_A_ w); 1391 ev_periodic_stop (EV_A_ w);
1377 ev_periodic_start (EV_A_ w); 1392 ev_periodic_start (EV_A_ w);
1378} 1393}
1379 1394
1380void 1395void
1559 else 1574 else
1560 { 1575 {
1561 once->cb = cb; 1576 once->cb = cb;
1562 once->arg = arg; 1577 once->arg = arg;
1563 1578
1564 ev_watcher_init (&once->io, once_cb_io); 1579 ev_init (&once->io, once_cb_io);
1565 if (fd >= 0) 1580 if (fd >= 0)
1566 { 1581 {
1567 ev_io_set (&once->io, fd, events); 1582 ev_io_set (&once->io, fd, events);
1568 ev_io_start (EV_A_ &once->io); 1583 ev_io_start (EV_A_ &once->io);
1569 } 1584 }
1570 1585
1571 ev_watcher_init (&once->to, once_cb_to); 1586 ev_init (&once->to, once_cb_to);
1572 if (timeout >= 0.) 1587 if (timeout >= 0.)
1573 { 1588 {
1574 ev_timer_set (&once->to, timeout, 0.); 1589 ev_timer_set (&once->to, timeout, 0.);
1575 ev_timer_start (EV_A_ &once->to); 1590 ev_timer_start (EV_A_ &once->to);
1576 } 1591 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines