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

Comparing libev/ev.c (file contents):
Revision 1.96 by root, Sun Nov 11 01:50:36 2007 UTC vs.
Revision 1.99 by root, Sun Nov 11 02:26:47 2007 UTC

35 35
36#ifndef EV_STANDALONE 36#ifndef EV_STANDALONE
37# include "config.h" 37# include "config.h"
38 38
39# if HAVE_CLOCK_GETTIME 39# if HAVE_CLOCK_GETTIME
40# ifndef EV_USE_MONOTONIC
40# define EV_USE_MONOTONIC 1 41# define EV_USE_MONOTONIC 1
42# endif
43# ifndef EV_USE_REALTIME
41# define EV_USE_REALTIME 1 44# define EV_USE_REALTIME 1
45# endif
42# endif 46# endif
43 47
44# if HAVE_SELECT && HAVE_SYS_SELECT_H && !defined (EV_USE_SELECT) 48# if HAVE_SELECT && HAVE_SYS_SELECT_H && !defined (EV_USE_SELECT)
45# define EV_USE_SELECT 1 49# define EV_USE_SELECT 1
46# endif 50# endif
157typedef struct ev_watcher_list *WL; 161typedef struct ev_watcher_list *WL;
158typedef struct ev_watcher_time *WT; 162typedef struct ev_watcher_time *WT;
159 163
160static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 164static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
161 165
166#ifdef WIN32
162#include "ev_win32.c" 167# include "ev_win32.c"
168#endif
163 169
164/*****************************************************************************/ 170/*****************************************************************************/
165 171
166static void (*syserr_cb)(const char *msg); 172static void (*syserr_cb)(const char *msg);
167 173
227#if EV_MULTIPLICITY 233#if EV_MULTIPLICITY
228 234
229 struct ev_loop 235 struct ev_loop
230 { 236 {
231 ev_tstamp ev_rt_now; 237 ev_tstamp ev_rt_now;
238 #define ev_rt_now ((loop)->ev_rt_now)
232 #define VAR(name,decl) decl; 239 #define VAR(name,decl) decl;
233 #include "ev_vars.h" 240 #include "ev_vars.h"
234 #undef VAR 241 #undef VAR
235 }; 242 };
236 #include "ev_wrap.h" 243 #include "ev_wrap.h"
528 heap [k] = w; 535 heap [k] = w;
529 ((W)heap [k])->active = k + 1; 536 ((W)heap [k])->active = k + 1;
530} 537}
531 538
532inline void 539inline void
533adjustheap (WT *heap, int N, int k, ev_tstamp at) 540adjustheap (WT *heap, int N, int k)
534{ 541{
535 ev_tstamp old_at = heap [k]->at; 542 upheap (heap, k);
536 heap [k]->at = at;
537
538 if (old_at < at)
539 downheap (heap, N, k); 543 downheap (heap, N, k);
540 else
541 upheap (heap, k);
542} 544}
543 545
544/*****************************************************************************/ 546/*****************************************************************************/
545 547
546typedef struct 548typedef struct
1346 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1348 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1347 1349
1348 if (((W)w)->active < timercnt--) 1350 if (((W)w)->active < timercnt--)
1349 { 1351 {
1350 timers [((W)w)->active - 1] = timers [timercnt]; 1352 timers [((W)w)->active - 1] = timers [timercnt];
1351 downheap ((WT *)timers, timercnt, ((W)w)->active - 1); 1353 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1352 } 1354 }
1353 1355
1354 ((WT)w)->at -= mn_now; 1356 ((WT)w)->at -= mn_now;
1355 1357
1356 ev_stop (EV_A_ (W)w); 1358 ev_stop (EV_A_ (W)w);
1360ev_timer_again (EV_P_ struct ev_timer *w) 1362ev_timer_again (EV_P_ struct ev_timer *w)
1361{ 1363{
1362 if (ev_is_active (w)) 1364 if (ev_is_active (w))
1363 { 1365 {
1364 if (w->repeat) 1366 if (w->repeat)
1367 {
1368 ((WT)w)->at = mn_now + w->repeat;
1365 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1, mn_now + w->repeat); 1369 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1);
1370 }
1366 else 1371 else
1367 ev_timer_stop (EV_A_ w); 1372 ev_timer_stop (EV_A_ w);
1368 } 1373 }
1369 else if (w->repeat) 1374 else if (w->repeat)
1370 ev_timer_start (EV_A_ w); 1375 ev_timer_start (EV_A_ w);
1404 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1409 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1405 1410
1406 if (((W)w)->active < periodiccnt--) 1411 if (((W)w)->active < periodiccnt--)
1407 { 1412 {
1408 periodics [((W)w)->active - 1] = periodics [periodiccnt]; 1413 periodics [((W)w)->active - 1] = periodics [periodiccnt];
1409 downheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); 1414 adjustheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1);
1410 } 1415 }
1411 1416
1412 ev_stop (EV_A_ (W)w); 1417 ev_stop (EV_A_ (W)w);
1413} 1418}
1414 1419

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines