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

Comparing libev/ev.c (file contents):
Revision 1.12 by root, Wed Oct 31 09:23:17 2007 UTC vs.
Revision 1.43 by root, Fri Nov 2 20:21:33 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines