Remove dependency on ConditionVariableWrapper and CriticalSectionWrapper in UdpSocketPosix.

This is a part of cleaning up 'friend' parts of ConditionVariableWrapper's implementation where it accesses private variables of CriticalSectionWrapper, which is not good since it makes assumptions about the implementation on all posix platforms.
Instead I'm using rtc::Event, another condition variable based implementation we have, and fits the requirements of UdpSocketPosix.

BUG=
R=pbos@webrtc.org

Review URL: https://codereview.webrtc.org/1591333002 .

Cr-Commit-Position: refs/heads/master@{#11295}
This commit is contained in:
Tommi 2016-01-18 20:35:39 +01:00
parent 233bfd2da4
commit 2067826a5e
3 changed files with 23 additions and 40 deletions

View File

@ -23,9 +23,6 @@
#include "webrtc/test/channel_transport/udp_socket_wrapper.h"
namespace webrtc {
class ConditionVariableWrapper;
namespace test {
class UdpSocketPosix;

View File

@ -27,7 +27,10 @@
namespace webrtc {
namespace test {
UdpSocketPosix::UdpSocketPosix(const int32_t id, UdpSocketManager* mgr,
bool ipV6Enable) : _id(id)
bool ipV6Enable)
: _id(id),
_closeBlockingCompletedCond(true, false),
_readyForDeletionCond(true, false)
{
WEBRTC_TRACE(kTraceMemory, kTraceTransport, id,
"UdpSocketPosix::UdpSocketPosix()");
@ -37,13 +40,9 @@ UdpSocketPosix::UdpSocketPosix(const int32_t id, UdpSocketManager* mgr,
_obj = NULL;
_incomingCb = NULL;
_readyForDeletionCond = ConditionVariableWrapper::CreateConditionVariable();
_closeBlockingCompletedCond =
ConditionVariableWrapper::CreateConditionVariable();
_cs = CriticalSectionWrapper::CreateCriticalSection();
_readyForDeletion = false;
_closeBlockingActive = false;
_closeBlockingCompleted= false;
_closeBlockingCompleted = false;
if(ipV6Enable)
{
_socket = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
@ -75,20 +74,6 @@ UdpSocketPosix::~UdpSocketPosix()
close(_socket);
_socket = INVALID_SOCKET;
}
if(_readyForDeletionCond)
{
delete _readyForDeletionCond;
}
if(_closeBlockingCompletedCond)
{
delete _closeBlockingCompletedCond;
}
if(_cs)
{
delete _cs;
}
}
bool UdpSocketPosix::SetCallback(CallbackObj obj, IncomingSocketCallback cb)
@ -227,41 +212,42 @@ bool UdpSocketPosix::WantsIncoming() { return _wantsIncoming; }
void UdpSocketPosix::CloseBlocking()
{
_cs->Enter();
rtc::CritScope lock(&_cs);
_closeBlockingActive = true;
if(!CleanUp())
{
_closeBlockingActive = false;
_cs->Leave();
return;
}
while(!_readyForDeletion)
if(!_readyForDeletion)
{
_readyForDeletionCond->SleepCS(*_cs);
_cs.Leave();
_readyForDeletionCond.Wait(rtc::Event::kForever);
_cs.Enter();
}
_closeBlockingCompleted = true;
_closeBlockingCompletedCond->Wake();
_cs->Leave();
_closeBlockingCompletedCond.Set();
}
void UdpSocketPosix::ReadyForDeletion()
{
_cs->Enter();
rtc::CritScope lock(&_cs);
if(!_closeBlockingActive)
{
_cs->Leave();
return;
}
close(_socket);
_socket = INVALID_SOCKET;
_readyForDeletion = true;
_readyForDeletionCond->Wake();
while(!_closeBlockingCompleted)
_readyForDeletionCond.Set();
if(!_closeBlockingCompleted)
{
_closeBlockingCompletedCond->SleepCS(*_cs);
_cs.Leave();
_closeBlockingCompletedCond.Wait(rtc::Event::kForever);
_cs.Enter();
}
_cs->Leave();
}
bool UdpSocketPosix::CleanUp()

View File

@ -16,8 +16,8 @@
#include <sys/socket.h>
#include <sys/types.h>
#include "webrtc/system_wrappers/include/condition_variable_wrapper.h"
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
#include "webrtc/base/event.h"
#include "webrtc/base/criticalsection.h"
#include "webrtc/test/channel_transport/udp_socket_wrapper.h"
namespace webrtc {
@ -78,14 +78,14 @@ private:
SOCKET _socket;
UdpSocketManager* _mgr;
ConditionVariableWrapper* _closeBlockingCompletedCond;
ConditionVariableWrapper* _readyForDeletionCond;
rtc::Event _closeBlockingCompletedCond;
rtc::Event _readyForDeletionCond;
bool _closeBlockingActive;
bool _closeBlockingCompleted;
bool _readyForDeletion;
CriticalSectionWrapper* _cs;
rtc::CriticalSection _cs;
};
} // namespace test