Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromecast/media/cma/ipc/media_message_fifo.h" | 5 #include "chromecast/media/cma/ipc/media_message_fifo.h" |
| 6 | 6 |
| 7 #include "base/atomicops.h" | 7 #include "base/atomicops.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 rd_offset_ = reinterpret_cast<AtomicSize*>(&(desc->rd_offset)); | 116 rd_offset_ = reinterpret_cast<AtomicSize*>(&(desc->rd_offset)); |
| 117 wr_offset_ = reinterpret_cast<AtomicSize*>(&(desc->wr_offset)); | 117 wr_offset_ = reinterpret_cast<AtomicSize*>(&(desc->wr_offset)); |
| 118 | 118 |
| 119 size_t max_size = mem_->size() - | 119 size_t max_size = mem_->size() - |
| 120 (static_cast<char*>(base_) - static_cast<char*>(mem_->data())); | 120 (static_cast<char*>(base_) - static_cast<char*>(mem_->data())); |
| 121 if (init) { | 121 if (init) { |
| 122 size_ = max_size; | 122 size_ = max_size; |
| 123 desc->size = size_; | 123 desc->size = size_; |
| 124 internal_rd_offset_ = 0; | 124 internal_rd_offset_ = 0; |
| 125 internal_wr_offset_ = 0; | 125 internal_wr_offset_ = 0; |
| 126 base::subtle::Acquire_Store(rd_offset_, 0); | 126 base::subtle::Release_Store(rd_offset_, 0); |
|
servolk
2014/10/07 19:43:37
The bug referenced in the description (https://cod
lcwu1
2014/10/07 21:30:17
No, the bug was talking about removing Acquire_Sto
| |
| 127 base::subtle::Acquire_Store(wr_offset_, 0); | 127 base::subtle::Release_Store(wr_offset_, 0); |
| 128 } else { | 128 } else { |
| 129 size_ = desc->size; | 129 size_ = desc->size; |
| 130 CHECK_LE(size_, max_size); | 130 CHECK_LE(size_, max_size); |
| 131 internal_rd_offset_ = current_rd_offset(); | 131 internal_rd_offset_ = current_rd_offset(); |
| 132 internal_wr_offset_ = current_wr_offset(); | 132 internal_wr_offset_ = current_wr_offset(); |
| 133 } | 133 } |
| 134 CMALOG(kLogControl) | 134 CMALOG(kLogControl) |
| 135 << "MediaMessageFifo:" << " init=" << init << " size=" << size_; | 135 << "MediaMessageFifo:" << " init=" << init << " size=" << size_; |
| 136 CHECK_GT(size_, 0) << size_; | 136 CHECK_GT(size_, 0) << size_; |
| 137 | 137 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 size_t wr_offset = base::subtle::Acquire_Load(wr_offset_); | 363 size_t wr_offset = base::subtle::Acquire_Load(wr_offset_); |
| 364 CHECK_LT(wr_offset, size_); | 364 CHECK_LT(wr_offset, size_); |
| 365 return wr_offset; | 365 return wr_offset; |
| 366 } | 366 } |
| 367 | 367 |
| 368 void MediaMessageFifo::CommitRead(size_t new_rd_offset) { | 368 void MediaMessageFifo::CommitRead(size_t new_rd_offset) { |
| 369 // Add a memory fence to ensure the message content is completely read | 369 // Add a memory fence to ensure the message content is completely read |
| 370 // before updating the read offset. | 370 // before updating the read offset. |
| 371 base::subtle::Release_Store(rd_offset_, new_rd_offset); | 371 base::subtle::Release_Store(rd_offset_, new_rd_offset); |
| 372 | 372 |
| 373 // Make sure the read pointer has been updated before sending a notification. | 373 // Make sure the read pointer has been updated before sending a notification. |
|
damienv1
2014/10/07 19:22:31
The comment should be updated (just to mention it'
lcwu1
2014/10/07 21:30:17
Done.
| |
| 374 if (!read_event_cb_.is_null()) { | 374 if (!read_event_cb_.is_null()) { |
| 375 base::subtle::MemoryBarrier(); | |
| 376 read_event_cb_.Run(); | 375 read_event_cb_.Run(); |
| 377 } | 376 } |
| 378 } | 377 } |
| 379 | 378 |
| 380 void MediaMessageFifo::CommitWrite(size_t new_wr_offset) { | 379 void MediaMessageFifo::CommitWrite(size_t new_wr_offset) { |
| 381 // Add a memory fence to ensure the message content is written | 380 // Add a memory fence to ensure the message content is written |
| 382 // before updating the write offset. | 381 // before updating the write offset. |
| 383 base::subtle::Release_Store(wr_offset_, new_wr_offset); | 382 base::subtle::Release_Store(wr_offset_, new_wr_offset); |
| 384 | 383 |
| 385 // Make sure the write pointer has been updated before sending a notification. | 384 // Make sure the write pointer has been updated before sending a notification. |
|
damienv1
2014/10/07 19:22:30
Same: update the comment.
Also, could you please m
lcwu1
2014/10/07 21:30:17
Ran Tsan on cast_media_unittests and everything is
| |
| 386 if (!write_event_cb_.is_null()) { | 385 if (!write_event_cb_.is_null()) { |
| 387 base::subtle::MemoryBarrier(); | |
| 388 write_event_cb_.Run(); | 386 write_event_cb_.Run(); |
| 389 } | 387 } |
| 390 } | 388 } |
| 391 | 389 |
| 392 void MediaMessageFifo::CommitInternalRead(size_t new_rd_offset) { | 390 void MediaMessageFifo::CommitInternalRead(size_t new_rd_offset) { |
| 393 internal_rd_offset_ = new_rd_offset; | 391 internal_rd_offset_ = new_rd_offset; |
| 394 } | 392 } |
| 395 | 393 |
| 396 void MediaMessageFifo::CommitInternalWrite(size_t new_wr_offset) { | 394 void MediaMessageFifo::CommitInternalWrite(size_t new_wr_offset) { |
| 397 internal_wr_offset_ = new_wr_offset; | 395 internal_wr_offset_ = new_wr_offset; |
| 398 } | 396 } |
| 399 | 397 |
| 400 } // namespace media | 398 } // namespace media |
| 401 } // namespace chromecast | 399 } // namespace chromecast |
| OLD | NEW |