2 // detail/posix_signal_blocker.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2019 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/config.hpp>
20 #if defined(BOOST_ASIO_HAS_PTHREADS)
25 #include <boost/asio/detail/noncopyable.hpp>
27 #include <boost/asio/detail/push_options.hpp>
33 class posix_signal_blocker
37 // Constructor blocks all signals for the calling thread.
38 posix_signal_blocker()
42 sigfillset(&new_mask);
43 blocked_ = (pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask_) == 0);
46 // Destructor restores the previous signal mask.
47 ~posix_signal_blocker()
50 pthread_sigmask(SIG_SETMASK, &old_mask_, 0);
53 // Block all signals for the calling thread.
59 sigfillset(&new_mask);
60 blocked_ = (pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask_) == 0);
64 // Restore the previous signal mask.
68 blocked_ = (pthread_sigmask(SIG_SETMASK, &old_mask_, 0) != 0);
72 // Have signals been blocked.
75 // The previous signal mask.
83 #include <boost/asio/detail/pop_options.hpp>
85 #endif // defined(BOOST_ASIO_HAS_PTHREADS)
87 #endif // BOOST_ASIO_DETAIL_POSIX_SIGNAL_BLOCKER_HPP