@@ -597,7 +597,8 @@ Planner::Result Planner::Result::Implementation::generate(
597597 Implementation{
598598 std::move (interface),
599599 std::move (state),
600- std::move (plan)
600+ std::move (plan),
601+ std::make_shared<std::atomic_bool>(false )
601602 });
602603
603604 return result;
@@ -618,7 +619,8 @@ Planner::Result Planner::Result::Implementation::setup(
618619 Implementation{
619620 std::move (interface),
620621 std::move (state),
621- rmf_utils::nullopt
622+ rmf_utils::nullopt ,
623+ std::make_shared<std::atomic_bool>(false )
622624 });
623625
624626 return result;
@@ -751,48 +753,56 @@ Planner::Result Planner::setup(
751753// ==============================================================================
752754bool Planner::Result::success () const
753755{
756+ planning::SpinLock lock (*_pimpl->mutex );
754757 return _pimpl->plan .has_value ();
755758}
756759
757760// ==============================================================================
758761bool Planner::Result::disconnected () const
759762{
763+ planning::SpinLock lock (*_pimpl->mutex );
760764 return _pimpl->state .issues .disconnected ;
761765}
762766
763767// ==============================================================================
764768Planner::Result::operator bool () const
765769{
770+ planning::SpinLock lock (*_pimpl->mutex );
766771 return _pimpl->plan .has_value ();
767772}
768773
769774// ==============================================================================
770775const Plan* Planner::Result::operator ->() const
771776{
777+ planning::SpinLock lock (*_pimpl->mutex );
772778 return &(*_pimpl->plan );
773779}
774780
775781// ==============================================================================
776782const Plan& Planner::Result::operator *() const &
777783{
784+ planning::SpinLock lock (*_pimpl->mutex );
778785 return *_pimpl->plan ;
779786}
780787
781788// ==============================================================================
782789Plan&& Planner::Result::operator *() &&
783790{
791+ planning::SpinLock lock (*_pimpl->mutex );
784792 return std::move (*std::move (_pimpl->plan ));
785793}
786794
787795// ==============================================================================
788796const Plan&& Planner::Result::operator *() const &&
789797{
798+ planning::SpinLock lock (*_pimpl->mutex );
790799 return std::move (*_pimpl->plan );
791800}
792801
793802// ==============================================================================
794803Planner::Result Planner::Result::replan (const Start& new_start) const
795804{
805+ planning::SpinLock lock (*_pimpl->mutex );
796806 return Result::Implementation::generate (
797807 _pimpl->interface ,
798808 {new_start},
@@ -805,6 +815,7 @@ Planner::Result Planner::Result::replan(
805815 const Planner::Start& new_start,
806816 Planner::Options new_options) const
807817{
818+ planning::SpinLock lock (*_pimpl->mutex );
808819 return Result::Implementation::generate (
809820 _pimpl->interface ,
810821 {new_start},
@@ -815,6 +826,7 @@ Planner::Result Planner::Result::replan(
815826// ==============================================================================
816827Planner::Result Planner::Result::replan (const StartSet& new_starts) const
817828{
829+ planning::SpinLock lock (*_pimpl->mutex );
818830 return Result::Implementation::generate (
819831 _pimpl->interface ,
820832 new_starts,
@@ -827,6 +839,7 @@ Planner::Result Planner::Result::replan(
827839 const StartSet& new_starts,
828840 Options new_options) const
829841{
842+ planning::SpinLock lock (*_pimpl->mutex );
830843 return Result::Implementation::generate (
831844 _pimpl->interface ,
832845 new_starts,
@@ -837,6 +850,7 @@ Planner::Result Planner::Result::replan(
837850// ==============================================================================
838851Planner::Result Planner::Result::setup (const Start& new_start) const
839852{
853+ planning::SpinLock lock (*_pimpl->mutex );
840854 return Result::Implementation::setup (
841855 _pimpl->interface ,
842856 {new_start},
@@ -849,6 +863,7 @@ Planner::Result Planner::Result::setup(
849863 const Start& new_start,
850864 Options new_options) const
851865{
866+ planning::SpinLock lock (*_pimpl->mutex );
852867 return Result::Implementation::setup (
853868 _pimpl->interface ,
854869 {new_start},
@@ -859,6 +874,7 @@ Planner::Result Planner::Result::setup(
859874// ==============================================================================
860875Planner::Result Planner::Result::setup (const StartSet& new_starts) const
861876{
877+ planning::SpinLock lock (*_pimpl->mutex );
862878 return Result::Implementation::setup (
863879 _pimpl->interface ,
864880 new_starts,
@@ -871,6 +887,7 @@ Planner::Result Planner::Result::setup(
871887 const StartSet& new_starts,
872888 Options new_options) const
873889{
890+ planning::SpinLock lock (*_pimpl->mutex );
874891 return Result::Implementation::setup (
875892 _pimpl->interface ,
876893 new_starts,
@@ -881,6 +898,7 @@ Planner::Result Planner::Result::setup(
881898// ==============================================================================
882899bool Planner::Result::resume ()
883900{
901+ planning::SpinLock lock (*_pimpl->mutex );
884902 if (_pimpl->plan )
885903 return true ;
886904
@@ -894,75 +912,90 @@ bool Planner::Result::resume()
894912bool Planner::Result::resume (
895913 std::shared_ptr<const std::atomic_bool> interrupt_flag)
896914{
897- _pimpl->state .conditions .options .interrupt_flag (std::move (interrupt_flag));
915+ {
916+ planning::SpinLock lock (*_pimpl->mutex );
917+ _pimpl->state .conditions .options .interrupt_flag (std::move (interrupt_flag));
918+ }
919+
898920 return resume ();
899921}
900922
901923// ==============================================================================
902924Planner::Options& Planner::Result::options ()
903925{
926+ planning::SpinLock lock (*_pimpl->mutex );
904927 return _pimpl->state .conditions .options ;
905928}
906929
907930// ==============================================================================
908931const Planner::Options& Planner::Result::options () const
909932{
933+ planning::SpinLock lock (*_pimpl->mutex );
910934 return _pimpl->state .conditions .options ;
911935}
912936
913937// ==============================================================================
914938Planner::Result& Planner::Result::options (Options new_options)
915939{
940+ planning::SpinLock lock (*_pimpl->mutex );
916941 _pimpl->state .conditions .options = std::move (new_options);
917942 return *this ;
918943}
919944
920945// ==============================================================================
921946std::optional<double > Planner::Result::cost_estimate () const
922947{
948+ planning::SpinLock lock (*_pimpl->mutex );
923949 return _pimpl->state .internal ->cost_estimate ();
924950}
925951
926952// ==============================================================================
927953double Planner::Result::initial_cost_estimate () const
928954{
955+ planning::SpinLock lock (*_pimpl->mutex );
929956 return _pimpl->state .ideal_cost .value_or (
930957 std::numeric_limits<double >::infinity ());
931958}
932959
933960// ==============================================================================
934961std::optional<double > Planner::Result::ideal_cost () const
935962{
963+ planning::SpinLock lock (*_pimpl->mutex );
936964 return _pimpl->state .ideal_cost ;
937965}
938966
939967// ==============================================================================
940968const std::vector<Planner::Start>& Planner::Result::get_starts () const
941969{
970+ planning::SpinLock lock (*_pimpl->mutex );
942971 return _pimpl->state .conditions .starts ;
943972}
944973
945974// ==============================================================================
946975const Planner::Goal& Planner::Result::get_goal () const
947976{
977+ planning::SpinLock lock (*_pimpl->mutex );
948978 return _pimpl->state .conditions .goal ;
949979}
950980
951981// ==============================================================================
952982const Planner::Configuration& Planner::Result::get_configuration () const
953983{
984+ planning::SpinLock lock (*_pimpl->mutex );
954985 return _pimpl->interface ->get_configuration ();
955986}
956987
957988// ==============================================================================
958989bool Planner::Result::interrupted () const
959990{
991+ planning::SpinLock lock (*_pimpl->mutex );
960992 return _pimpl->state .issues .interrupted ;
961993}
962994
963995// ==============================================================================
964996bool Planner::Result::saturated () const
965997{
998+ planning::SpinLock lock (*_pimpl->mutex );
966999 const auto saturation_limit =
9671000 _pimpl->state .conditions .options .saturation_limit ();
9681001
@@ -978,6 +1011,7 @@ bool Planner::Result::saturated() const
9781011// ==============================================================================
9791012std::vector<schedule::ParticipantId> Planner::Result::blockers () const
9801013{
1014+ planning::SpinLock lock (*_pimpl->mutex );
9811015 std::vector<schedule::ParticipantId> blockers;
9821016 blockers.reserve (_pimpl->state .issues .blocked_nodes .size ());
9831017 for (const auto & b : _pimpl->state .issues .blocked_nodes )
@@ -1427,15 +1461,17 @@ auto Planner::Debug::begin(
14271461// ==============================================================================
14281462std::size_t Planner::Debug::queue_size (const Planner::Result& result)
14291463{
1430- return Planner::Result::Implementation::get (result)
1431- .state .internal ->queue_size ();
1464+ const auto & pimpl = Planner::Result::Implementation::get (result);
1465+ planning::SpinLock lock (*pimpl.mutex );
1466+ return pimpl.state .internal ->queue_size ();
14321467}
14331468
14341469// ==============================================================================
14351470std::size_t Planner::Debug::expansion_count (const Planner::Result& result)
14361471{
1437- return Planner::Result::Implementation::get (result)
1438- .state .internal ->expansion_count ();
1472+ const auto & pimpl = Planner::Result::Implementation::get (result);
1473+ planning::SpinLock lock (*pimpl.mutex );
1474+ return pimpl.state .internal ->expansion_count ();
14391475}
14401476
14411477// ==============================================================================
0 commit comments