X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d54ca2b555fc67dfb608b5c6e87e1af04f7b15db..8d9c110f5bf839dcb7426f7750c09b3ff196bdf3:/include/simgrid/s4u/ActivitySet.hpp diff --git a/include/simgrid/s4u/ActivitySet.hpp b/include/simgrid/s4u/ActivitySet.hpp index 8f9e6ed718..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) {} @@ -40,13 +46,12 @@ public: /** Wait for the completion of all activities in the set, but not longer than the provided timeout * - * On timeout, an exception is raised, and the completed activities remain in the set. Use test_any() to retrieve - * them. + * On timeout, an exception is raised. * - * When no timeout occures, the set is emptied. + * In any case, the completed activities remain in the set. Use test_any() to retrieve them. */ void wait_all_for(double timeout); - /** Wait for the completion of all activities in the set. The set is emptied afterward. */ + /** Wait for the completion of all activities in the set. The set is NOT emptied afterward. */ void wait_all() { wait_all_for(-1); } /** Returns the first terminated activity if any, or ActivityPtr(nullptr) if no activity is terminated */ ActivityPtr test_any(); @@ -73,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