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

Comparing libev/ev.c (file contents):
Revision 1.377 by root, Wed Jun 8 13:11:55 2011 UTC vs.
Revision 1.378 by root, Mon Jun 13 09:52:36 2011 UTC

1368inline_size void 1368inline_size void
1369evpipe_write (EV_P_ EV_ATOMIC_T *flag) 1369evpipe_write (EV_P_ EV_ATOMIC_T *flag)
1370{ 1370{
1371 if (!*flag) 1371 if (!*flag)
1372 { 1372 {
1373 int old_errno = errno; /* save errno because write might clobber it */
1374 char dummy;
1375
1376 *flag = 1; 1373 *flag = 1;
1377 1374
1375 pipe_write_skipped = 1;
1376
1377 if (pipe_write_wanted)
1378 {
1379 int old_errno = errno; /* save errno because write will clobber it */
1380 char dummy;
1381
1382 pipe_write_skipped = 0;
1383
1378#if EV_USE_EVENTFD 1384#if EV_USE_EVENTFD
1379 if (evfd >= 0) 1385 if (evfd >= 0)
1380 { 1386 {
1381 uint64_t counter = 1; 1387 uint64_t counter = 1;
1382 write (evfd, &counter, sizeof (uint64_t)); 1388 write (evfd, &counter, sizeof (uint64_t));
1389 }
1390 else
1391#endif
1392 {
1393 /* win32 people keep sending patches that change this write() to send() */
1394 /* and then run away. but send() is wrong, it wants a socket handle on win32 */
1395 /* so when you think this write should be a send instead, please find out */
1396 /* where your send() is from - it's definitely not the microsoft send, and */
1397 /* tell me. thank you. */
1398 write (evpipe [1], &dummy, 1);
1399 }
1400
1401 errno = old_errno;
1383 } 1402 }
1384 else
1385#endif
1386 /* win32 people keep sending patches that change this write() to send() */
1387 /* and then run away. but send() is wrong, it wants a socket handle on win32 */
1388 /* so when you think this write should be a send instead, please find out */
1389 /* where your send() is from - it's definitely not the microsoft send, and */
1390 /* tell me. thank you. */
1391 write (evpipe [1], &dummy, 1);
1392
1393 errno = old_errno;
1394 } 1403 }
1395} 1404}
1396 1405
1397/* called whenever the libev signal pipe */ 1406/* called whenever the libev signal pipe */
1398/* got some events (signal, async) */ 1407/* got some events (signal, async) */
1399static void 1408static void
1400pipecb (EV_P_ ev_io *iow, int revents) 1409pipecb (EV_P_ ev_io *iow, int revents)
1401{ 1410{
1402 int i; 1411 int i;
1403 1412
1413 if (revents & EV_READ)
1414 {
1404#if EV_USE_EVENTFD 1415#if EV_USE_EVENTFD
1405 if (evfd >= 0) 1416 if (evfd >= 0)
1406 { 1417 {
1407 uint64_t counter; 1418 uint64_t counter;
1408 read (evfd, &counter, sizeof (uint64_t)); 1419 read (evfd, &counter, sizeof (uint64_t));
1409 } 1420 }
1410 else 1421 else
1411#endif 1422#endif
1412 { 1423 {
1413 char dummy; 1424 char dummy;
1414 /* see discussion in evpipe_write when you think this read should be recv in win32 */ 1425 /* see discussion in evpipe_write when you think this read should be recv in win32 */
1415 read (evpipe [0], &dummy, 1); 1426 read (evpipe [0], &dummy, 1);
1427 }
1416 } 1428 }
1429
1430 pipe_write_skipped = 0;
1417 1431
1418#if EV_SIGNAL_ENABLE 1432#if EV_SIGNAL_ENABLE
1419 if (sig_pending) 1433 if (sig_pending)
1420 { 1434 {
1421 sig_pending = 0; 1435 sig_pending = 0;
1450 EV_P = signals [signum - 1].loop; 1464 EV_P = signals [signum - 1].loop;
1451 1465
1452 if (!EV_A) 1466 if (!EV_A)
1453 return; 1467 return;
1454#endif 1468#endif
1469
1470 evpipe_init (EV_A);
1455 1471
1456 signals [signum - 1].pending = 1; 1472 signals [signum - 1].pending = 1;
1457 evpipe_write (EV_A_ &sig_pending); 1473 evpipe_write (EV_A_ &sig_pending);
1458} 1474}
1459 1475
1757 if (!(flags & EVFLAG_NOENV) 1773 if (!(flags & EVFLAG_NOENV)
1758 && !enable_secure () 1774 && !enable_secure ()
1759 && getenv ("LIBEV_FLAGS")) 1775 && getenv ("LIBEV_FLAGS"))
1760 flags = atoi (getenv ("LIBEV_FLAGS")); 1776 flags = atoi (getenv ("LIBEV_FLAGS"));
1761 1777
1762 ev_rt_now = ev_time (); 1778 ev_rt_now = ev_time ();
1763 mn_now = get_clock (); 1779 mn_now = get_clock ();
1764 now_floor = mn_now; 1780 now_floor = mn_now;
1765 rtmn_diff = ev_rt_now - mn_now; 1781 rtmn_diff = ev_rt_now - mn_now;
1766#if EV_FEATURE_API 1782#if EV_FEATURE_API
1767 invoke_cb = ev_invoke_pending; 1783 invoke_cb = ev_invoke_pending;
1768#endif 1784#endif
1769 1785
1770 io_blocktime = 0.; 1786 io_blocktime = 0.;
1771 timeout_blocktime = 0.; 1787 timeout_blocktime = 0.;
1772 backend = 0; 1788 backend = 0;
1773 backend_fd = -1; 1789 backend_fd = -1;
1774 sig_pending = 0; 1790 sig_pending = 0;
1775#if EV_ASYNC_ENABLE 1791#if EV_ASYNC_ENABLE
1776 async_pending = 0; 1792 async_pending = 0;
1777#endif 1793#endif
1794 pipe_write_skipped = 0;
1795 pipe_write_wanted = 0;
1778#if EV_USE_INOTIFY 1796#if EV_USE_INOTIFY
1779 fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2; 1797 fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2;
1780#endif 1798#endif
1781#if EV_USE_SIGNALFD 1799#if EV_USE_SIGNALFD
1782 sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1; 1800 sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1;
1783#endif 1801#endif
1784 1802
1785 if (!(flags & EVBACKEND_MASK)) 1803 if (!(flags & EVBACKEND_MASK))
1786 flags |= ev_recommended_backends (); 1804 flags |= ev_recommended_backends ();
1787 1805
1952 infy_fork (EV_A); 1970 infy_fork (EV_A);
1953#endif 1971#endif
1954 1972
1955 if (ev_is_active (&pipe_w)) 1973 if (ev_is_active (&pipe_w))
1956 { 1974 {
1957 /* this "locks" the handlers against writing to the pipe */ 1975 /* pipe_write_wanted must be false now, so modifying fd vars should be safe */
1958 /* while we modify the fd vars */
1959 sig_pending = 1;
1960#if EV_ASYNC_ENABLE
1961 async_pending = 1;
1962#endif
1963 1976
1964 ev_ref (EV_A); 1977 ev_ref (EV_A);
1965 ev_io_stop (EV_A_ &pipe_w); 1978 ev_io_stop (EV_A_ &pipe_w);
1966 1979
1967#if EV_USE_EVENTFD 1980#if EV_USE_EVENTFD
2499 ev_tstamp prev_mn_now = mn_now; 2512 ev_tstamp prev_mn_now = mn_now;
2500 2513
2501 /* update time to cancel out callback processing overhead */ 2514 /* update time to cancel out callback processing overhead */
2502 time_update (EV_A_ 1e100); 2515 time_update (EV_A_ 1e100);
2503 2516
2517 /* from now on, we want a pipe-wake-up */
2518 pipe_write_wanted = 1;
2519
2504 if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt))) 2520 if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped)))
2505 { 2521 {
2506 waittime = MAX_BLOCKTIME; 2522 waittime = MAX_BLOCKTIME;
2507 2523
2508 if (timercnt) 2524 if (timercnt)
2509 { 2525 {
2548 ++loop_count; 2564 ++loop_count;
2549#endif 2565#endif
2550 assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */ 2566 assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */
2551 backend_poll (EV_A_ waittime); 2567 backend_poll (EV_A_ waittime);
2552 assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ 2568 assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */
2569
2570 pipe_write_wanted = 0;
2571
2572 if (pipe_write_skipped)
2573 {
2574 assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w)));
2575 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM);
2576 }
2577
2553 2578
2554 /* update ev_rt_now, do magic */ 2579 /* update ev_rt_now, do magic */
2555 time_update (EV_A_ waittime + sleeptime); 2580 time_update (EV_A_ waittime + sleeptime);
2556 } 2581 }
2557 2582

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines