Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Unified Diff: mojo/system/local_data_pipe.cc

Issue 98013005: Mojo: DataPipe: Implement "may discard" mode for simple writes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove todo Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/system/data_pipe.cc ('k') | mojo/system/local_data_pipe_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/system/local_data_pipe.cc
diff --git a/mojo/system/local_data_pipe.cc b/mojo/system/local_data_pipe.cc
index 936c68c4b80a0995074ff82c7f50c5351cbc84e8..36ba55272e7b51f2d31c5073313fb78a673a76fb 100644
--- a/mojo/system/local_data_pipe.cc
+++ b/mojo/system/local_data_pipe.cc
@@ -51,13 +51,30 @@ MojoResult LocalDataPipe::ProducerWriteDataImplNoLock(const void* elements,
DCHECK_EQ(*num_bytes % element_num_bytes(), 0u);
DCHECK_GT(*num_bytes, 0u);
- // TODO(vtl): Consider this return value.
- if (all_or_none && *num_bytes > capacity_num_bytes() - current_num_bytes_)
- return MOJO_RESULT_OUT_OF_RANGE;
-
- size_t num_bytes_to_write =
- std::min(static_cast<size_t>(*num_bytes),
- capacity_num_bytes() - current_num_bytes_);
+ size_t num_bytes_to_write = 0;
+ if (may_discard()) {
+ if (all_or_none && *num_bytes > capacity_num_bytes())
+ return MOJO_RESULT_OUT_OF_RANGE;
+
+ num_bytes_to_write = std::min(static_cast<size_t>(*num_bytes),
+ capacity_num_bytes());
+ if (num_bytes_to_write > capacity_num_bytes() - current_num_bytes_) {
+ // Discard as much as needed (discard oldest first).
+ size_t num_bytes_to_discard =
+ num_bytes_to_write - (capacity_num_bytes() - current_num_bytes_);
+ start_index_ += num_bytes_to_discard;
+ start_index_ %= capacity_num_bytes();
+ current_num_bytes_ -= num_bytes_to_discard;
+ }
+ } else {
+ if (all_or_none && *num_bytes > capacity_num_bytes() - current_num_bytes_) {
+ return (*num_bytes > capacity_num_bytes()) ? MOJO_RESULT_OUT_OF_RANGE :
+ MOJO_RESULT_SHOULD_WAIT;
+ }
+
+ num_bytes_to_write = std::min(static_cast<size_t>(*num_bytes),
+ capacity_num_bytes() - current_num_bytes_);
+ }
if (num_bytes_to_write == 0)
return MOJO_RESULT_SHOULD_WAIT;
« no previous file with comments | « mojo/system/data_pipe.cc ('k') | mojo/system/local_data_pipe_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698