From a9bc54a3a92c437b101794a062fb6c28404f929d Mon Sep 17 00:00:00 2001
From: Ahmed Moussa <[email protected]>
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 <typename T>
inline absl::StatusOr<std::unique_ptr<T>> Packet::Consume() {
- // If type validation fails, returns error.
- MP_RETURN_IF_ERROR(ValidateAsType<T>());
- // 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<std::unique_ptr<T>> release_result =
- holder_->AsMutable<T>()->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 <typename T>
inline absl::StatusOr<std::unique_ptr<T>> Packet::ConsumeOrCopy(
bool* was_copied,
typename std::enable_if<!std::is_array<T>::value>::type*) {
- MP_RETURN_IF_ERROR(ValidateAsType<T>());
- // 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<std::unique_ptr<T>> release_result =
- holder_->AsMutable<T>()->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<T> data_ptr = absl::make_unique<T>(Get<T>());
- 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 <typename T>
@@ -745,35 +706,7 @@ inline absl::StatusOr<std::unique_ptr<T>> Packet::ConsumeOrCopy(
bool* was_copied,
typename std::enable_if<std::is_array<T>::value &&
std::extent<T>::value != 0>::type*) {
- MP_RETURN_IF_ERROR(ValidateAsType<T>());
- // 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<std::unique_ptr<T>> release_result =
- holder_->AsMutable<T>()->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<T>();
- // Type T is bounded array type, such as int[N] and float[M].
- // The new operator creates a new bounded array.
- std::unique_ptr<T> data_ptr(reinterpret_cast<T*>(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 <typename T>
--
2.46.0.295.g3b9ea8a38a-goog