1 | /* |
1 | /* |
2 | * libev event processing core, watcher management |
2 | * libev event processing core, watcher management |
3 | * |
3 | * |
4 | * Copyright (c) 2007,2008,2009,2010 Marc Alexander Lehmann <libev@schmorp.de> |
4 | * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann <libev@schmorp.de> |
5 | * All rights reserved. |
5 | * All rights reserved. |
6 | * |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
8 | * tion, are permitted provided that the following conditions are met: |
8 | * tion, are permitted provided that the following conditions are met: |
9 | * |
9 | * |
… | |
… | |
1369 | #endif |
1369 | #endif |
1370 | } |
1370 | } |
1371 | |
1371 | |
1372 | /*****************************************************************************/ |
1372 | /*****************************************************************************/ |
1373 | |
1373 | |
|
|
1374 | void |
|
|
1375 | ev_feed_signal (int signum) |
|
|
1376 | { |
|
|
1377 | #if EV_MULTIPLICITY |
|
|
1378 | EV_P = signals [signum - 1].loop; |
|
|
1379 | |
|
|
1380 | if (!EV_A) |
|
|
1381 | return; |
|
|
1382 | #endif |
|
|
1383 | |
|
|
1384 | signals [signum - 1].pending = 1; |
|
|
1385 | evpipe_write (EV_A_ &sig_pending); |
|
|
1386 | } |
|
|
1387 | |
1374 | static void |
1388 | static void |
1375 | ev_sighandler (int signum) |
1389 | ev_sighandler (int signum) |
1376 | { |
1390 | { |
1377 | #if EV_MULTIPLICITY |
|
|
1378 | EV_P = signals [signum - 1].loop; |
|
|
1379 | #endif |
|
|
1380 | |
|
|
1381 | #ifdef _WIN32 |
1391 | #ifdef _WIN32 |
1382 | signal (signum, ev_sighandler); |
1392 | signal (signum, ev_sighandler); |
1383 | #endif |
1393 | #endif |
1384 | |
1394 | |
1385 | signals [signum - 1].pending = 1; |
1395 | ev_feed_signal (signum); |
1386 | evpipe_write (EV_A_ &sig_pending); |
|
|
1387 | } |
1396 | } |
1388 | |
1397 | |
1389 | void noinline |
1398 | void noinline |
1390 | ev_feed_signal_event (EV_P_ int signum) |
1399 | ev_feed_signal_event (EV_P_ int signum) |
1391 | { |
1400 | { |
… | |
… | |
1643 | static void noinline |
1652 | static void noinline |
1644 | loop_init (EV_P_ unsigned int flags) |
1653 | loop_init (EV_P_ unsigned int flags) |
1645 | { |
1654 | { |
1646 | if (!backend) |
1655 | if (!backend) |
1647 | { |
1656 | { |
|
|
1657 | origflags = flags; |
|
|
1658 | |
1648 | #if EV_USE_REALTIME |
1659 | #if EV_USE_REALTIME |
1649 | if (!have_realtime) |
1660 | if (!have_realtime) |
1650 | { |
1661 | { |
1651 | struct timespec ts; |
1662 | struct timespec ts; |
1652 | |
1663 | |
… | |
… | |
1697 | #endif |
1708 | #endif |
1698 | #if EV_USE_SIGNALFD |
1709 | #if EV_USE_SIGNALFD |
1699 | sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1; |
1710 | sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1; |
1700 | #endif |
1711 | #endif |
1701 | |
1712 | |
1702 | if (!(flags & 0x0000ffffU)) |
1713 | if (!(flags & EVBACKEND_MASK)) |
1703 | flags |= ev_recommended_backends (); |
1714 | flags |= ev_recommended_backends (); |
1704 | |
1715 | |
1705 | #if EV_USE_IOCP |
1716 | #if EV_USE_IOCP |
1706 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
1717 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
1707 | #endif |
1718 | #endif |
… | |
… | |
2879 | sa.sa_handler = ev_sighandler; |
2890 | sa.sa_handler = ev_sighandler; |
2880 | sigfillset (&sa.sa_mask); |
2891 | sigfillset (&sa.sa_mask); |
2881 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
2892 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
2882 | sigaction (w->signum, &sa, 0); |
2893 | sigaction (w->signum, &sa, 0); |
2883 | |
2894 | |
|
|
2895 | if (origflags & EVFLAG_NOSIGMASK) |
|
|
2896 | { |
2884 | sigemptyset (&sa.sa_mask); |
2897 | sigemptyset (&sa.sa_mask); |
2885 | sigaddset (&sa.sa_mask, w->signum); |
2898 | sigaddset (&sa.sa_mask, w->signum); |
2886 | sigprocmask (SIG_UNBLOCK, &sa.sa_mask, 0); |
2899 | sigprocmask (SIG_UNBLOCK, &sa.sa_mask, 0); |
|
|
2900 | } |
2887 | #endif |
2901 | #endif |
2888 | } |
2902 | } |
2889 | |
2903 | |
2890 | EV_FREQUENT_CHECK; |
2904 | EV_FREQUENT_CHECK; |
2891 | } |
2905 | } |