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/webrtc@5484 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h b/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h
index e854120..452ca95 100644
--- a/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h
+++ b/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h
@@ -32,27 +32,22 @@
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 @@
};
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 @@
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 @@
public:
AfterInitializationFixture();
virtual ~AfterInitializationFixture();
+
protected:
webrtc::scoped_ptr<TestErrorObserver> error_observer_;
};