Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ASIO_DETAIL_POSIX_SIGNAL_BLOCKER_HPP
00012 #define ASIO_DETAIL_POSIX_SIGNAL_BLOCKER_HPP
00013
00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00015 # pragma once
00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
00017
00018 #include "asio/detail/push_options.hpp"
00019
00020 #include "asio/detail/push_options.hpp"
00021 #include <boost/config.hpp>
00022 #include "asio/detail/pop_options.hpp"
00023
00024 #if defined(BOOST_HAS_PTHREADS)
00025
00026 #include "asio/detail/push_options.hpp"
00027 #include <csignal>
00028 #include <pthread.h>
00029 #include <signal.h>
00030 #include "asio/detail/pop_options.hpp"
00031
00032 #include "asio/detail/noncopyable.hpp"
00033
00034 namespace asio {
00035 namespace detail {
00036
00037 class posix_signal_blocker
00038 : private noncopyable
00039 {
00040 public:
00041
00042 posix_signal_blocker()
00043 : blocked_(false)
00044 {
00045 sigset_t new_mask;
00046 sigfillset(&new_mask);
00047 blocked_ = (pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask_) == 0);
00048 }
00049
00050
00051 ~posix_signal_blocker()
00052 {
00053 if (blocked_)
00054 pthread_sigmask(SIG_SETMASK, &old_mask_, 0);
00055 }
00056
00057
00058 void block()
00059 {
00060 if (!blocked_)
00061 {
00062 sigset_t new_mask;
00063 sigfillset(&new_mask);
00064 blocked_ = (pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask_) == 0);
00065 }
00066 }
00067
00068
00069 void unblock()
00070 {
00071 if (blocked_)
00072 blocked_ = (pthread_sigmask(SIG_SETMASK, &old_mask_, 0) != 0);
00073 }
00074
00075 private:
00076
00077 bool blocked_;
00078
00079
00080 sigset_t old_mask_;
00081 };
00082
00083 }
00084 }
00085
00086 #endif // defined(BOOST_HAS_PTHREADS)
00087
00088 #include "asio/detail/pop_options.hpp"
00089
00090 #endif // ASIO_DETAIL_POSIX_SIGNAL_BLOCKER_HPP