Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-45144: [C++] use std::atomic<std::shared_ptr> instead of std::atomic_load()/std::atomic_store() #45145

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cpp/src/arrow/array/array_nested.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ const ArrayVector& StructArray::fields() const {
}

const std::shared_ptr<Array>& StructArray::field(int i) const {
std::shared_ptr<Array> result = std::atomic_load(&boxed_fields_[i]);
std::shared_ptr<Array> result = std::atomic(&boxed_fields_[i]);
if (!result) {
std::shared_ptr<ArrayData> field_data;
if (data_->offset != 0 || data_->child_data[i]->length != data_->length) {
Expand All @@ -1086,7 +1086,7 @@ const std::shared_ptr<Array>& StructArray::field(int i) const {
field_data = data_->child_data[i];
}
result = MakeArray(field_data);
std::atomic_store(&boxed_fields_[i], std::move(result));
std::atomic(&boxed_fields_[i], std::move(result));
return boxed_fields_[i];
}
return boxed_fields_[i];
Expand Down Expand Up @@ -1357,7 +1357,7 @@ std::shared_ptr<Array> UnionArray::field(int i) const {
static_cast<decltype(boxed_fields_)::size_type>(i) >= boxed_fields_.size()) {
return nullptr;
}
std::shared_ptr<Array> result = std::atomic_load(&boxed_fields_[i]);
std::shared_ptr<Array> result = std::atomic(&boxed_fields_[i]);
if (!result) {
std::shared_ptr<ArrayData> child_data = data_->child_data[i]->Copy();
if (mode() == UnionMode::SPARSE) {
Expand All @@ -1369,7 +1369,7 @@ std::shared_ptr<Array> UnionArray::field(int i) const {
}
}
result = MakeArray(child_data);
std::atomic_store(&boxed_fields_[i], result);
std::atomic(&boxed_fields_[i], result);
}
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/filesystem/s3fs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ class RegionResolver {
}

static Result<std::shared_ptr<RegionResolver>> DefaultInstance() {
auto resolver = std::atomic_load(&instance_);
auto resolver = std::atomic(&instance_);
if (resolver) {
return resolver;
}
Expand All @@ -1239,7 +1239,7 @@ class RegionResolver {
}

static void ResetDefaultInstance() {
std::atomic_store(&instance_, std::shared_ptr<RegionResolver>());
std::atomic(&instance_, std::shared_ptr<RegionResolver>());
}

Result<std::string> ResolveRegion(const std::string& bucket) {
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/record_batch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ class SimpleRecordBatch : public RecordBatch {
}

std::shared_ptr<Array> column(int i) const override {
std::shared_ptr<Array> result = std::atomic_load(&boxed_columns_[i]);
std::shared_ptr<Array> result = std::atomic(&boxed_columns_[i]);
if (!result) {
result = MakeArray(columns_[i]);
std::atomic_store(&boxed_columns_[i], result);
std::atomic(&boxed_columns_[i], result);
}
return result;
}
Expand Down
Loading