File indexing completed on 2025-12-16 09:43:09
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_POSIX_SIGNAL_BLOCKER_HPP
0012 #define BOOST_ASIO_DETAIL_POSIX_SIGNAL_BLOCKER_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019
0020 #if defined(BOOST_ASIO_HAS_PTHREADS)
0021
0022 #include <csignal>
0023 #include <pthread.h>
0024 #include <signal.h>
0025 #include <boost/asio/detail/noncopyable.hpp>
0026
0027 #include <boost/asio/detail/push_options.hpp>
0028
0029 namespace boost {
0030 namespace asio {
0031 namespace detail {
0032
0033 class posix_signal_blocker
0034 : private noncopyable
0035 {
0036 public:
0037
0038 posix_signal_blocker()
0039 : blocked_(false)
0040 {
0041 sigset_t new_mask;
0042 sigfillset(&new_mask);
0043 blocked_ = (pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask_) == 0);
0044 }
0045
0046
0047 ~posix_signal_blocker()
0048 {
0049 if (blocked_)
0050 pthread_sigmask(SIG_SETMASK, &old_mask_, 0);
0051 }
0052
0053
0054 void block()
0055 {
0056 if (!blocked_)
0057 {
0058 sigset_t new_mask;
0059 sigfillset(&new_mask);
0060 blocked_ = (pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask_) == 0);
0061 }
0062 }
0063
0064
0065 void unblock()
0066 {
0067 if (blocked_)
0068 blocked_ = (pthread_sigmask(SIG_SETMASK, &old_mask_, 0) != 0);
0069 }
0070
0071 private:
0072
0073 bool blocked_;
0074
0075
0076 sigset_t old_mask_;
0077 };
0078
0079 }
0080 }
0081 }
0082
0083 #include <boost/asio/detail/pop_options.hpp>
0084
0085 #endif
0086
0087 #endif