Fix locking in LoopBackTransport::StorePacket.

The critical section in StorePacket was unnamed and only existed in
expression scope. Added GUARDED_BY annotations (which caught the bug),
then fixed it by naming the variable.

BUG=2880
R=henrika@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/7979004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5484 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
pbos@webrtc.org 2014-02-04 09:42:02 +00:00
parent 36291da197
commit 064b32acbb

View File

@ -32,27 +32,22 @@ class LoopBackTransport : public webrtc::Transport {
unsigned int id;
thread_->Start(id);
}
~LoopBackTransport() {
thread_->Stop();
}
virtual int SendPacket(int channel, const void *data, int len) {
~LoopBackTransport() { thread_->Stop(); }
virtual int SendPacket(int channel, const void* data, int len) {
StorePacket(Packet::Rtp, channel, data, len);
return len;
}
virtual int SendRTCPPacket(int channel, const void *data, int len) {
virtual int SendRTCPPacket(int channel, const void* data, int len) {
StorePacket(Packet::Rtcp, channel, data, len);
return len;
}
private:
struct Packet {
enum Type {
Rtp,
Rtcp,
} type;
enum Type { Rtp, Rtcp, } type;
Packet() : len(0) {}
Packet(Type type, int channel, const void* data, int len)
@ -67,10 +62,11 @@ class LoopBackTransport : public webrtc::Transport {
};
void StorePacket(Packet::Type type, int channel, const void* data, int len) {
webrtc::CriticalSectionScoped(crit_.get());
webrtc::CriticalSectionScoped lock(crit_.get());
packet_queue_.push_back(Packet(type, channel, data, len));
packet_event_->Set();
}
static bool NetworkProcess(void* transport) {
return static_cast<LoopBackTransport*>(transport)->SendPackets();
}
@ -112,8 +108,8 @@ class LoopBackTransport : public webrtc::Transport {
webrtc::scoped_ptr<webrtc::CriticalSectionWrapper> crit_;
webrtc::scoped_ptr<webrtc::EventWrapper> packet_event_;
webrtc::scoped_ptr<webrtc::ThreadWrapper> thread_;
std::deque<Packet> packet_queue_;
webrtc::VoENetwork* voe_network_;
std::deque<Packet> packet_queue_ GUARDED_BY(crit_.get());
webrtc::VoENetwork* const voe_network_;
};
// This fixture initializes the voice engine in addition to the work
@ -125,6 +121,7 @@ class AfterInitializationFixture : public BeforeInitializationFixture {
public:
AfterInitializationFixture();
virtual ~AfterInitializationFixture();
protected:
webrtc::scoped_ptr<TestErrorObserver> error_observer_;
};