From 064b32acbb9ae0152918d6770ff98d2ba60d20e4 Mon Sep 17 00:00:00 2001 From: "pbos@webrtc.org" Date: Tue, 4 Feb 2014 09:42:02 +0000 Subject: [PATCH] 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 --- .../fixtures/after_initialization_fixture.h | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h b/webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h index e854120ecb..452ca956d8 100644 --- a/webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h +++ b/webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h @@ -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(transport)->SendPackets(); } @@ -112,8 +108,8 @@ class LoopBackTransport : public webrtc::Transport { webrtc::scoped_ptr crit_; webrtc::scoped_ptr packet_event_; webrtc::scoped_ptr thread_; - std::deque packet_queue_; - webrtc::VoENetwork* voe_network_; + std::deque 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 error_observer_; };