From a9bc54a3a92c437b101794a062fb6c28404f929d Mon Sep 17 00:00:00 2001 From: Ahmed Moussa Date: Tue, 27 Aug 2024 21:28:32 +0000 Subject: [PATCH 2/2] no-consume --- .../src/mediapipe/framework/packet.h | 73 +------------------ 1 file changed, 3 insertions(+), 70 deletions(-) diff --git a/third_party/mediapipe/src/mediapipe/framework/packet.h b/third_party/mediapipe/src/mediapipe/framework/packet.h index ef0b5d113925b..a5501848e9f2b 100644 --- a/third_party/mediapipe/src/mediapipe/framework/packet.h +++ b/third_party/mediapipe/src/mediapipe/framework/packet.h @@ -691,53 +691,14 @@ inline Packet& Packet::operator=(const Packet& packet) { template inline absl::StatusOr> Packet::Consume() { - // If type validation fails, returns error. - MP_RETURN_IF_ERROR(ValidateAsType()); - // Clients who use this function are responsible for ensuring that no - // other thread is doing anything with this Packet. - if (!holder_->HasForeignOwner() && holder_.use_count() == 1) { - VLOG(2) << "Consuming the data of " << DebugString(); - absl::StatusOr> release_result = - holder_->AsMutable()->Release(); - if (release_result.ok()) { - VLOG(2) << "Setting " << DebugString() << " to empty."; - holder_.reset(); - } - return release_result; - } - // If packet isn't the sole owner of the holder, returns kFailedPrecondition - // error with message. - return absl::Status(absl::StatusCode::kFailedPrecondition, - "Packet isn't the sole owner of the holder."); + return absl::InternalError("Consume isn't supported."); } template inline absl::StatusOr> Packet::ConsumeOrCopy( bool* was_copied, typename std::enable_if::value>::type*) { - MP_RETURN_IF_ERROR(ValidateAsType()); - // If holder is the sole owner of the underlying data, consumes this packet. - if (!holder_->HasForeignOwner() && holder_.use_count() == 1) { - VLOG(2) << "Consuming the data of " << DebugString(); - absl::StatusOr> release_result = - holder_->AsMutable()->Release(); - if (release_result.ok()) { - VLOG(2) << "Setting " << DebugString() << " to empty."; - holder_.reset(); - } - if (was_copied) { - *was_copied = false; - } - return release_result; - } - VLOG(2) << "Copying the data of " << DebugString(); - std::unique_ptr data_ptr = absl::make_unique(Get()); - VLOG(2) << "Setting " << DebugString() << " to empty."; - holder_.reset(); - if (was_copied) { - *was_copied = true; - } - return std::move(data_ptr); + return absl::InternalError("ConsumeOrCopy isn't supported."); } template @@ -745,35 +706,7 @@ inline absl::StatusOr> Packet::ConsumeOrCopy( bool* was_copied, typename std::enable_if::value && std::extent::value != 0>::type*) { - MP_RETURN_IF_ERROR(ValidateAsType()); - // If holder is the sole owner of the underlying data, consumes this packet. - if (!holder_->HasForeignOwner() && holder_.use_count() == 1) { - VLOG(2) << "Consuming the data of " << DebugString(); - absl::StatusOr> release_result = - holder_->AsMutable()->Release(); - if (release_result.ok()) { - VLOG(2) << "Setting " << DebugString() << " to empty."; - holder_.reset(); - } - if (was_copied) { - *was_copied = false; - } - return release_result; - } - VLOG(2) << "Copying the data of " << DebugString(); - const auto& original_array = Get(); - // Type T is bounded array type, such as int[N] and float[M]. - // The new operator creates a new bounded array. - std::unique_ptr data_ptr(reinterpret_cast(new T)); - // Copies bounded array data into data_ptr. - std::copy(std::begin(original_array), std::end(original_array), - std::begin(*data_ptr)); - VLOG(2) << "Setting " << DebugString() << " to empty."; - holder_.reset(); - if (was_copied) { - *was_copied = true; - } - return std::move(data_ptr); + return absl::InternalError("ConsumeOrCopy isn't supported."); } template -- 2.46.0.295.g3b9ea8a38a-goog