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

Comparing libev/ev.c (file contents):
Revision 1.140 by root, Mon Nov 26 19:49:36 2007 UTC vs.
Revision 1.143 by root, Tue Nov 27 07:27:10 2007 UTC

225 225
226/*****************************************************************************/ 226/*****************************************************************************/
227 227
228static void (*syserr_cb)(const char *msg); 228static void (*syserr_cb)(const char *msg);
229 229
230void
230void ev_set_syserr_cb (void (*cb)(const char *msg)) 231ev_set_syserr_cb (void (*cb)(const char *msg))
231{ 232{
232 syserr_cb = cb; 233 syserr_cb = cb;
233} 234}
234 235
235static void 236static void noinline
236syserr (const char *msg) 237syserr (const char *msg)
237{ 238{
238 if (!msg) 239 if (!msg)
239 msg = "(libev) system error"; 240 msg = "(libev) system error";
240 241
247 } 248 }
248} 249}
249 250
250static void *(*alloc)(void *ptr, long size); 251static void *(*alloc)(void *ptr, long size);
251 252
253void
252void ev_set_allocator (void *(*cb)(void *ptr, long size)) 254ev_set_allocator (void *(*cb)(void *ptr, long size))
253{ 255{
254 alloc = cb; 256 alloc = cb;
255} 257}
256 258
257static void * 259static void *
315 317
316#endif 318#endif
317 319
318/*****************************************************************************/ 320/*****************************************************************************/
319 321
320ev_tstamp noinline 322ev_tstamp
321ev_time (void) 323ev_time (void)
322{ 324{
323#if EV_USE_REALTIME 325#if EV_USE_REALTIME
324 struct timespec ts; 326 struct timespec ts;
325 clock_gettime (CLOCK_REALTIME, &ts); 327 clock_gettime (CLOCK_REALTIME, &ts);
382#define array_free(stem, idx) \ 384#define array_free(stem, idx) \
383 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; 385 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0;
384 386
385/*****************************************************************************/ 387/*****************************************************************************/
386 388
387void inline_size
388anfds_init (ANFD *base, int count)
389{
390 while (count--)
391 {
392 base->head = 0;
393 base->events = EV_NONE;
394 base->reify = 0;
395
396 ++base;
397 }
398}
399
400void noinline 389void noinline
401ev_feed_event (EV_P_ void *w, int revents) 390ev_feed_event (EV_P_ void *w, int revents)
402{ 391{
403 W w_ = (W)w; 392 W w_ = (W)w;
404 393
412 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2); 401 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2);
413 pendings [ABSPRI (w_)][w_->pending - 1].w = w_; 402 pendings [ABSPRI (w_)][w_->pending - 1].w = w_;
414 pendings [ABSPRI (w_)][w_->pending - 1].events = revents; 403 pendings [ABSPRI (w_)][w_->pending - 1].events = revents;
415} 404}
416 405
417static void 406void inline_size
418queue_events (EV_P_ W *events, int eventcnt, int type) 407queue_events (EV_P_ W *events, int eventcnt, int type)
419{ 408{
420 int i; 409 int i;
421 410
422 for (i = 0; i < eventcnt; ++i) 411 for (i = 0; i < eventcnt; ++i)
423 ev_feed_event (EV_A_ events [i], type); 412 ev_feed_event (EV_A_ events [i], type);
424} 413}
425 414
415/*****************************************************************************/
416
417void inline_size
418anfds_init (ANFD *base, int count)
419{
420 while (count--)
421 {
422 base->head = 0;
423 base->events = EV_NONE;
424 base->reify = 0;
425
426 ++base;
427 }
428}
429
426void inline_speed 430void inline_speed
427fd_event (EV_P_ int fd, int revents) 431fd_event (EV_P_ int fd, int revents)
428{ 432{
429 ANFD *anfd = anfds + fd; 433 ANFD *anfd = anfds + fd;
430 ev_io *w; 434 ev_io *w;
441void 445void
442ev_feed_fd_event (EV_P_ int fd, int revents) 446ev_feed_fd_event (EV_P_ int fd, int revents)
443{ 447{
444 fd_event (EV_A_ fd, revents); 448 fd_event (EV_A_ fd, revents);
445} 449}
446
447/*****************************************************************************/
448 450
449void inline_size 451void inline_size
450fd_reify (EV_P) 452fd_reify (EV_P)
451{ 453{
452 int i; 454 int i;
712static ev_child *childs [PID_HASHSIZE]; 714static ev_child *childs [PID_HASHSIZE];
713 715
714#ifndef _WIN32 716#ifndef _WIN32
715 717
716static ev_signal childev; 718static ev_signal childev;
717
718#ifndef WCONTINUED
719# define WCONTINUED 0
720#endif
721 719
722void inline_speed 720void inline_speed
723child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) 721child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status)
724{ 722{
725 ev_child *w; 723 ev_child *w;
732 w->rstatus = status; 730 w->rstatus = status;
733 ev_feed_event (EV_A_ (W)w, EV_CHILD); 731 ev_feed_event (EV_A_ (W)w, EV_CHILD);
734 } 732 }
735} 733}
736 734
735#ifndef WCONTINUED
736# define WCONTINUED 0
737#endif
738
737static void 739static void
738childcb (EV_P_ ev_signal *sw, int revents) 740childcb (EV_P_ ev_signal *sw, int revents)
739{ 741{
740 int pid, status; 742 int pid, status;
741 743
744 /* some systems define WCONTINUED but then fail to support it (linux 2.4) */
742 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) 745 if (0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)))
743 { 746 if (!WCONTINUED
747 || errno != EINVAL
748 || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED)))
749 return;
750
744 /* make sure we are called again until all childs have been reaped */ 751 /* make sure we are called again until all childs have been reaped */
745 /* we need to do it this way so that the callback gets called before we continue */ 752 /* we need to do it this way so that the callback gets called before we continue */
746 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); 753 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
747 754
748 child_reap (EV_A_ sw, pid, pid, status); 755 child_reap (EV_A_ sw, pid, pid, status);
749 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ 756 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */
750 }
751} 757}
752 758
753#endif 759#endif
754 760
755/*****************************************************************************/ 761/*****************************************************************************/
1759 1765
1760# ifdef _WIN32 1766# ifdef _WIN32
1761# define lstat(a,b) stat(a,b) 1767# define lstat(a,b) stat(a,b)
1762# endif 1768# endif
1763 1769
1770#define DEF_STAT_INTERVAL 5.0074891
1771#define MIN_STAT_INTERVAL 0.1074891
1772
1764void 1773void
1765ev_stat_stat (EV_P_ ev_stat *w) 1774ev_stat_stat (EV_P_ ev_stat *w)
1766{ 1775{
1767 if (lstat (w->path, &w->attr) < 0) 1776 if (lstat (w->path, &w->attr) < 0)
1768 w->attr.st_nlink = 0; 1777 w->attr.st_nlink = 0;
1793 /* since we use memcmp, we need to clear any padding data etc. */ 1802 /* since we use memcmp, we need to clear any padding data etc. */
1794 memset (&w->prev, 0, sizeof (ev_statdata)); 1803 memset (&w->prev, 0, sizeof (ev_statdata));
1795 memset (&w->attr, 0, sizeof (ev_statdata)); 1804 memset (&w->attr, 0, sizeof (ev_statdata));
1796 1805
1797 ev_stat_stat (EV_A_ w); 1806 ev_stat_stat (EV_A_ w);
1807
1808 if (w->interval < MIN_STAT_INTERVAL)
1809 w->interval = w->interval ? MIN_STAT_INTERVAL : DEF_STAT_INTERVAL;
1798 1810
1799 ev_timer_init (&w->timer, stat_timer_cb, w->interval, w->interval); 1811 ev_timer_init (&w->timer, stat_timer_cb, w->interval, w->interval);
1800 ev_set_priority (&w->timer, ev_priority (w)); 1812 ev_set_priority (&w->timer, ev_priority (w));
1801 ev_timer_start (EV_A_ &w->timer); 1813 ev_timer_start (EV_A_ &w->timer);
1802 1814

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines