diff --git a/libs/core/errors/include/hpx/errors/exception_list.hpp b/libs/core/errors/include/hpx/errors/exception_list.hpp index c958d3ef431..df259287a75 100644 --- a/libs/core/errors/include/hpx/errors/exception_list.hpp +++ b/libs/core/errors/include/hpx/errors/exception_list.hpp @@ -26,7 +26,7 @@ namespace hpx { /// The class exception_list is a container of exception_ptr objects /// parallel algorithms may use to communicate uncaught exceptions - /// encountered during parallel execution to the caller of the algorithm. + /// encountered during parallel execution to the caller of the algorithm /// /// The type exception_list::const_iterator fulfills the requirements of /// a forward iterator. @@ -34,58 +34,59 @@ namespace hpx { class HPX_CORE_EXPORT exception_list : public hpx::exception { private: - using mutex_type = hpx::spinlock; // Use hpx::spinlock for thread safety + /// \cond NOINTERNAL + + // TODO: Does this need to be hpx::spinlock? + // typedef hpx::spinlock mutex_type; + // TODO: Add correct initialization of hpx::util::detail spinlock. + using mutex_type = hpx::util::detail::spinlock; + using exception_list_type = std::list; - - exception_list_type exceptions_; // Holds the list of exceptions - mutable mutex_type mtx_; // Mutex for thread-safe access + exception_list_type exceptions_; + mutable mutex_type mtx_; - // Internal function to add an exception without locking void add_no_lock(std::exception_ptr const& e) { exceptions_.push_back(e); } + /// \endcond public: - /// Bidirectional iterator type for the exception list + /// bidirectional iterator using iterator = exception_list_type::const_iterator; + /// \cond NOINTERNAL + // \throws nothing ~exception_list() noexcept override = default; - // Default constructor exception_list() = default; - // Constructor that adds an initial exception explicit exception_list(std::exception_ptr const& e) { add(e); } - // Move constructor that transfers ownership of exceptions explicit exception_list(exception_list_type&& l) { std::lock_guard lock(mtx_); exceptions_ = std::move(l); } - // Copy constructor with thread-safe access - exception_list(exception_list const& l) + exception_list(exception_list const& l) : hpx::exception(l) { std::lock_guard lock(l.mtx_); exceptions_ = l.exceptions_; } - // Move constructor with thread-safe access - exception_list(exception_list&& l) noexcept + exception_list(exception_list&& l) noexcept : hpx::exception(std::move(l)) { - std::lock_guard lock(l.mtx_); + std::lock_guard l_lock(l.mtx_); exceptions_ = std::move(l.exceptions_); } - // Copy assignment operator with thread-safe access exception_list& operator=(exception_list const& l) { - if (this != &l) { // Avoid self-assignment + if (this != &l) { std::lock_guard this_lock(mtx_); std::lock_guard l_lock(l.mtx_); exceptions_ = l.exceptions_; @@ -93,10 +94,9 @@ namespace hpx { return *this; } - // Move assignment operator with thread-safe access exception_list& operator=(exception_list&& l) noexcept { - if (this != &l) { // Avoid self-assignment + if (this != &l) { std::lock_guard this_lock(mtx_); std::lock_guard l_lock(l.mtx_); exceptions_ = std::move(l.exceptions_); @@ -104,47 +104,50 @@ namespace hpx { return *this; } - // Adds an exception to the list in a thread-safe manner void add(std::exception_ptr const& e) { - std::lock_guard lock(mtx_); + std::lock_guard l(mtx_); add_no_lock(e); } + /// \endcond - /// Returns the number of exception_ptr objects in the exception_list. - /// Complexity: Constant time. + /// The number of exception_ptr objects contained within the + /// exception_list. + /// + /// \note Complexity: Constant time. [[nodiscard]] std::size_t size() const noexcept { - std::lock_guard lock(mtx_); + std::lock_guard l(mtx_); return exceptions_.size(); } - /// Returns an iterator referring to the first exception_ptr object. + /// An iterator referring to the first exception_ptr object contained + /// within the exception_list. [[nodiscard]] exception_list_type::const_iterator begin() const noexcept { - std::lock_guard lock(mtx_); + std::lock_guard l(mtx_); return exceptions_.begin(); } - /// Returns a past-the-end iterator for the exception_list. + /// An iterator which is the past-the-end value for the exception_list. [[nodiscard]] exception_list_type::const_iterator end() const noexcept { - std::lock_guard lock(mtx_); + std::lock_guard l(mtx_); return exceptions_.end(); } - // Placeholder for retrieving an error code + /// \cond NOINTERNAL [[nodiscard]] std::error_code get_error_code() const { - return std::error_code(); // Placeholder implementation + return std::error_code(); // placeholder implementation } - // Placeholder for retrieving an exception message [[nodiscard]] std::string get_message() const { - return "Exception occurred"; // Placeholder implementation + return "Exception occurred"; // placeholder implementation } + /// \endcond }; -} // namespace hpx +} // namespace hpx #include