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

Comparing libev/ev.c (file contents):
Revision 1.25 by root, Wed Oct 31 21:34:45 2007 UTC vs.
Revision 1.44 by root, Fri Nov 2 20:59:14 2007 UTC

1/* 1/*
2 * libev event processing core, watcher management
3 *
2 * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
3 * All rights reserved. 5 * All rights reserved.
4 * 6 *
5 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 8 * modification, are permitted provided that the following conditions are
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 30 */
31#if EV_USE_CONFIG_H
32# include "config.h"
33#endif
29 34
30#include <math.h> 35#include <math.h>
31#include <stdlib.h> 36#include <stdlib.h>
32#include <unistd.h> 37#include <unistd.h>
33#include <fcntl.h> 38#include <fcntl.h>
41#include <sys/types.h> 46#include <sys/types.h>
42#include <sys/wait.h> 47#include <sys/wait.h>
43#include <sys/time.h> 48#include <sys/time.h>
44#include <time.h> 49#include <time.h>
45 50
51/**/
52
46#ifndef HAVE_MONOTONIC 53#ifndef EV_USE_MONOTONIC
54# define EV_USE_MONOTONIC 1
55#endif
56
57#ifndef EV_USE_SELECT
58# define EV_USE_SELECT 1
59#endif
60
61#ifndef EV_USE_POLL
62# define EV_USE_POLL 0 /* poll is usually slower than select, and not as well tested */
63#endif
64
65#ifndef EV_USE_EPOLL
66# define EV_USE_EPOLL 0
67#endif
68
69#ifndef EV_USE_KQUEUE
70# define EV_USE_KQUEUE 0
71#endif
72
73#ifndef EV_USE_REALTIME
74# define EV_USE_REALTIME 1
75#endif
76
77/**/
78
47# ifdef CLOCK_MONOTONIC 79#ifndef CLOCK_MONOTONIC
80# undef EV_USE_MONOTONIC
48# define HAVE_MONOTONIC 1 81# define EV_USE_MONOTONIC 0
49# endif 82#endif
50#endif
51 83
52#ifndef HAVE_SELECT
53# define HAVE_SELECT 1
54#endif
55
56#ifndef HAVE_EPOLL
57# define HAVE_EPOLL 0
58#endif
59
60#ifndef HAVE_REALTIME 84#ifndef CLOCK_REALTIME
61# define HAVE_REALTIME 1 /* posix requirement, but might be slower */ 85# undef EV_USE_REALTIME
86# define EV_USE_REALTIME 0
62#endif 87#endif
88
89/**/
63 90
64#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 91#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
65#define MAX_BLOCKTIME 60. 92#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */
66#define PID_HASHSIZE 16 /* size of pid hahs table, must be power of two */ 93#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */
94/*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */
67 95
68#include "ev.h" 96#include "ev.h"
97
98#if __GNUC__ >= 3
99# define expect(expr,value) __builtin_expect ((expr),(value))
100# define inline inline
101#else
102# define expect(expr,value) (expr)
103# define inline static
104#endif
105
106#define expect_false(expr) expect ((expr) != 0, 0)
107#define expect_true(expr) expect ((expr) != 0, 1)
108
109#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
110#define ABSPRI(w) ((w)->priority - EV_MINPRI)
69 111
70typedef struct ev_watcher *W; 112typedef struct ev_watcher *W;
71typedef struct ev_watcher_list *WL; 113typedef struct ev_watcher_list *WL;
72typedef struct ev_watcher_time *WT; 114typedef struct ev_watcher_time *WT;
73 115
74static ev_tstamp now, diff; /* monotonic clock */ 116static ev_tstamp now_floor, now, diff; /* monotonic clock */
75ev_tstamp ev_now; 117ev_tstamp ev_now;
76int ev_method; 118int ev_method;
77 119
78static int have_monotonic; /* runtime */ 120static int have_monotonic; /* runtime */
79 121
84/*****************************************************************************/ 126/*****************************************************************************/
85 127
86ev_tstamp 128ev_tstamp
87ev_time (void) 129ev_time (void)
88{ 130{
89#if HAVE_REALTIME 131#if EV_USE_REALTIME
90 struct timespec ts; 132 struct timespec ts;
91 clock_gettime (CLOCK_REALTIME, &ts); 133 clock_gettime (CLOCK_REALTIME, &ts);
92 return ts.tv_sec + ts.tv_nsec * 1e-9; 134 return ts.tv_sec + ts.tv_nsec * 1e-9;
93#else 135#else
94 struct timeval tv; 136 struct timeval tv;
98} 140}
99 141
100static ev_tstamp 142static ev_tstamp
101get_clock (void) 143get_clock (void)
102{ 144{
103#if HAVE_MONOTONIC 145#if EV_USE_MONOTONIC
104 if (have_monotonic) 146 if (expect_true (have_monotonic))
105 { 147 {
106 struct timespec ts; 148 struct timespec ts;
107 clock_gettime (CLOCK_MONOTONIC, &ts); 149 clock_gettime (CLOCK_MONOTONIC, &ts);
108 return ts.tv_sec + ts.tv_nsec * 1e-9; 150 return ts.tv_sec + ts.tv_nsec * 1e-9;
109 } 151 }
110#endif 152#endif
111 153
112 return ev_time (); 154 return ev_time ();
113} 155}
114 156
157#define array_roundsize(base,n) ((n) | 4 & ~3)
158
115#define array_needsize(base,cur,cnt,init) \ 159#define array_needsize(base,cur,cnt,init) \
116 if ((cnt) > cur) \ 160 if (expect_false ((cnt) > cur)) \
117 { \ 161 { \
118 int newcnt = cur; \ 162 int newcnt = cur; \
119 do \ 163 do \
120 { \ 164 { \
121 newcnt = (newcnt << 1) | 4 & ~3; \ 165 newcnt = array_roundsize (base, newcnt << 1); \
122 } \ 166 } \
123 while ((cnt) > newcnt); \ 167 while ((cnt) > newcnt); \
124 \ 168 \
125 base = realloc (base, sizeof (*base) * (newcnt)); \ 169 base = realloc (base, sizeof (*base) * (newcnt)); \
126 init (base + cur, newcnt - cur); \ 170 init (base + cur, newcnt - cur); \
130/*****************************************************************************/ 174/*****************************************************************************/
131 175
132typedef struct 176typedef struct
133{ 177{
134 struct ev_io *head; 178 struct ev_io *head;
135 unsigned char wev, rev; /* want, received event set */ 179 unsigned char events;
180 unsigned char reify;
136} ANFD; 181} ANFD;
137 182
138static ANFD *anfds; 183static ANFD *anfds;
139static int anfdmax; 184static int anfdmax;
140 185
141static int *fdchanges;
142static int fdchangemax, fdchangecnt;
143
144static void 186static void
145anfds_init (ANFD *base, int count) 187anfds_init (ANFD *base, int count)
146{ 188{
147 while (count--) 189 while (count--)
148 { 190 {
149 base->head = 0; 191 base->head = 0;
150 base->wev = base->rev = EV_NONE; 192 base->events = EV_NONE;
193 base->reify = 0;
194
151 ++base; 195 ++base;
152 } 196 }
153} 197}
154 198
155typedef struct 199typedef struct
156{ 200{
157 W w; 201 W w;
158 int events; 202 int events;
159} ANPENDING; 203} ANPENDING;
160 204
161static ANPENDING *pendings; 205static ANPENDING *pendings [NUMPRI];
162static int pendingmax, pendingcnt; 206static int pendingmax [NUMPRI], pendingcnt [NUMPRI];
163 207
164static void 208static void
165event (W w, int events) 209event (W w, int events)
166{ 210{
167 if (w->active) 211 if (w->pending)
168 { 212 {
169 w->pending = ++pendingcnt;
170 array_needsize (pendings, pendingmax, pendingcnt, );
171 pendings [pendingcnt - 1].w = w;
172 pendings [pendingcnt - 1].events = events; 213 pendings [ABSPRI (w)][w->pending - 1].events |= events;
214 return;
173 } 215 }
216
217 w->pending = ++pendingcnt [ABSPRI (w)];
218 array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], );
219 pendings [ABSPRI (w)][w->pending - 1].w = w;
220 pendings [ABSPRI (w)][w->pending - 1].events = events;
221}
222
223static void
224queue_events (W *events, int eventcnt, int type)
225{
226 int i;
227
228 for (i = 0; i < eventcnt; ++i)
229 event (events [i], type);
174} 230}
175 231
176static void 232static void
177fd_event (int fd, int events) 233fd_event (int fd, int events)
178{ 234{
186 if (ev) 242 if (ev)
187 event ((W)w, ev); 243 event ((W)w, ev);
188 } 244 }
189} 245}
190 246
247/*****************************************************************************/
248
249static int *fdchanges;
250static int fdchangemax, fdchangecnt;
251
191static void 252static void
192queue_events (W *events, int eventcnt, int type) 253fd_reify (void)
193{ 254{
194 int i; 255 int i;
195 256
196 for (i = 0; i < eventcnt; ++i) 257 for (i = 0; i < fdchangecnt; ++i)
197 event (events [i], type); 258 {
259 int fd = fdchanges [i];
260 ANFD *anfd = anfds + fd;
261 struct ev_io *w;
262
263 int events = 0;
264
265 for (w = anfd->head; w; w = w->next)
266 events |= w->events;
267
268 anfd->reify = 0;
269
270 if (anfd->events != events)
271 {
272 method_modify (fd, anfd->events, events);
273 anfd->events = events;
274 }
275 }
276
277 fdchangecnt = 0;
278}
279
280static void
281fd_change (int fd)
282{
283 if (anfds [fd].reify || fdchangecnt < 0)
284 return;
285
286 anfds [fd].reify = 1;
287
288 ++fdchangecnt;
289 array_needsize (fdchanges, fdchangemax, fdchangecnt, );
290 fdchanges [fdchangecnt - 1] = fd;
291}
292
293static void
294fd_kill (int fd)
295{
296 struct ev_io *w;
297
298 printf ("killing fd %d\n", fd);//D
299 while ((w = anfds [fd].head))
300 {
301 ev_io_stop (w);
302 event ((W)w, EV_ERROR | EV_READ | EV_WRITE);
303 }
198} 304}
199 305
200/* called on EBADF to verify fds */ 306/* called on EBADF to verify fds */
201static void 307static void
202fd_recheck (void) 308fd_ebadf (void)
203{ 309{
204 int fd; 310 int fd;
205 311
206 for (fd = 0; fd < anfdmax; ++fd) 312 for (fd = 0; fd < anfdmax; ++fd)
207 if (anfds [fd].wev) 313 if (anfds [fd].events)
208 if (fcntl (fd, F_GETFD) == -1 && errno == EBADF) 314 if (fcntl (fd, F_GETFD) == -1 && errno == EBADF)
209 while (anfds [fd].head) 315 fd_kill (fd);
316}
317
318/* called on ENOMEM in select/poll to kill some fds and retry */
319static void
320fd_enomem (void)
321{
322 int fd = anfdmax;
323
324 while (fd--)
325 if (anfds [fd].events)
210 { 326 {
211 event ((W)anfds [fd].head, EV_ERROR); 327 close (fd);
212 evio_stop (anfds [fd].head); 328 fd_kill (fd);
329 return;
213 } 330 }
214} 331}
215 332
216/*****************************************************************************/ 333/*****************************************************************************/
217 334
218static struct ev_timer **timers; 335static struct ev_timer **timers;
265/*****************************************************************************/ 382/*****************************************************************************/
266 383
267typedef struct 384typedef struct
268{ 385{
269 struct ev_signal *head; 386 struct ev_signal *head;
270 sig_atomic_t gotsig; 387 sig_atomic_t volatile gotsig;
271} ANSIG; 388} ANSIG;
272 389
273static ANSIG *signals; 390static ANSIG *signals;
274static int signalmax; 391static int signalmax;
275 392
276static int sigpipe [2]; 393static int sigpipe [2];
277static sig_atomic_t gotsig; 394static sig_atomic_t volatile gotsig;
278static struct ev_io sigev; 395static struct ev_io sigev;
279 396
280static void 397static void
281signals_init (ANSIG *base, int count) 398signals_init (ANSIG *base, int count)
282{ 399{
283 while (count--) 400 while (count--)
284 { 401 {
285 base->head = 0; 402 base->head = 0;
286 base->gotsig = 0; 403 base->gotsig = 0;
404
287 ++base; 405 ++base;
288 } 406 }
289} 407}
290 408
291static void 409static void
294 signals [signum - 1].gotsig = 1; 412 signals [signum - 1].gotsig = 1;
295 413
296 if (!gotsig) 414 if (!gotsig)
297 { 415 {
298 gotsig = 1; 416 gotsig = 1;
299 write (sigpipe [1], &gotsig, 1); 417 write (sigpipe [1], &signum, 1);
300 } 418 }
301} 419}
302 420
303static void 421static void
304sigcb (struct ev_io *iow, int revents) 422sigcb (struct ev_io *iow, int revents)
305{ 423{
306 struct ev_signal *w; 424 struct ev_signal *w;
307 int sig; 425 int signum;
308 426
427 read (sigpipe [0], &revents, 1);
309 gotsig = 0; 428 gotsig = 0;
310 read (sigpipe [0], &revents, 1);
311 429
312 for (sig = signalmax; sig--; ) 430 for (signum = signalmax; signum--; )
313 if (signals [sig].gotsig) 431 if (signals [signum].gotsig)
314 { 432 {
315 signals [sig].gotsig = 0; 433 signals [signum].gotsig = 0;
316 434
317 for (w = signals [sig].head; w; w = w->next) 435 for (w = signals [signum].head; w; w = w->next)
318 event ((W)w, EV_SIGNAL); 436 event ((W)w, EV_SIGNAL);
319 } 437 }
320} 438}
321 439
322static void 440static void
327 445
328 /* rather than sort out wether we really need nb, set it */ 446 /* rather than sort out wether we really need nb, set it */
329 fcntl (sigpipe [0], F_SETFL, O_NONBLOCK); 447 fcntl (sigpipe [0], F_SETFL, O_NONBLOCK);
330 fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); 448 fcntl (sigpipe [1], F_SETFL, O_NONBLOCK);
331 449
332 evio_set (&sigev, sigpipe [0], EV_READ); 450 ev_io_set (&sigev, sigpipe [0], EV_READ);
333 evio_start (&sigev); 451 ev_io_start (&sigev);
334} 452}
335 453
336/*****************************************************************************/ 454/*****************************************************************************/
337 455
338static struct ev_idle **idles; 456static struct ev_idle **idles;
359 struct ev_child *w; 477 struct ev_child *w;
360 int pid, status; 478 int pid, status;
361 479
362 while ((pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)) != -1) 480 while ((pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)) != -1)
363 for (w = childs [pid & (PID_HASHSIZE - 1)]; w; w = w->next) 481 for (w = childs [pid & (PID_HASHSIZE - 1)]; w; w = w->next)
364 if (w->pid == pid || w->pid == -1) 482 if (w->pid == pid || !w->pid)
365 { 483 {
366 w->status = status; 484 w->status = status;
367 event ((W)w, EV_CHILD); 485 event ((W)w, EV_CHILD);
368 } 486 }
369} 487}
370 488
371/*****************************************************************************/ 489/*****************************************************************************/
372 490
491#if EV_USE_KQUEUE
492# include "ev_kqueue.c"
493#endif
373#if HAVE_EPOLL 494#if EV_USE_EPOLL
374# include "ev_epoll.c" 495# include "ev_epoll.c"
375#endif 496#endif
497#if EV_USE_POLL
498# include "ev_poll.c"
499#endif
376#if HAVE_SELECT 500#if EV_USE_SELECT
377# include "ev_select.c" 501# include "ev_select.c"
378#endif 502#endif
379 503
380int 504int
381ev_version_major (void) 505ev_version_major (void)
387ev_version_minor (void) 511ev_version_minor (void)
388{ 512{
389 return EV_VERSION_MINOR; 513 return EV_VERSION_MINOR;
390} 514}
391 515
516/* return true if we are running with elevated privileges and ignore env variables */
517static int
518enable_secure ()
519{
520 return getuid () != geteuid ()
521 || getgid () != getegid ();
522}
523
392int ev_init (int flags) 524int ev_init (int methods)
393{ 525{
394 if (!ev_method) 526 if (!ev_method)
395 { 527 {
396#if HAVE_MONOTONIC 528#if EV_USE_MONOTONIC
397 { 529 {
398 struct timespec ts; 530 struct timespec ts;
399 if (!clock_gettime (CLOCK_MONOTONIC, &ts)) 531 if (!clock_gettime (CLOCK_MONOTONIC, &ts))
400 have_monotonic = 1; 532 have_monotonic = 1;
401 } 533 }
402#endif 534#endif
403 535
404 ev_now = ev_time (); 536 ev_now = ev_time ();
405 now = get_clock (); 537 now = get_clock ();
538 now_floor = now;
406 diff = ev_now - now; 539 diff = ev_now - now;
407 540
408 if (pipe (sigpipe)) 541 if (pipe (sigpipe))
409 return 0; 542 return 0;
410 543
544 if (methods == EVMETHOD_AUTO)
545 if (!enable_secure () && getenv ("LIBEV_METHODS"))
546 methods = atoi (getenv ("LIBEV_METHODS"));
547 else
411 ev_method = EVMETHOD_NONE; 548 methods = EVMETHOD_ANY;
549
550 ev_method = 0;
551#if EV_USE_KQUEUE
552 if (!ev_method && (methods & EVMETHOD_KQUEUE)) kqueue_init (methods);
553#endif
412#if HAVE_EPOLL 554#if EV_USE_EPOLL
413 if (ev_method == EVMETHOD_NONE) epoll_init (flags); 555 if (!ev_method && (methods & EVMETHOD_EPOLL )) epoll_init (methods);
414#endif 556#endif
557#if EV_USE_POLL
558 if (!ev_method && (methods & EVMETHOD_POLL )) poll_init (methods);
559#endif
415#if HAVE_SELECT 560#if EV_USE_SELECT
416 if (ev_method == EVMETHOD_NONE) select_init (flags); 561 if (!ev_method && (methods & EVMETHOD_SELECT)) select_init (methods);
417#endif 562#endif
418 563
419 if (ev_method) 564 if (ev_method)
420 { 565 {
421 evw_init (&sigev, sigcb); 566 ev_watcher_init (&sigev, sigcb);
422 siginit (); 567 siginit ();
423 568
424 evsignal_init (&childev, childcb, SIGCHLD); 569 ev_signal_init (&childev, childcb, SIGCHLD);
425 evsignal_start (&childev); 570 ev_signal_start (&childev);
426 } 571 }
427 } 572 }
428 573
429 return ev_method; 574 return ev_method;
430} 575}
431 576
432/*****************************************************************************/ 577/*****************************************************************************/
433 578
434void 579void
435ev_prefork (void) 580ev_fork_prepare (void)
436{ 581{
437 /* nop */ 582 /* nop */
438} 583}
439 584
440void 585void
441ev_postfork_parent (void) 586ev_fork_parent (void)
442{ 587{
443 /* nop */ 588 /* nop */
444} 589}
445 590
446void 591void
447ev_postfork_child (void) 592ev_fork_child (void)
448{ 593{
449#if HAVE_EPOLL 594#if EV_USE_EPOLL
450 if (ev_method == EVMETHOD_EPOLL) 595 if (ev_method == EVMETHOD_EPOLL)
451 epoll_postfork_child (); 596 epoll_postfork_child ();
452#endif 597#endif
453 598
454 evio_stop (&sigev); 599 ev_io_stop (&sigev);
455 close (sigpipe [0]); 600 close (sigpipe [0]);
456 close (sigpipe [1]); 601 close (sigpipe [1]);
457 pipe (sigpipe); 602 pipe (sigpipe);
458 siginit (); 603 siginit ();
459} 604}
460 605
461/*****************************************************************************/ 606/*****************************************************************************/
462 607
463static void 608static void
464fd_reify (void)
465{
466 int i;
467
468 for (i = 0; i < fdchangecnt; ++i)
469 {
470 int fd = fdchanges [i];
471 ANFD *anfd = anfds + fd;
472 struct ev_io *w;
473
474 int wev = 0;
475
476 for (w = anfd->head; w; w = w->next)
477 wev |= w->events;
478
479 if (anfd->wev != wev)
480 {
481 method_modify (fd, anfd->wev, wev);
482 anfd->wev = wev;
483 }
484 }
485
486 fdchangecnt = 0;
487}
488
489static void
490call_pending (void) 609call_pending (void)
491{ 610{
611 int pri;
612
613 for (pri = NUMPRI; pri--; )
492 while (pendingcnt) 614 while (pendingcnt [pri])
493 { 615 {
494 ANPENDING *p = pendings + --pendingcnt; 616 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
495 617
496 if (p->w) 618 if (p->w)
497 { 619 {
498 p->w->pending = 0; 620 p->w->pending = 0;
499 p->w->cb (p->w, p->events); 621 p->w->cb (p->w, p->events);
500 } 622 }
501 } 623 }
502} 624}
503 625
504static void 626static void
505timers_reify (void) 627timers_reify (void)
506{ 628{
507 while (timercnt && timers [0]->at <= now) 629 while (timercnt && timers [0]->at <= now)
508 { 630 {
509 struct ev_timer *w = timers [0]; 631 struct ev_timer *w = timers [0];
510
511 event ((W)w, EV_TIMEOUT);
512 632
513 /* first reschedule or stop timer */ 633 /* first reschedule or stop timer */
514 if (w->repeat) 634 if (w->repeat)
515 { 635 {
636 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.));
516 w->at = now + w->repeat; 637 w->at = now + w->repeat;
517 assert (("timer timeout in the past, negative repeat?", w->at > now));
518 downheap ((WT *)timers, timercnt, 0); 638 downheap ((WT *)timers, timercnt, 0);
519 } 639 }
520 else 640 else
521 evtimer_stop (w); /* nonrepeating: stop timer */ 641 ev_timer_stop (w); /* nonrepeating: stop timer */
642
643 event ((W)w, EV_TIMEOUT);
522 } 644 }
523} 645}
524 646
525static void 647static void
526periodics_reify (void) 648periodics_reify (void)
531 653
532 /* first reschedule or stop timer */ 654 /* first reschedule or stop timer */
533 if (w->interval) 655 if (w->interval)
534 { 656 {
535 w->at += floor ((ev_now - w->at) / w->interval + 1.) * w->interval; 657 w->at += floor ((ev_now - w->at) / w->interval + 1.) * w->interval;
536 assert (("periodic timeout in the past, negative interval?", w->at > ev_now)); 658 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", w->at > ev_now));
537 downheap ((WT *)periodics, periodiccnt, 0); 659 downheap ((WT *)periodics, periodiccnt, 0);
538 } 660 }
539 else 661 else
540 evperiodic_stop (w); /* nonrepeating: stop timer */ 662 ev_periodic_stop (w); /* nonrepeating: stop timer */
541 663
542 event ((W)w, EV_TIMEOUT); 664 event ((W)w, EV_PERIODIC);
543 } 665 }
544} 666}
545 667
546static void 668static void
547periodics_reschedule (ev_tstamp diff) 669periodics_reschedule (ev_tstamp diff)
557 { 679 {
558 ev_tstamp diff = ceil ((ev_now - w->at) / w->interval) * w->interval; 680 ev_tstamp diff = ceil ((ev_now - w->at) / w->interval) * w->interval;
559 681
560 if (fabs (diff) >= 1e-4) 682 if (fabs (diff) >= 1e-4)
561 { 683 {
562 evperiodic_stop (w); 684 ev_periodic_stop (w);
563 evperiodic_start (w); 685 ev_periodic_start (w);
564 686
565 i = 0; /* restart loop, inefficient, but time jumps should be rare */ 687 i = 0; /* restart loop, inefficient, but time jumps should be rare */
566 } 688 }
567 } 689 }
568 } 690 }
569} 691}
570 692
693static int
694time_update_monotonic (void)
695{
696 now = get_clock ();
697
698 if (expect_true (now - now_floor < MIN_TIMEJUMP * .5))
699 {
700 ev_now = now + diff;
701 return 0;
702 }
703 else
704 {
705 now_floor = now;
706 ev_now = ev_time ();
707 return 1;
708 }
709}
710
571static void 711static void
572time_update (void) 712time_update (void)
573{ 713{
574 int i; 714 int i;
575 715
576 ev_now = ev_time (); 716#if EV_USE_MONOTONIC
577
578 if (have_monotonic) 717 if (expect_true (have_monotonic))
579 { 718 {
719 if (time_update_monotonic ())
720 {
580 ev_tstamp odiff = diff; 721 ev_tstamp odiff = diff;
581 722
582 for (i = 4; --i; ) /* loop a few times, before making important decisions */ 723 for (i = 4; --i; ) /* loop a few times, before making important decisions */
583 { 724 {
584 now = get_clock ();
585 diff = ev_now - now; 725 diff = ev_now - now;
586 726
587 if (fabs (odiff - diff) < MIN_TIMEJUMP) 727 if (fabs (odiff - diff) < MIN_TIMEJUMP)
588 return; /* all is well */ 728 return; /* all is well */
589 729
590 ev_now = ev_time (); 730 ev_now = ev_time ();
731 now = get_clock ();
732 now_floor = now;
591 } 733 }
592 734
593 periodics_reschedule (diff - odiff); 735 periodics_reschedule (diff - odiff);
594 /* no timer adjustment, as the monotonic clock doesn't jump */ 736 /* no timer adjustment, as the monotonic clock doesn't jump */
737 }
595 } 738 }
596 else 739 else
740#endif
597 { 741 {
742 ev_now = ev_time ();
743
598 if (now > ev_now || now < ev_now - MAX_BLOCKTIME - MIN_TIMEJUMP) 744 if (expect_false (now > ev_now || now < ev_now - MAX_BLOCKTIME - MIN_TIMEJUMP))
599 { 745 {
600 periodics_reschedule (ev_now - now); 746 periodics_reschedule (ev_now - now);
601 747
602 /* adjust timers. this is easy, as the offset is the same for all */ 748 /* adjust timers. this is easy, as the offset is the same for all */
603 for (i = 0; i < timercnt; ++i) 749 for (i = 0; i < timercnt; ++i)
611int ev_loop_done; 757int ev_loop_done;
612 758
613void ev_loop (int flags) 759void ev_loop (int flags)
614{ 760{
615 double block; 761 double block;
616 ev_loop_done = flags & EVLOOP_ONESHOT ? 1 : 0; 762 ev_loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0;
617 763
618 do 764 do
619 { 765 {
620 /* queue check watchers (and execute them) */ 766 /* queue check watchers (and execute them) */
621 if (preparecnt) 767 if (expect_false (preparecnt))
622 { 768 {
623 queue_events ((W *)prepares, preparecnt, EV_PREPARE); 769 queue_events ((W *)prepares, preparecnt, EV_PREPARE);
624 call_pending (); 770 call_pending ();
625 } 771 }
626 772
629 775
630 /* calculate blocking time */ 776 /* calculate blocking time */
631 777
632 /* we only need this for !monotonic clockor timers, but as we basically 778 /* we only need this for !monotonic clockor timers, but as we basically
633 always have timers, we just calculate it always */ 779 always have timers, we just calculate it always */
780#if EV_USE_MONOTONIC
781 if (expect_true (have_monotonic))
782 time_update_monotonic ();
783 else
784#endif
785 {
634 ev_now = ev_time (); 786 ev_now = ev_time ();
787 now = ev_now;
788 }
635 789
636 if (flags & EVLOOP_NONBLOCK || idlecnt) 790 if (flags & EVLOOP_NONBLOCK || idlecnt)
637 block = 0.; 791 block = 0.;
638 else 792 else
639 { 793 {
640 block = MAX_BLOCKTIME; 794 block = MAX_BLOCKTIME;
641 795
642 if (timercnt) 796 if (timercnt)
643 { 797 {
644 ev_tstamp to = timers [0]->at - (have_monotonic ? get_clock () : ev_now) + method_fudge; 798 ev_tstamp to = timers [0]->at - now + method_fudge;
645 if (block > to) block = to; 799 if (block > to) block = to;
646 } 800 }
647 801
648 if (periodiccnt) 802 if (periodiccnt)
649 { 803 {
702 head = &(*head)->next; 856 head = &(*head)->next;
703 } 857 }
704} 858}
705 859
706static void 860static void
707ev_clear (W w) 861ev_clear_pending (W w)
708{ 862{
709 if (w->pending) 863 if (w->pending)
710 { 864 {
711 pendings [w->pending - 1].w = 0; 865 pendings [ABSPRI (w)][w->pending - 1].w = 0;
712 w->pending = 0; 866 w->pending = 0;
713 } 867 }
714} 868}
715 869
716static void 870static void
717ev_start (W w, int active) 871ev_start (W w, int active)
718{ 872{
873 if (w->priority < EV_MINPRI) w->priority = EV_MINPRI;
874 if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI;
875
719 w->active = active; 876 w->active = active;
720} 877}
721 878
722static void 879static void
723ev_stop (W w) 880ev_stop (W w)
726} 883}
727 884
728/*****************************************************************************/ 885/*****************************************************************************/
729 886
730void 887void
731evio_start (struct ev_io *w) 888ev_io_start (struct ev_io *w)
732{ 889{
890 int fd = w->fd;
891
733 if (ev_is_active (w)) 892 if (ev_is_active (w))
734 return; 893 return;
735 894
736 int fd = w->fd; 895 assert (("ev_io_start called with negative fd", fd >= 0));
737 896
738 ev_start ((W)w, 1); 897 ev_start ((W)w, 1);
739 array_needsize (anfds, anfdmax, fd + 1, anfds_init); 898 array_needsize (anfds, anfdmax, fd + 1, anfds_init);
740 wlist_add ((WL *)&anfds[fd].head, (WL)w); 899 wlist_add ((WL *)&anfds[fd].head, (WL)w);
741 900
742 ++fdchangecnt; 901 fd_change (fd);
743 array_needsize (fdchanges, fdchangemax, fdchangecnt, );
744 fdchanges [fdchangecnt - 1] = fd;
745
746 if (w->fd == 9)
747 printf ("start %p:%x\n", w, w->events);//D
748} 902}
749 903
750void 904void
751evio_stop (struct ev_io *w) 905ev_io_stop (struct ev_io *w)
752{ 906{
753 if (w->fd == 9)
754 printf ("stop %p:%x\n", w, w->events);//D
755 ev_clear ((W)w); 907 ev_clear_pending ((W)w);
756 if (!ev_is_active (w)) 908 if (!ev_is_active (w))
757 return; 909 return;
758 910
759 wlist_del ((WL *)&anfds[w->fd].head, (WL)w); 911 wlist_del ((WL *)&anfds[w->fd].head, (WL)w);
760 ev_stop ((W)w); 912 ev_stop ((W)w);
761 913
762 ++fdchangecnt; 914 fd_change (w->fd);
763 array_needsize (fdchanges, fdchangemax, fdchangecnt, );
764 fdchanges [fdchangecnt - 1] = w->fd;
765} 915}
766 916
767void 917void
768evtimer_start (struct ev_timer *w) 918ev_timer_start (struct ev_timer *w)
769{ 919{
770 if (ev_is_active (w)) 920 if (ev_is_active (w))
771 return; 921 return;
772 922
773 w->at += now; 923 w->at += now;
774 924
775 assert (("timer repeat value less than zero not allowed", w->repeat >= 0.)); 925 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
776 926
777 ev_start ((W)w, ++timercnt); 927 ev_start ((W)w, ++timercnt);
778 array_needsize (timers, timermax, timercnt, ); 928 array_needsize (timers, timermax, timercnt, );
779 timers [timercnt - 1] = w; 929 timers [timercnt - 1] = w;
780 upheap ((WT *)timers, timercnt - 1); 930 upheap ((WT *)timers, timercnt - 1);
781} 931}
782 932
783void 933void
784evtimer_stop (struct ev_timer *w) 934ev_timer_stop (struct ev_timer *w)
785{ 935{
786 ev_clear ((W)w); 936 ev_clear_pending ((W)w);
787 if (!ev_is_active (w)) 937 if (!ev_is_active (w))
788 return; 938 return;
789 939
790 if (w->active < timercnt--) 940 if (w->active < timercnt--)
791 { 941 {
797 947
798 ev_stop ((W)w); 948 ev_stop ((W)w);
799} 949}
800 950
801void 951void
802evtimer_again (struct ev_timer *w) 952ev_timer_again (struct ev_timer *w)
803{ 953{
804 if (ev_is_active (w)) 954 if (ev_is_active (w))
805 { 955 {
806 if (w->repeat) 956 if (w->repeat)
807 { 957 {
808 w->at = now + w->repeat; 958 w->at = now + w->repeat;
809 downheap ((WT *)timers, timercnt, w->active - 1); 959 downheap ((WT *)timers, timercnt, w->active - 1);
810 } 960 }
811 else 961 else
812 evtimer_stop (w); 962 ev_timer_stop (w);
813 } 963 }
814 else if (w->repeat) 964 else if (w->repeat)
815 evtimer_start (w); 965 ev_timer_start (w);
816} 966}
817 967
818void 968void
819evperiodic_start (struct ev_periodic *w) 969ev_periodic_start (struct ev_periodic *w)
820{ 970{
821 if (ev_is_active (w)) 971 if (ev_is_active (w))
822 return; 972 return;
823 973
824 assert (("periodic interval value less than zero not allowed", w->interval >= 0.)); 974 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.));
825 975
826 /* this formula differs from the one in periodic_reify because we do not always round up */ 976 /* this formula differs from the one in periodic_reify because we do not always round up */
827 if (w->interval) 977 if (w->interval)
828 w->at += ceil ((ev_now - w->at) / w->interval) * w->interval; 978 w->at += ceil ((ev_now - w->at) / w->interval) * w->interval;
829 979
832 periodics [periodiccnt - 1] = w; 982 periodics [periodiccnt - 1] = w;
833 upheap ((WT *)periodics, periodiccnt - 1); 983 upheap ((WT *)periodics, periodiccnt - 1);
834} 984}
835 985
836void 986void
837evperiodic_stop (struct ev_periodic *w) 987ev_periodic_stop (struct ev_periodic *w)
838{ 988{
839 ev_clear ((W)w); 989 ev_clear_pending ((W)w);
840 if (!ev_is_active (w)) 990 if (!ev_is_active (w))
841 return; 991 return;
842 992
843 if (w->active < periodiccnt--) 993 if (w->active < periodiccnt--)
844 { 994 {
848 998
849 ev_stop ((W)w); 999 ev_stop ((W)w);
850} 1000}
851 1001
852void 1002void
853evsignal_start (struct ev_signal *w) 1003ev_signal_start (struct ev_signal *w)
854{ 1004{
855 if (ev_is_active (w)) 1005 if (ev_is_active (w))
856 return; 1006 return;
1007
1008 assert (("ev_signal_start called with illegal signal number", w->signum > 0));
857 1009
858 ev_start ((W)w, 1); 1010 ev_start ((W)w, 1);
859 array_needsize (signals, signalmax, w->signum, signals_init); 1011 array_needsize (signals, signalmax, w->signum, signals_init);
860 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 1012 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
861 1013
868 sigaction (w->signum, &sa, 0); 1020 sigaction (w->signum, &sa, 0);
869 } 1021 }
870} 1022}
871 1023
872void 1024void
873evsignal_stop (struct ev_signal *w) 1025ev_signal_stop (struct ev_signal *w)
874{ 1026{
875 ev_clear ((W)w); 1027 ev_clear_pending ((W)w);
876 if (!ev_is_active (w)) 1028 if (!ev_is_active (w))
877 return; 1029 return;
878 1030
879 wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); 1031 wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w);
880 ev_stop ((W)w); 1032 ev_stop ((W)w);
881 1033
882 if (!signals [w->signum - 1].head) 1034 if (!signals [w->signum - 1].head)
883 signal (w->signum, SIG_DFL); 1035 signal (w->signum, SIG_DFL);
884} 1036}
885 1037
1038void
886void evidle_start (struct ev_idle *w) 1039ev_idle_start (struct ev_idle *w)
887{ 1040{
888 if (ev_is_active (w)) 1041 if (ev_is_active (w))
889 return; 1042 return;
890 1043
891 ev_start ((W)w, ++idlecnt); 1044 ev_start ((W)w, ++idlecnt);
892 array_needsize (idles, idlemax, idlecnt, ); 1045 array_needsize (idles, idlemax, idlecnt, );
893 idles [idlecnt - 1] = w; 1046 idles [idlecnt - 1] = w;
894} 1047}
895 1048
1049void
896void evidle_stop (struct ev_idle *w) 1050ev_idle_stop (struct ev_idle *w)
897{ 1051{
898 ev_clear ((W)w); 1052 ev_clear_pending ((W)w);
899 if (ev_is_active (w)) 1053 if (ev_is_active (w))
900 return; 1054 return;
901 1055
902 idles [w->active - 1] = idles [--idlecnt]; 1056 idles [w->active - 1] = idles [--idlecnt];
903 ev_stop ((W)w); 1057 ev_stop ((W)w);
904} 1058}
905 1059
1060void
906void evprepare_start (struct ev_prepare *w) 1061ev_prepare_start (struct ev_prepare *w)
907{ 1062{
908 if (ev_is_active (w)) 1063 if (ev_is_active (w))
909 return; 1064 return;
910 1065
911 ev_start ((W)w, ++preparecnt); 1066 ev_start ((W)w, ++preparecnt);
912 array_needsize (prepares, preparemax, preparecnt, ); 1067 array_needsize (prepares, preparemax, preparecnt, );
913 prepares [preparecnt - 1] = w; 1068 prepares [preparecnt - 1] = w;
914} 1069}
915 1070
1071void
916void evprepare_stop (struct ev_prepare *w) 1072ev_prepare_stop (struct ev_prepare *w)
917{ 1073{
918 ev_clear ((W)w); 1074 ev_clear_pending ((W)w);
919 if (ev_is_active (w)) 1075 if (ev_is_active (w))
920 return; 1076 return;
921 1077
922 prepares [w->active - 1] = prepares [--preparecnt]; 1078 prepares [w->active - 1] = prepares [--preparecnt];
923 ev_stop ((W)w); 1079 ev_stop ((W)w);
924} 1080}
925 1081
1082void
926void evcheck_start (struct ev_check *w) 1083ev_check_start (struct ev_check *w)
927{ 1084{
928 if (ev_is_active (w)) 1085 if (ev_is_active (w))
929 return; 1086 return;
930 1087
931 ev_start ((W)w, ++checkcnt); 1088 ev_start ((W)w, ++checkcnt);
932 array_needsize (checks, checkmax, checkcnt, ); 1089 array_needsize (checks, checkmax, checkcnt, );
933 checks [checkcnt - 1] = w; 1090 checks [checkcnt - 1] = w;
934} 1091}
935 1092
1093void
936void evcheck_stop (struct ev_check *w) 1094ev_check_stop (struct ev_check *w)
937{ 1095{
938 ev_clear ((W)w); 1096 ev_clear_pending ((W)w);
939 if (ev_is_active (w)) 1097 if (ev_is_active (w))
940 return; 1098 return;
941 1099
942 checks [w->active - 1] = checks [--checkcnt]; 1100 checks [w->active - 1] = checks [--checkcnt];
943 ev_stop ((W)w); 1101 ev_stop ((W)w);
944} 1102}
945 1103
1104void
946void evchild_start (struct ev_child *w) 1105ev_child_start (struct ev_child *w)
947{ 1106{
948 if (ev_is_active (w)) 1107 if (ev_is_active (w))
949 return; 1108 return;
950 1109
951 ev_start ((W)w, 1); 1110 ev_start ((W)w, 1);
952 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1111 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
953} 1112}
954 1113
1114void
955void evchild_stop (struct ev_child *w) 1115ev_child_stop (struct ev_child *w)
956{ 1116{
957 ev_clear ((W)w); 1117 ev_clear_pending ((W)w);
958 if (ev_is_active (w)) 1118 if (ev_is_active (w))
959 return; 1119 return;
960 1120
961 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1121 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
962 ev_stop ((W)w); 1122 ev_stop ((W)w);
976once_cb (struct ev_once *once, int revents) 1136once_cb (struct ev_once *once, int revents)
977{ 1137{
978 void (*cb)(int revents, void *arg) = once->cb; 1138 void (*cb)(int revents, void *arg) = once->cb;
979 void *arg = once->arg; 1139 void *arg = once->arg;
980 1140
981 evio_stop (&once->io); 1141 ev_io_stop (&once->io);
982 evtimer_stop (&once->to); 1142 ev_timer_stop (&once->to);
983 free (once); 1143 free (once);
984 1144
985 cb (revents, arg); 1145 cb (revents, arg);
986} 1146}
987 1147
1001ev_once (int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 1161ev_once (int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg)
1002{ 1162{
1003 struct ev_once *once = malloc (sizeof (struct ev_once)); 1163 struct ev_once *once = malloc (sizeof (struct ev_once));
1004 1164
1005 if (!once) 1165 if (!once)
1006 cb (EV_ERROR, arg); 1166 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg);
1007 else 1167 else
1008 { 1168 {
1009 once->cb = cb; 1169 once->cb = cb;
1010 once->arg = arg; 1170 once->arg = arg;
1011 1171
1012 evw_init (&once->io, once_cb_io); 1172 ev_watcher_init (&once->io, once_cb_io);
1013
1014 if (fd >= 0) 1173 if (fd >= 0)
1015 { 1174 {
1016 evio_set (&once->io, fd, events); 1175 ev_io_set (&once->io, fd, events);
1017 evio_start (&once->io); 1176 ev_io_start (&once->io);
1018 } 1177 }
1019 1178
1020 evw_init (&once->to, once_cb_to); 1179 ev_watcher_init (&once->to, once_cb_to);
1021
1022 if (timeout >= 0.) 1180 if (timeout >= 0.)
1023 { 1181 {
1024 evtimer_set (&once->to, timeout, 0.); 1182 ev_timer_set (&once->to, timeout, 0.);
1025 evtimer_start (&once->to); 1183 ev_timer_start (&once->to);
1026 } 1184 }
1027 } 1185 }
1028} 1186}
1029 1187
1030/*****************************************************************************/ 1188/*****************************************************************************/
1041 1199
1042static void 1200static void
1043ocb (struct ev_timer *w, int revents) 1201ocb (struct ev_timer *w, int revents)
1044{ 1202{
1045 //fprintf (stderr, "timer %f,%f (%x) (%f) d%p\n", w->at, w->repeat, revents, w->at - ev_time (), w->data); 1203 //fprintf (stderr, "timer %f,%f (%x) (%f) d%p\n", w->at, w->repeat, revents, w->at - ev_time (), w->data);
1046 evtimer_stop (w); 1204 ev_timer_stop (w);
1047 evtimer_start (w); 1205 ev_timer_start (w);
1048} 1206}
1049 1207
1050static void 1208static void
1051scb (struct ev_signal *w, int revents) 1209scb (struct ev_signal *w, int revents)
1052{ 1210{
1053 fprintf (stderr, "signal %x,%d\n", revents, w->signum); 1211 fprintf (stderr, "signal %x,%d\n", revents, w->signum);
1054 evio_stop (&wio); 1212 ev_io_stop (&wio);
1055 evio_start (&wio); 1213 ev_io_start (&wio);
1056} 1214}
1057 1215
1058static void 1216static void
1059gcb (struct ev_signal *w, int revents) 1217gcb (struct ev_signal *w, int revents)
1060{ 1218{
1064 1222
1065int main (void) 1223int main (void)
1066{ 1224{
1067 ev_init (0); 1225 ev_init (0);
1068 1226
1069 evio_init (&wio, sin_cb, 0, EV_READ); 1227 ev_io_init (&wio, sin_cb, 0, EV_READ);
1070 evio_start (&wio); 1228 ev_io_start (&wio);
1071 1229
1072 struct ev_timer t[10000]; 1230 struct ev_timer t[10000];
1073 1231
1074#if 0 1232#if 0
1075 int i; 1233 int i;
1076 for (i = 0; i < 10000; ++i) 1234 for (i = 0; i < 10000; ++i)
1077 { 1235 {
1078 struct ev_timer *w = t + i; 1236 struct ev_timer *w = t + i;
1079 evw_init (w, ocb, i); 1237 ev_watcher_init (w, ocb, i);
1080 evtimer_init_abs (w, ocb, drand48 (), 0.99775533); 1238 ev_timer_init_abs (w, ocb, drand48 (), 0.99775533);
1081 evtimer_start (w); 1239 ev_timer_start (w);
1082 if (drand48 () < 0.5) 1240 if (drand48 () < 0.5)
1083 evtimer_stop (w); 1241 ev_timer_stop (w);
1084 } 1242 }
1085#endif 1243#endif
1086 1244
1087 struct ev_timer t1; 1245 struct ev_timer t1;
1088 evtimer_init (&t1, ocb, 5, 10); 1246 ev_timer_init (&t1, ocb, 5, 10);
1089 evtimer_start (&t1); 1247 ev_timer_start (&t1);
1090 1248
1091 struct ev_signal sig; 1249 struct ev_signal sig;
1092 evsignal_init (&sig, scb, SIGQUIT); 1250 ev_signal_init (&sig, scb, SIGQUIT);
1093 evsignal_start (&sig); 1251 ev_signal_start (&sig);
1094 1252
1095 struct ev_check cw; 1253 struct ev_check cw;
1096 evcheck_init (&cw, gcb); 1254 ev_check_init (&cw, gcb);
1097 evcheck_start (&cw); 1255 ev_check_start (&cw);
1098 1256
1099 struct ev_idle iw; 1257 struct ev_idle iw;
1100 evidle_init (&iw, gcb); 1258 ev_idle_init (&iw, gcb);
1101 evidle_start (&iw); 1259 ev_idle_start (&iw);
1102 1260
1103 ev_loop (0); 1261 ev_loop (0);
1104 1262
1105 return 0; 1263 return 0;
1106} 1264}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines