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

Comparing libev/ev.c (file contents):
Revision 1.426 by root, Sun May 6 13:42:10 2012 UTC vs.
Revision 1.435 by root, Sat May 26 08:52:09 2012 UTC

201# include <sys/wait.h> 201# include <sys/wait.h>
202# include <unistd.h> 202# include <unistd.h>
203#else 203#else
204# include <io.h> 204# include <io.h>
205# define WIN32_LEAN_AND_MEAN 205# define WIN32_LEAN_AND_MEAN
206# include <winsock2.h>
206# include <windows.h> 207# include <windows.h>
207# ifndef EV_SELECT_IS_WINSOCKET 208# ifndef EV_SELECT_IS_WINSOCKET
208# define EV_SELECT_IS_WINSOCKET 1 209# define EV_SELECT_IS_WINSOCKET 1
209# endif 210# endif
210# undef EV_AVOID_STDIO 211# undef EV_AVOID_STDIO
408/* some very old inotify.h headers don't have IN_DONT_FOLLOW */ 409/* some very old inotify.h headers don't have IN_DONT_FOLLOW */
409# ifndef IN_DONT_FOLLOW 410# ifndef IN_DONT_FOLLOW
410# undef EV_USE_INOTIFY 411# undef EV_USE_INOTIFY
411# define EV_USE_INOTIFY 0 412# define EV_USE_INOTIFY 0
412# endif 413# endif
413#endif
414
415#if EV_SELECT_IS_WINSOCKET
416# include <winsock.h>
417#endif 414#endif
418 415
419#if EV_USE_EVENTFD 416#if EV_USE_EVENTFD
420/* our minimum requirement is glibc 2.7 which has the stub, but not the header */ 417/* our minimum requirement is glibc 2.7 which has the stub, but not the header */
421# include <stdint.h> 418# include <stdint.h>
1108#endif 1105#endif
1109 1106
1110static void (*syserr_cb)(const char *msg) EV_THROW; 1107static void (*syserr_cb)(const char *msg) EV_THROW;
1111 1108
1112void ecb_cold 1109void ecb_cold
1113ev_set_syserr_cb (void (*cb)(const char *msg)) EV_THROW 1110ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW
1114{ 1111{
1115 syserr_cb = cb; 1112 syserr_cb = cb;
1116} 1113}
1117 1114
1118static void noinline ecb_cold 1115static void noinline ecb_cold
1136 abort (); 1133 abort ();
1137 } 1134 }
1138} 1135}
1139 1136
1140static void * 1137static void *
1141ev_realloc_emul (void *ptr, long size) 1138ev_realloc_emul (void *ptr, long size) EV_THROW
1142{ 1139{
1143#if __GLIBC__ 1140#if __GLIBC__
1144 return realloc (ptr, size); 1141 return realloc (ptr, size);
1145#else 1142#else
1146 /* some systems, notably openbsd and darwin, fail to properly 1143 /* some systems, notably openbsd and darwin, fail to properly
1157} 1154}
1158 1155
1159static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; 1156static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul;
1160 1157
1161void ecb_cold 1158void ecb_cold
1162ev_set_allocator (void *(*cb)(void *ptr, long size)) EV_THROW 1159ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW
1163{ 1160{
1164 alloc = cb; 1161 alloc = cb;
1165} 1162}
1166 1163
1167inline_speed void * 1164inline_speed void *
1876 write (evfd, &counter, sizeof (uint64_t)); 1873 write (evfd, &counter, sizeof (uint64_t));
1877 } 1874 }
1878 else 1875 else
1879#endif 1876#endif
1880 { 1877 {
1881 /* win32 people keep sending patches that change this write() to send() */ 1878#ifdef _WIN32
1882 /* and then run away. but send() is wrong, it wants a socket handle on win32 */ 1879 WSABUF buf;
1883 /* so when you think this write should be a send instead, please find out */ 1880 DWORD sent;
1884 /* where your send() is from - it's definitely not the microsoft send, and */ 1881 buf.buf = &buf;
1885 /* tell me. thank you. */ 1882 buf.len = 1;
1886 /* it might be that your problem is that your environment needs EV_USE_WSASOCKET */ 1883 WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0);
1887 /* check the ev documentation on how to use this flag */ 1884#else
1888 write (evpipe [1], &(evpipe [1]), 1); 1885 write (evpipe [1], &(evpipe [1]), 1);
1886#endif
1889 } 1887 }
1890 1888
1891 errno = old_errno; 1889 errno = old_errno;
1892 } 1890 }
1893} 1891}
1908 read (evfd, &counter, sizeof (uint64_t)); 1906 read (evfd, &counter, sizeof (uint64_t));
1909 } 1907 }
1910 else 1908 else
1911#endif 1909#endif
1912 { 1910 {
1913 char dummy; 1911 char dummy[4];
1914 /* see discussion in evpipe_write when you think this read should be recv in win32 */ 1912#ifdef _WIN32
1913 WSABUF buf;
1914 DWORD recvd;
1915 DWORD flags = 0;
1916 buf.buf = dummy;
1917 buf.len = sizeof (dummy);
1918 WSARecv (EV_FD_TO_WIN32_HANDLE (evpipe [0]), &buf, 1, &recvd, &flags, 0, 0);
1919#else
1915 read (evpipe [0], &dummy, 1); 1920 read (evpipe [0], &dummy, sizeof (dummy));
1921#endif
1916 } 1922 }
1917 } 1923 }
1918 1924
1919 pipe_write_skipped = 0; 1925 pipe_write_skipped = 0;
1920 1926
2349 EV_INVOKE_PENDING; 2355 EV_INVOKE_PENDING;
2350 } 2356 }
2351#endif 2357#endif
2352 2358
2353#if EV_CHILD_ENABLE 2359#if EV_CHILD_ENABLE
2354 if (ev_is_active (&childev)) 2360 if (ev_is_default_loop (EV_A) && ev_is_active (&childev))
2355 { 2361 {
2356 ev_ref (EV_A); /* child watcher */ 2362 ev_ref (EV_A); /* child watcher */
2357 ev_signal_stop (EV_A_ &childev); 2363 ev_signal_stop (EV_A_ &childev);
2358 } 2364 }
2359#endif 2365#endif
2554#if EV_FEATURE_API 2560#if EV_FEATURE_API
2555void ecb_cold 2561void ecb_cold
2556ev_verify (EV_P) EV_THROW 2562ev_verify (EV_P) EV_THROW
2557{ 2563{
2558#if EV_VERIFY 2564#if EV_VERIFY
2559 int i, j; 2565 int i;
2560 WL w, w2; 2566 WL w, w2;
2561 2567
2562 assert (activecnt >= -1); 2568 assert (activecnt >= -1);
2563 2569
2564 assert (fdchangemax >= fdchangecnt); 2570 assert (fdchangemax >= fdchangecnt);
2565 for (i = 0; i < fdchangecnt; ++i) 2571 for (i = 0; i < fdchangecnt; ++i)
2566 assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); 2572 assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0));
2567 2573
2568 assert (anfdmax >= 0); 2574 assert (anfdmax >= 0);
2569 for (i = j = 0; i < anfdmax; ++i) 2575 for (i = 0; i < anfdmax; ++i)
2576 {
2577 int j = 0;
2578
2570 for (w = w2 = anfds [i].head; w; w = w->next) 2579 for (w = w2 = anfds [i].head; w; w = w->next)
2571 { 2580 {
2572 verify_watcher (EV_A_ (W)w); 2581 verify_watcher (EV_A_ (W)w);
2573 2582
2574 if (++j & 1) 2583 if (j++ & 1)
2575 w2 = w2->next; 2584 {
2576
2577 assert (("libev: io watcher list contains a loop", w != w2)); 2585 assert (("libev: io watcher list contains a loop", w != w2));
2586 w2 = w2->next;
2587 }
2588
2578 assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); 2589 assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1));
2579 assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); 2590 assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i));
2580 } 2591 }
2592 }
2581 2593
2582 assert (timermax >= timercnt); 2594 assert (timermax >= timercnt);
2583 verify_heap (EV_A_ timers, timercnt); 2595 verify_heap (EV_A_ timers, timercnt);
2584 2596
2585#if EV_PERIODIC_ENABLE 2597#if EV_PERIODIC_ENABLE
2800{ 2812{
2801 EV_FREQUENT_CHECK; 2813 EV_FREQUENT_CHECK;
2802 2814
2803 while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) 2815 while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now)
2804 { 2816 {
2805 int feed_count = 0;
2806
2807 do 2817 do
2808 { 2818 {
2809 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); 2819 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]);
2810 2820
2811 /*assert (("libev: inactive timer on periodic heap detected", ev_is_active (w)));*/ 2821 /*assert (("libev: inactive timer on periodic heap detected", ev_is_active (w)));*/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines