Commits

Luis Torres committed 0ab5239

Conditional compilation added for old versions of boost which require a deprecated call

Comments (0)

Files changed (3)

     add_definitions(-DBOOST_TEST_DYN_LINK)
 endif(IS_ICPC)
 
-find_package(Boost COMPONENTS date_time thread serialization filesystem system program_options unit_test_framework chrono REQUIRED)
-include_directories(SYSTEM ${Boost_INCLUDE_DIR})
+# Do one quiet find_package on Boost to see if it is recent enough to
+# have the try_join_for call
+find_package(Boost QUIET 1.50)
+
+# try_join_for requires the chrono library, so if we will use
+# try_join_for, we need to include the chrono component
+if (${Boost_FOUND})
+  # we're using chrono
+  find_package(Boost COMPONENTS date_time thread serialization filesystem system program_options unit_test_framework chrono REQUIRED)
+else()
+  # don't use chrono, set a flag to notify that we're using the
+  # deprecated timed_join() call
+  find_package(Boost COMPONENTS date_time thread serialization filesystem system program_options unit_test_framework REQUIRED)
+  add_definitions(-DUSE_BOOST_TIMED_JOIN)
+endif()
+# include_directories(SYSTEM ${Boost_INCLUDE_DIR})
+include_directories(${Boost_INCLUDE_DIR})
 
 if (NOT ${Boost_VERSION} LESS 104400)
   option(OMPL_ODESOLVER "Enable OMPL ODE solver classes" ON)

src/ompl/tools/benchmark/Benchmark.h

                 /** \brief Constructor that provides default values for all members */
                 Request(double maxTime = 5.0, double maxMem = 4096.0,
                         unsigned int runCount = 100,
-                        boost::int_least64_t msBetweenProgressUpdates = 1,
+                        double timeBetweenUpdates = 0.001,
                         bool displayProgress = true,
                         bool saveConsoleOutput = true, bool useThreads = true)
                     : maxTime(maxTime), maxMem(maxMem), runCount(runCount),
                 /// \brief the number of times to run each planner; 100 by default
                 unsigned int runCount;
 
-                /// \brief When collecting time-varying data from a planner during its execution, the planner's progress will be queried every \c msBetweenProgressUpdates milliseconds.
-                boost::int_least64_t msBetweenProgressUpdates;
+                /// \brief When collecting time-varying data from a planner during its execution, the planner's progress will be queried every \c timeBetweenUpdates seconds.
+                double       timeBetweenUpdates;
 
                 /// \brief flag indicating whether progress is to be displayed or not; true by default
                 bool         displayProgress;

src/ompl/tools/benchmark/src/Benchmark.cpp

             {
             }
 
-            void run(const base::PlannerPtr &planner, const machine::MemUsage_t memStart, const machine::MemUsage_t maxMem, const double maxTime, const boost::int_least64_t msBetweenProgressUpdates)
+            void run(const base::PlannerPtr &planner, const machine::MemUsage_t memStart, const machine::MemUsage_t maxMem, const double maxTime, const double timeBetweenUpdates)
             {
                 if (!useThreads_)
                 {
-                    runThread(planner, memStart + maxMem, time::seconds(maxTime), msBetweenProgressUpdates);
+                    runThread(planner, memStart + maxMem, time::seconds(maxTime), time::seconds(timeBetweenUpdates));
                     return;
                 }
 
-                boost::thread t(boost::bind(&RunPlanner::runThread, this, planner, memStart + maxMem, time::seconds(maxTime), msBetweenProgressUpdates));
+                boost::thread t(boost::bind(&RunPlanner::runThread, this, planner, memStart + maxMem, time::seconds(maxTime), time::seconds(timeBetweenUpdates)));
 
                 // allow 25% more time than originally specified, in order to detect planner termination
+#ifdef USE_BOOST_TIMED_JOIN
+                // For older versions of boost, we have to use this
+                // deprecated form of the timed join
+                if (!t.timed_join(time::seconds(maxTime * 1.25)))
+#else
                 if (!t.try_join_for(boost::chrono::duration<double>(maxTime * 1.25)))
+#endif
                 {
                     status_ = base::PlannerStatus::CRASH;
 
 
         private:
 
-            void runThread(const base::PlannerPtr &planner, const machine::MemUsage_t maxMem, const time::duration &maxDuration, const boost::int_least64_t msBetweenProgressUpdates)
+            void runThread(const base::PlannerPtr &planner, const machine::MemUsage_t maxMem, const time::duration &maxDuration, const time::duration &timeBetweenUpdates)
             {
                 time::point timeStart = time::now();
 
                     if (planner->getPlannerProgressProperties().size() > 0)
                         t.reset(new boost::thread(boost::bind(&RunPlanner::collectProgressProperties,                                                               this,
                                                               planner->getPlannerProgressProperties(),
-                                                              msBetweenProgressUpdates)));
+                                                              timeBetweenUpdates)));
                     status_ = planner->solve(ptc, 0.1);
                     solvedFlag_.lock();
                     solved_ = true;
             }
 
             void collectProgressProperties(const base::Planner::PlannerProgressProperties& properties,
-                                           boost::int_least64_t milliseconds)
+                                           const time::duration &timePerUpdate)
             {
-                boost::chrono::milliseconds updatePeriod(milliseconds);
                 time::point timeStart = time::now();
 
                 boost::unique_lock<boost::mutex> ulock(solvedFlag_);
                 while (!solved_)
                 {
-                    if (solvedCondition_.wait_for(ulock, updatePeriod) == boost::cv_status::no_timeout)
+                    if (solvedCondition_.timed_wait(ulock, time::now() + timePerUpdate))
                         return;
                     else
                     {
             }
 
             RunPlanner rp(this, req.useThreads);
-            rp.run(planners_[i], memStart, maxMemBytes, req.maxTime, req.msBetweenProgressUpdates);
+            rp.run(planners_[i], memStart, maxMemBytes, req.maxTime, req.timeBetweenUpdates);
             bool solved = gsetup_ ? gsetup_->haveSolutionPath() : csetup_->haveSolutionPath();
 
             // store results