Skip to content

Commit

Permalink
use a mutex to prevent thread conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ullingerc committed Nov 30, 2024
1 parent 456dc02 commit 8f52c76
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/engine/Operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class Operation {
// Add a warning to the `Operation`. The warning will be returned by
// `collectWarnings()` above.
void addWarning(std::string warning) const {
// TODO<ullingerc>
// warnings_.wlock()->push_back(std::move(warning));
std::lock_guard l{warningsMutex_};
warnings_.push_back(std::move(warning));
}

Expand Down Expand Up @@ -256,9 +255,12 @@ class Operation {
[[nodiscard]] virtual vector<ColumnIndex> resultSortedOn() const = 0;

/// interface to the generated warnings of this operation
// TODO<ullingerc>
std::vector<std::string>& getWarnings() { return warnings_; }
std::vector<std::string>& getWarnings() {
std::lock_guard l{warningsMutex_};
return warnings_;
}

Check warning on line 261 in src/engine/Operation.h

View check run for this annotation

Codecov / codecov/patch

src/engine/Operation.h#L258-L261

Added lines #L258 - L261 were not covered by tests
[[nodiscard]] const std::vector<std::string>& getWarnings() const {
std::lock_guard l{warningsMutex_};
return warnings_;
}

Expand Down Expand Up @@ -386,11 +388,11 @@ class Operation {
std::shared_ptr<const RuntimeInformation> _rootRuntimeInfo = _runtimeInfo;
RuntimeInformationWholeQuery _runtimeInfoWholeQuery;

// Mutex that protects the `warnings_` below.
mutable ad_utility::CopyableMutex warningsMutex_;
// Collect all the warnings that were created during the creation or
// execution of this operation. This attribute is declared mutable in order to
// allow const-functions in subclasses of Operation to add warnings.
// TODO<ullingerc> use a
// ad_utility::Synchronized<std::vector<std::string>, std::shared_mutex>?
mutable std::vector<std::string> warnings_;

// The limit from a SPARQL `LIMIT` clause.
Expand Down

0 comments on commit 8f52c76

Please sign in to comment.