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}
This commit is contained in:
jbauch
2016-02-09 02:30:34 -08:00
committed by Commit bot
parent e594213a2b
commit 097d54956d
2 changed files with 19 additions and 9 deletions

View File

@ -741,6 +741,7 @@ StreamResult FifoBuffer::WriteOffset(const void* buffer, size_t bytes,
}
StreamState FifoBuffer::GetState() const {
CritScope cs(&crit_);
return state_;
}

View File

@ -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<char[]> 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<char[]> 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);
};