Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64780 - in sandbox/SOC/2010/process: boost/process/detail libs/process/test/inclusion
From: boris_at_[hidden]
Date: 2010-08-13 05:28:21


Author: bschaeling
Date: 2010-08-13 05:28:15 EDT (Fri, 13 Aug 2010)
New Revision: 64780
URL: http://svn.boost.org/trac/boost/changeset/64780

Log:
Fixed status class to support asynchronous wait operations on POSIX systems
Text files modified:
   sandbox/SOC/2010/process/boost/process/detail/basic_status_service.hpp | 44 +++++++++++++++++++++++++++++----------
   sandbox/SOC/2010/process/boost/process/detail/status_impl.hpp | 6 +++-
   sandbox/SOC/2010/process/libs/process/test/inclusion/detail_posix_helpers.cpp | 6 ++++
   sandbox/SOC/2010/process/libs/process/test/inclusion/detail_windows_helpers.cpp | 6 ++++
   4 files changed, 46 insertions(+), 16 deletions(-)

Modified: sandbox/SOC/2010/process/boost/process/detail/basic_status_service.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/detail/basic_status_service.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/detail/basic_status_service.hpp 2010-08-13 05:28:15 EDT (Fri, 13 Aug 2010)
@@ -23,6 +23,7 @@
 #include <boost/process/config.hpp>
 
 #if defined(BOOST_POSIX_API)
+# include <boost/process/operations.hpp>
 # include <sys/types.h>
 # include <sys/wait.h>
 #elif defined(BOOST_WINDOWS_API)
@@ -59,12 +60,13 @@
 public:
     explicit basic_status_service(boost::asio::io_service &io_service)
         : boost::asio::detail::service_base<StatusImplementation>(io_service),
- work_thread_(&basic_status_service<StatusImplementation>::work_thread, this)
 #if defined(BOOST_POSIX_API)
- , interrupt_pid_(-1),
+ interrupt_pid_(-1),
         pids_(0)
 #elif defined(BOOST_WINDOWS_API)
- , run_(true)
+ work_thread_(&basic_status_service<StatusImplementation>::work_thread,
+ this),
+ run_(true)
 #endif
     {
 #if defined(BOOST_WINDOWS_API)
@@ -76,9 +78,15 @@
 
     ~basic_status_service()
     {
+#if defined(BOOST_POSIX_API)
+ if (work_thread_.joinable())
+ {
+ stop_work_thread();
+ work_thread_.join();
+ }
+#elif defined(BOOST_WINDOWS_API)
         stop_work_thread();
         work_thread_.join();
-#if defined(BOOST_WINDOWS_API)
         CloseHandle(handles_[0]);
 #endif
     }
@@ -116,16 +124,23 @@
 #if defined(BOOST_POSIX_API)
         boost::unique_lock<boost::mutex> lock(work_thread_mutex_);
         if (!work_)
- work_.reset(new boost::asio::io_service::work(this->get_io_service()));
+ work_.reset(new boost::asio::io_service::work(
+ this->get_io_service()));
         ++pids_;
+ if (!work_thread_.joinable())
+ 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);
+ 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()));
+ 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);
@@ -141,9 +156,9 @@
 
     void work_thread()
     {
- for (;;)
- {
 #if defined(BOOST_POSIX_API)
+ while (pids_)
+ {
             int status;
             pid_t pid = ::wait(&status);
             if (pid == -1)
@@ -165,11 +180,15 @@
                 if (--pids_ == 0)
                     work_.reset();
             }
+ }
 #elif defined(BOOST_WINDOWS_API)
+ for (;;)
+ {
             DWORD res = WaitForMultipleObjects(handles_.size(), &handles_[0],
                 FALSE, INFINITE);
             if (res == WAIT_FAILED)
- BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("WaitForMultipleObjects() failed");
+ BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR(
+ "WaitForMultipleObjects() failed");
             else if (res - WAIT_OBJECT_0 == 0)
             {
                 boost::unique_lock<boost::mutex> lock(work_thread_mutex_);
@@ -183,7 +202,8 @@
                 HANDLE handle = handles_[res - WAIT_OBJECT_0];
                 DWORD exit_code;
                 if (!GetExitCodeProcess(handle, &exit_code))
- BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("GetExitCodeProcess() failed");
+ BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR(
+ "GetExitCodeProcess() failed");
                 boost::unique_lock<boost::mutex> lock(work_thread_mutex_);
                 for (std::vector<implementation_type>::iterator it =
                     impls_.begin(); it != impls_.end(); ++it)
@@ -194,8 +214,8 @@
                 if (handles_.size() == 1)
                     work_.reset();
             }
-#endif
         }
+#endif
     }
 
     void interrupt_work_thread()

Modified: sandbox/SOC/2010/process/boost/process/detail/status_impl.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/detail/status_impl.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/detail/status_impl.hpp 2010-08-13 05:28:15 EDT (Fri, 13 Aug 2010)
@@ -94,7 +94,8 @@
         }
         return status;
 #elif defined(BOOST_WINDOWS_API)
- HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, pid);
+ HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE,
+ pid);
         if (h == NULL)
         {
             ec = boost::system::error_code(GetLastError(),
@@ -136,7 +137,8 @@
 
     void complete(phandle ph, int exit_code)
     {
- boost::iterator_range<operations_type::iterator> r = ops_.equal_range(ph);
+ boost::iterator_range<operations_type::iterator> r =
+ ops_.equal_range(ph);
         for (operations_type::iterator it = r.begin(); it != r.end(); ++it)
             (*it->second)(exit_code);
         ops_.erase(r.begin(), r.end());

Modified: sandbox/SOC/2010/process/libs/process/test/inclusion/detail_posix_helpers.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/test/inclusion/detail_posix_helpers.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/test/inclusion/detail_posix_helpers.cpp 2010-08-13 05:28:15 EDT (Fri, 13 Aug 2010)
@@ -11,4 +11,8 @@
 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 //
 
-#include <boost/process/detail/posix_helpers.hpp>
+#include <boost/process/config.hpp>
+
+#if defined(BOOST_POSIX_API)
+# include <boost/process/detail/posix_helpers.hpp>
+#endif

Modified: sandbox/SOC/2010/process/libs/process/test/inclusion/detail_windows_helpers.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/test/inclusion/detail_windows_helpers.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/test/inclusion/detail_windows_helpers.cpp 2010-08-13 05:28:15 EDT (Fri, 13 Aug 2010)
@@ -11,4 +11,8 @@
 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 //
 
-#include <boost/process/detail/windows_helpers.hpp>
+#include <boost/process/config.hpp>
+
+#if defined(BOOST_WINDOWS_API)
+# include <boost/process/detail/windows_helpers.hpp>
+#endif


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk