2 // posix_signal_blocker.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_DETAIL_POSIX_SIGNAL_BLOCKER_HPP
12 #define BOOST_ASIO_DETAIL_POSIX_SIGNAL_BLOCKER_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/push_options.hpp>
20 #include <boost/asio/detail/push_options.hpp>
21 #include <boost/config.hpp>
22 #include <boost/asio/detail/pop_options.hpp>
24 #if defined(BOOST_HAS_PTHREADS)
26 #include <boost/asio/detail/push_options.hpp>
30 #include <boost/asio/detail/pop_options.hpp>
32 #include <boost/asio/detail/noncopyable.hpp>
38 class posix_signal_blocker
42 // Constructor blocks all signals for the calling thread.
43 posix_signal_blocker()
47 sigfillset(&new_mask
);
48 blocked_
= (pthread_sigmask(SIG_BLOCK
, &new_mask
, &old_mask_
) == 0);
51 // Destructor restores the previous signal mask.
52 ~posix_signal_blocker()
55 pthread_sigmask(SIG_SETMASK
, &old_mask_
, 0);
58 // Block all signals for the calling thread.
64 sigfillset(&new_mask
);
65 blocked_
= (pthread_sigmask(SIG_BLOCK
, &new_mask
, &old_mask_
) == 0);
69 // Restore the previous signal mask.
73 blocked_
= (pthread_sigmask(SIG_SETMASK
, &old_mask_
, 0) != 0);
77 // Have signals been blocked.
80 // The previous signal mask.
88 #endif // defined(BOOST_HAS_PTHREADS)
90 #include <boost/asio/detail/pop_options.hpp>
92 #endif // BOOST_ASIO_DETAIL_POSIX_SIGNAL_BLOCKER_HPP