X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c4b7bad9496047f71e12b920ee69366769686018..8d9c110f5bf839dcb7426f7750c09b3ff196bdf3:/include/simgrid/s4u/ActivitySet.hpp diff --git a/include/simgrid/s4u/ActivitySet.hpp b/include/simgrid/s4u/ActivitySet.hpp index 172bb36991..10ec7c86ec 100644 --- a/include/simgrid/s4u/ActivitySet.hpp +++ b/include/simgrid/s4u/ActivitySet.hpp @@ -11,7 +11,11 @@ #include -namespace simgrid::s4u { +namespace simgrid { + +extern template class XBT_PUBLIC xbt::Extendable; + +namespace s4u { /** @brief ActivitiesSet * * This class is a container of activities, allowing to wait for the completion of any or all activities in the set. @@ -19,10 +23,12 @@ namespace simgrid::s4u { * activities. */ class XBT_PUBLIC ActivitySet : public xbt::Extendable { - std::vector - activities_; // We use a vector instead of a set to improve reproductibility accross architectures + std::atomic_int_fast32_t refcount_{1}; + std::vector activities_; // Use vectors, not sets for better reproductibility accross architectures std::vector failed_activities_; + void handle_failed_activities(); + public: ActivitySet() = default; ActivitySet(const std::vector init) : activities_(init) {} @@ -72,10 +78,27 @@ public: */ ActivityPtr wait_any() { return wait_any_for(-1); } + /** Return one of the failed activity of the set that was revealed during the previous wait operation, or + * ActivityPtr() if no failed activity exist in the set. */ ActivityPtr get_failed_activity(); + /** Return whether the set contains any failed activity. */ bool has_failed_activities() { return not failed_activities_.empty(); } + + // boost::intrusive_ptr support: + friend void intrusive_ptr_add_ref(ActivitySet* as) + { + XBT_ATTRIB_UNUSED auto previous = as->refcount_.fetch_add(1); + xbt_assert(previous != 0); + } + + friend void intrusive_ptr_release(ActivitySet* as) + { + if (as->refcount_.fetch_sub(1) == 1) + delete as; + } }; -}; // namespace simgrid::s4u +} // namespace s4u +} // namespace simgrid #endif