Protecting Bitrate to avoid data race found by tsan.
TEST=try and vie_auto_test with tsan. R=stefan@webrtc.org Review URL: https://webrtc-codereview.appspot.com/2163004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4673 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
65abb6b1ed
commit
b21e528c60
@ -11,11 +11,13 @@
|
||||
#include "webrtc/modules/rtp_rtcp/source/bitrate.h"
|
||||
|
||||
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
|
||||
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
Bitrate::Bitrate(Clock* clock)
|
||||
: clock_(clock),
|
||||
crit_(CriticalSectionWrapper::CreateCriticalSection()),
|
||||
packet_rate_(0),
|
||||
bitrate_(0),
|
||||
bitrate_next_idx_(0),
|
||||
@ -28,19 +30,23 @@ Bitrate::Bitrate(Clock* clock)
|
||||
}
|
||||
|
||||
void Bitrate::Update(const int32_t bytes) {
|
||||
CriticalSectionScoped cs(crit_.get());
|
||||
bytes_count_ += bytes;
|
||||
packet_count_++;
|
||||
}
|
||||
|
||||
uint32_t Bitrate::PacketRate() const {
|
||||
CriticalSectionScoped cs(crit_.get());
|
||||
return packet_rate_;
|
||||
}
|
||||
|
||||
uint32_t Bitrate::BitrateLast() const {
|
||||
CriticalSectionScoped cs(crit_.get());
|
||||
return bitrate_;
|
||||
}
|
||||
|
||||
uint32_t Bitrate::BitrateNow() const {
|
||||
CriticalSectionScoped cs(crit_.get());
|
||||
int64_t now = clock_->TimeInMilliseconds();
|
||||
int64_t diff_ms = now - time_last_rate_update_;
|
||||
|
||||
@ -58,11 +64,13 @@ uint32_t Bitrate::BitrateNow() const {
|
||||
}
|
||||
|
||||
int64_t Bitrate::time_last_rate_update() const {
|
||||
CriticalSectionScoped cs(crit_.get());
|
||||
return time_last_rate_update_;
|
||||
}
|
||||
|
||||
void Bitrate::Process() {
|
||||
// Triggered by timer.
|
||||
CriticalSectionScoped cs(crit_.get());
|
||||
int64_t now = clock_->TimeInMilliseconds();
|
||||
int64_t diff_ms = now - time_last_rate_update_;
|
||||
|
||||
|
@ -17,11 +17,13 @@
|
||||
|
||||
#include "webrtc/common_types.h"
|
||||
#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
|
||||
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class Clock;
|
||||
class CriticalSectionWrapper;
|
||||
|
||||
class Bitrate {
|
||||
public:
|
||||
@ -48,6 +50,7 @@ class Bitrate {
|
||||
Clock* clock_;
|
||||
|
||||
private:
|
||||
scoped_ptr<CriticalSectionWrapper> crit_;
|
||||
uint32_t packet_rate_;
|
||||
uint32_t bitrate_;
|
||||
uint8_t bitrate_next_idx_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user