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 |
… | |
… | |
323 | /*****************************************************************************/ |
325 | /*****************************************************************************/ |
324 | |
326 | |
325 | typedef struct |
327 | typedef struct |
326 | { |
328 | { |
327 | struct ev_signal *head; |
329 | struct ev_signal *head; |
328 | sig_atomic_t gotsig; |
330 | sig_atomic_t volatile gotsig; |
329 | } ANSIG; |
331 | } ANSIG; |
330 | |
332 | |
331 | static ANSIG *signals; |
333 | static ANSIG *signals; |
332 | static int signalmax; |
334 | static int signalmax; |
333 | |
335 | |
334 | static int sigpipe [2]; |
336 | static int sigpipe [2]; |
335 | static sig_atomic_t gotsig; |
337 | static sig_atomic_t volatile gotsig; |
336 | static struct ev_io sigev; |
338 | static struct ev_io sigev; |
337 | |
339 | |
338 | static void |
340 | static void |
339 | signals_init (ANSIG *base, int count) |
341 | signals_init (ANSIG *base, int count) |
340 | { |
342 | { |
… | |
… | |
353 | signals [signum - 1].gotsig = 1; |
355 | signals [signum - 1].gotsig = 1; |
354 | |
356 | |
355 | if (!gotsig) |
357 | if (!gotsig) |
356 | { |
358 | { |
357 | gotsig = 1; |
359 | gotsig = 1; |
358 | write (sigpipe [1], &gotsig, 1); |
360 | write (sigpipe [1], &signum, 1); |
359 | } |
361 | } |
360 | } |
362 | } |
361 | |
363 | |
362 | static void |
364 | static void |
363 | sigcb (struct ev_io *iow, int revents) |
365 | sigcb (struct ev_io *iow, int revents) |
364 | { |
366 | { |
365 | struct ev_signal *w; |
367 | struct ev_signal *w; |
366 | int sig; |
368 | int sig; |
367 | |
369 | |
|
|
370 | read (sigpipe [0], &revents, 1); |
368 | gotsig = 0; |
371 | gotsig = 0; |
369 | read (sigpipe [0], &revents, 1); |
|
|
370 | |
372 | |
371 | for (sig = signalmax; sig--; ) |
373 | for (sig = signalmax; sig--; ) |
372 | if (signals [sig].gotsig) |
374 | if (signals [sig].gotsig) |
373 | { |
375 | { |
374 | signals [sig].gotsig = 0; |
376 | signals [sig].gotsig = 0; |
… | |
… | |
489 | } |
491 | } |
490 | |
492 | |
491 | /*****************************************************************************/ |
493 | /*****************************************************************************/ |
492 | |
494 | |
493 | void |
495 | void |
494 | ev_prefork (void) |
496 | ev_fork_prepare (void) |
495 | { |
497 | { |
496 | /* nop */ |
498 | /* nop */ |
497 | } |
499 | } |
498 | |
500 | |
499 | void |
501 | void |
500 | ev_postfork_parent (void) |
502 | ev_fork_parent (void) |
501 | { |
503 | { |
502 | /* nop */ |
504 | /* nop */ |
503 | } |
505 | } |
504 | |
506 | |
505 | void |
507 | void |
506 | ev_postfork_child (void) |
508 | ev_fork_child (void) |
507 | { |
509 | { |
508 | #if EV_USE_EPOLL |
510 | #if EV_USE_EPOLL |
509 | if (ev_method == EVMETHOD_EPOLL) |
511 | if (ev_method == EVMETHOD_EPOLL) |
510 | epoll_postfork_child (); |
512 | epoll_postfork_child (); |
511 | #endif |
513 | #endif |