From 097d54956dfd2cc3a5983f07a0e35d2c46afac27 Mon Sep 17 00:00:00 2001 From: jbauch Date: Tue, 9 Feb 2016 02:30:34 -0800 Subject: [PATCH] Added thread annotations to FifoBuffer. This CL adds thread annotations to FifoBuffer and adds a missing CritScope for attribute access that is modified in locked code paths. Review URL: https://codereview.webrtc.org/1677333002 Cr-Commit-Position: refs/heads/master@{#11535} --- webrtc/base/stream.cc | 1 + webrtc/base/stream.h | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/webrtc/base/stream.cc b/webrtc/base/stream.cc index e22c3d8aa4..1ddff1cf0a 100644 --- a/webrtc/base/stream.cc +++ b/webrtc/base/stream.cc @@ -741,6 +741,7 @@ StreamResult FifoBuffer::WriteOffset(const void* buffer, size_t bytes, } StreamState FifoBuffer::GetState() const { + CritScope cs(&crit_); return state_; } diff --git a/webrtc/base/stream.h b/webrtc/base/stream.h index 98123b8211..e624df5504 100644 --- a/webrtc/base/stream.h +++ b/webrtc/base/stream.h @@ -542,20 +542,29 @@ class FifoBuffer : public StreamInterface { // Helper method that implements ReadOffset. Caller must acquire a lock // when calling this method. StreamResult ReadOffsetLocked(void* buffer, size_t bytes, size_t offset, - size_t* bytes_read); + size_t* bytes_read) + EXCLUSIVE_LOCKS_REQUIRED(crit_); // Helper method that implements WriteOffset. Caller must acquire a lock // when calling this method. StreamResult WriteOffsetLocked(const void* buffer, size_t bytes, - size_t offset, size_t* bytes_written); + size_t offset, size_t* bytes_written) + EXCLUSIVE_LOCKS_REQUIRED(crit_); - StreamState state_; // keeps the opened/closed state of the stream - scoped_ptr buffer_; // the allocated buffer - size_t buffer_length_; // size of the allocated buffer - size_t data_length_; // amount of readable data in the buffer - size_t read_position_; // offset to the readable data - Thread* owner_; // stream callbacks are dispatched on this thread - CriticalSection crit_; // object lock + // keeps the opened/closed state of the stream + StreamState state_ GUARDED_BY(crit_); + // the allocated buffer + scoped_ptr buffer_ GUARDED_BY(crit_); + // size of the allocated buffer + size_t buffer_length_ GUARDED_BY(crit_); + // amount of readable data in the buffer + size_t data_length_ GUARDED_BY(crit_); + // offset to the readable data + size_t read_position_ GUARDED_BY(crit_); + // stream callbacks are dispatched on this thread + Thread* owner_; + // object lock + CriticalSection crit_; RTC_DISALLOW_COPY_AND_ASSIGN(FifoBuffer); };