Exemplo n.º 1
0
    void async_wait(implementation_type &impl, pid_type pid, Handler handler)
    {
#if defined(BOOST_POSIX_API)
        boost::unique_lock<boost::mutex> lock(work_thread_mutex_);
        if (++pids_ == 1)
        {
            work_.reset(new boost::asio::io_service::work(
                this->get_io_service()));
            work_thread_ = boost::thread(
                &basic_status_service<StatusImplementation>::work_thread,
                this);
        }
        impl->async_wait(pid, this->get_io_service().wrap(handler));
#elif defined(BOOST_WINDOWS_API)
        HANDLE handle = OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION,
            FALSE, pid);
        if (handle == NULL)
            BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("OpenProcess() failed");
        boost::unique_lock<boost::mutex> lock(work_thread_mutex_);
        if (!work_)
            work_.reset(new boost::asio::io_service::work(
                this->get_io_service()));
        interrupt_work_thread();
        work_thread_cond_.wait(work_thread_mutex_);
        handles_.push_back(handle);
        impl->async_wait(handle, this->get_io_service().wrap(handler));
        work_thread_cond_.notify_all();
#endif
    }
    void async_wait(
        implementation_type& impl,
        NotificationHandler handler)
      {
      basic_signal_callback h = handler;
      
      if (is_process_thread())
        {
        impl->async_wait(h);

        return;
        }

      apoa::get_process_io_service().post(
        std::bind(
          &signal_handler_base_impl::async_wait, impl.get(),
          h));
      }