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

Comparing libev/ev.c (file contents):
Revision 1.73 by root, Tue Nov 6 16:27:10 2007 UTC vs.
Revision 1.74 by root, Tue Nov 6 16:51:20 2007 UTC

268ev_now (EV_P) 268ev_now (EV_P)
269{ 269{
270 return rt_now; 270 return rt_now;
271} 271}
272 272
273#define array_roundsize(base,n) ((n) | 4 & ~3) 273#define array_roundsize(type,n) ((n) | 4 & ~3)
274 274
275#define array_needsize(base,cur,cnt,init) \ 275#define array_needsize(type,base,cur,cnt,init) \
276 if (expect_false ((cnt) > cur)) \ 276 if (expect_false ((cnt) > cur)) \
277 { \ 277 { \
278 int newcnt = cur; \ 278 int newcnt = cur; \
279 do \ 279 do \
280 { \ 280 { \
281 newcnt = array_roundsize (base, newcnt << 1); \ 281 newcnt = array_roundsize (type, newcnt << 1); \
282 } \ 282 } \
283 while ((cnt) > newcnt); \ 283 while ((cnt) > newcnt); \
284 \ 284 \
285 base = ev_realloc (base, sizeof (*base) * (newcnt)); \ 285 base = (type *)ev_realloc (base, sizeof (type) * (newcnt));\
286 init (base + cur, newcnt - cur); \ 286 init (base + cur, newcnt - cur); \
287 cur = newcnt; \ 287 cur = newcnt; \
288 } 288 }
289 289
290#define array_slim(stem) \ 290#define array_slim(type,stem) \
291 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ 291 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
292 { \ 292 { \
293 stem ## max = array_roundsize (stem ## cnt >> 1); \ 293 stem ## max = array_roundsize (stem ## cnt >> 1); \
294 base = ev_realloc (base, sizeof (*base) * (stem ## max)); \ 294 base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\
295 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ 295 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\
296 } 296 }
297 297
298/* microsoft's pseudo-c is quite far from C as the rest of the world and the standard knows it */ 298/* microsoft's pseudo-c is quite far from C as the rest of the world and the standard knows it */
299/* bringing us everlasting joy in form of stupid extra macros that are not required in C */ 299/* bringing us everlasting joy in form of stupid extra macros that are not required in C */
326 pendings [ABSPRI (w)][w->pending - 1].events |= events; 326 pendings [ABSPRI (w)][w->pending - 1].events |= events;
327 return; 327 return;
328 } 328 }
329 329
330 w->pending = ++pendingcnt [ABSPRI (w)]; 330 w->pending = ++pendingcnt [ABSPRI (w)];
331 array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], (void)); 331 array_needsize (ANPENDING, pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], (void));
332 pendings [ABSPRI (w)][w->pending - 1].w = w; 332 pendings [ABSPRI (w)][w->pending - 1].w = w;
333 pendings [ABSPRI (w)][w->pending - 1].events = events; 333 pendings [ABSPRI (w)][w->pending - 1].events = events;
334} 334}
335 335
336static void 336static void
391 return; 391 return;
392 392
393 anfds [fd].reify = 1; 393 anfds [fd].reify = 1;
394 394
395 ++fdchangecnt; 395 ++fdchangecnt;
396 array_needsize (fdchanges, fdchangemax, fdchangecnt, (void)); 396 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, (void));
397 fdchanges [fdchangecnt - 1] = fd; 397 fdchanges [fdchangecnt - 1] = fd;
398} 398}
399 399
400static void 400static void
401fd_kill (EV_P_ int fd) 401fd_kill (EV_P_ int fd)
1209 return; 1209 return;
1210 1210
1211 assert (("ev_io_start called with negative fd", fd >= 0)); 1211 assert (("ev_io_start called with negative fd", fd >= 0));
1212 1212
1213 ev_start (EV_A_ (W)w, 1); 1213 ev_start (EV_A_ (W)w, 1);
1214 array_needsize (anfds, anfdmax, fd + 1, anfds_init); 1214 array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init);
1215 wlist_add ((WL *)&anfds[fd].head, (WL)w); 1215 wlist_add ((WL *)&anfds[fd].head, (WL)w);
1216 1216
1217 fd_change (EV_A_ fd); 1217 fd_change (EV_A_ fd);
1218} 1218}
1219 1219
1239 ((WT)w)->at += mn_now; 1239 ((WT)w)->at += mn_now;
1240 1240
1241 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 1241 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
1242 1242
1243 ev_start (EV_A_ (W)w, ++timercnt); 1243 ev_start (EV_A_ (W)w, ++timercnt);
1244 array_needsize (timers, timermax, timercnt, (void)); 1244 array_needsize (struct ev_timer *, timers, timermax, timercnt, (void));
1245 timers [timercnt - 1] = w; 1245 timers [timercnt - 1] = w;
1246 upheap ((WT *)timers, timercnt - 1); 1246 upheap ((WT *)timers, timercnt - 1);
1247 1247
1248 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1248 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1249} 1249}
1296 /* this formula differs from the one in periodic_reify because we do not always round up */ 1296 /* this formula differs from the one in periodic_reify because we do not always round up */
1297 if (w->interval) 1297 if (w->interval)
1298 ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; 1298 ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval;
1299 1299
1300 ev_start (EV_A_ (W)w, ++periodiccnt); 1300 ev_start (EV_A_ (W)w, ++periodiccnt);
1301 array_needsize (periodics, periodicmax, periodiccnt, (void)); 1301 array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, (void));
1302 periodics [periodiccnt - 1] = w; 1302 periodics [periodiccnt - 1] = w;
1303 upheap ((WT *)periodics, periodiccnt - 1); 1303 upheap ((WT *)periodics, periodiccnt - 1);
1304 1304
1305 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1305 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1306} 1306}
1328{ 1328{
1329 if (ev_is_active (w)) 1329 if (ev_is_active (w))
1330 return; 1330 return;
1331 1331
1332 ev_start (EV_A_ (W)w, ++idlecnt); 1332 ev_start (EV_A_ (W)w, ++idlecnt);
1333 array_needsize (idles, idlemax, idlecnt, (void)); 1333 array_needsize (struct ev_idle *, idles, idlemax, idlecnt, (void));
1334 idles [idlecnt - 1] = w; 1334 idles [idlecnt - 1] = w;
1335} 1335}
1336 1336
1337void 1337void
1338ev_idle_stop (EV_P_ struct ev_idle *w) 1338ev_idle_stop (EV_P_ struct ev_idle *w)
1350{ 1350{
1351 if (ev_is_active (w)) 1351 if (ev_is_active (w))
1352 return; 1352 return;
1353 1353
1354 ev_start (EV_A_ (W)w, ++preparecnt); 1354 ev_start (EV_A_ (W)w, ++preparecnt);
1355 array_needsize (prepares, preparemax, preparecnt, (void)); 1355 array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, (void));
1356 prepares [preparecnt - 1] = w; 1356 prepares [preparecnt - 1] = w;
1357} 1357}
1358 1358
1359void 1359void
1360ev_prepare_stop (EV_P_ struct ev_prepare *w) 1360ev_prepare_stop (EV_P_ struct ev_prepare *w)
1372{ 1372{
1373 if (ev_is_active (w)) 1373 if (ev_is_active (w))
1374 return; 1374 return;
1375 1375
1376 ev_start (EV_A_ (W)w, ++checkcnt); 1376 ev_start (EV_A_ (W)w, ++checkcnt);
1377 array_needsize (checks, checkmax, checkcnt, (void)); 1377 array_needsize (struct ev_check *, checks, checkmax, checkcnt, (void));
1378 checks [checkcnt - 1] = w; 1378 checks [checkcnt - 1] = w;
1379} 1379}
1380 1380
1381void 1381void
1382ev_check_stop (EV_P_ struct ev_check *w) 1382ev_check_stop (EV_P_ struct ev_check *w)
1403 return; 1403 return;
1404 1404
1405 assert (("ev_signal_start called with illegal signal number", w->signum > 0)); 1405 assert (("ev_signal_start called with illegal signal number", w->signum > 0));
1406 1406
1407 ev_start (EV_A_ (W)w, 1); 1407 ev_start (EV_A_ (W)w, 1);
1408 array_needsize (signals, signalmax, w->signum, signals_init); 1408 array_needsize (ANSIG, signals, signalmax, w->signum, signals_init);
1409 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 1409 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
1410 1410
1411 if (!((WL)w)->next) 1411 if (!((WL)w)->next)
1412 { 1412 {
1413#if WIN32 1413#if WIN32
1496} 1496}
1497 1497
1498void 1498void
1499ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 1499ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg)
1500{ 1500{
1501 struct ev_once *once = ev_malloc (sizeof (struct ev_once)); 1501 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
1502 1502
1503 if (!once) 1503 if (!once)
1504 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); 1504 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg);
1505 else 1505 else
1506 { 1506 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines