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

Comparing libev/ev.c (file contents):
Revision 1.33 by root, Thu Nov 1 11:11:22 2007 UTC vs.
Revision 1.38 by root, Thu Nov 1 15:21:13 2007 UTC

1/* 1/*
2 * libev event processing core, watcher management
3 *
2 * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
3 * All rights reserved. 5 * All rights reserved.
4 * 6 *
5 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 8 * modification, are permitted provided that the following conditions are
45#include <sys/wait.h> 47#include <sys/wait.h>
46#include <sys/time.h> 48#include <sys/time.h>
47#include <time.h> 49#include <time.h>
48 50
49#ifndef EV_USE_MONOTONIC 51#ifndef EV_USE_MONOTONIC
50# ifdef CLOCK_MONOTONIC
51# define EV_USE_MONOTONIC 1 52# define EV_USE_MONOTONIC 1
52# endif 53#endif
54
55#ifndef CLOCK_MONOTONIC
56# undef EV_USE_MONOTONIC
57# define EV_USE_MONOTONIC 0
53#endif 58#endif
54 59
55#ifndef EV_USE_SELECT 60#ifndef EV_USE_SELECT
56# define EV_USE_SELECT 1 61# define EV_USE_SELECT 1
57#endif 62#endif
323/*****************************************************************************/ 328/*****************************************************************************/
324 329
325typedef struct 330typedef struct
326{ 331{
327 struct ev_signal *head; 332 struct ev_signal *head;
328 sig_atomic_t gotsig; 333 sig_atomic_t volatile gotsig;
329} ANSIG; 334} ANSIG;
330 335
331static ANSIG *signals; 336static ANSIG *signals;
332static int signalmax; 337static int signalmax;
333 338
334static int sigpipe [2]; 339static int sigpipe [2];
335static sig_atomic_t gotsig; 340static sig_atomic_t volatile gotsig;
336static struct ev_io sigev; 341static struct ev_io sigev;
337 342
338static void 343static void
339signals_init (ANSIG *base, int count) 344signals_init (ANSIG *base, int count)
340{ 345{
353 signals [signum - 1].gotsig = 1; 358 signals [signum - 1].gotsig = 1;
354 359
355 if (!gotsig) 360 if (!gotsig)
356 { 361 {
357 gotsig = 1; 362 gotsig = 1;
358 write (sigpipe [1], &gotsig, 1); 363 write (sigpipe [1], &signum, 1);
359 } 364 }
360} 365}
361 366
362static void 367static void
363sigcb (struct ev_io *iow, int revents) 368sigcb (struct ev_io *iow, int revents)
364{ 369{
365 struct ev_signal *w; 370 struct ev_signal *w;
366 int sig; 371 int signum;
367 372
373 read (sigpipe [0], &revents, 1);
368 gotsig = 0; 374 gotsig = 0;
369 read (sigpipe [0], &revents, 1);
370 375
371 for (sig = signalmax; sig--; ) 376 for (signum = signalmax; signum--; )
372 if (signals [sig].gotsig) 377 if (signals [signum].gotsig)
373 { 378 {
374 signals [sig].gotsig = 0; 379 signals [signum].gotsig = 0;
375 380
376 for (w = signals [sig].head; w; w = w->next) 381 for (w = signals [signum].head; w; w = w->next)
377 event ((W)w, EV_SIGNAL); 382 event ((W)w, EV_SIGNAL);
378 } 383 }
379} 384}
380 385
381static void 386static void
489} 494}
490 495
491/*****************************************************************************/ 496/*****************************************************************************/
492 497
493void 498void
494ev_prefork (void) 499ev_fork_prepare (void)
495{ 500{
496 /* nop */ 501 /* nop */
497} 502}
498 503
499void 504void
500ev_postfork_parent (void) 505ev_fork_parent (void)
501{ 506{
502 /* nop */ 507 /* nop */
503} 508}
504 509
505void 510void
506ev_postfork_child (void) 511ev_fork_child (void)
507{ 512{
508#if EV_USE_EPOLL 513#if EV_USE_EPOLL
509 if (ev_method == EVMETHOD_EPOLL) 514 if (ev_method == EVMETHOD_EPOLL)
510 epoll_postfork_child (); 515 epoll_postfork_child ();
511#endif 516#endif
761/*****************************************************************************/ 766/*****************************************************************************/
762 767
763void 768void
764ev_io_start (struct ev_io *w) 769ev_io_start (struct ev_io *w)
765{ 770{
766 if (ev_is_active (w))
767 return;
768
769 int fd = w->fd; 771 int fd = w->fd;
772
773 if (ev_is_active (w))
774 return;
770 775
771 assert (("ev_io_start called with negative fd", fd >= 0)); 776 assert (("ev_io_start called with negative fd", fd >= 0));
772 777
773 ev_start ((W)w, 1); 778 ev_start ((W)w, 1);
774 array_needsize (anfds, anfdmax, fd + 1, anfds_init); 779 array_needsize (anfds, anfdmax, fd + 1, anfds_init);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines