Remove use of ConditionVariableWrapper and CriticalSectionWrapper from UdpSocket2Windows.

This helps with untangling CriticalSectionWrapper from ConditionVariableWrapper and looks like we can just delete ConditionVariableWrapper and use rtc::Event instead.

BUG=
R=pbos@webrtc.org

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

Cr-Commit-Position: refs/heads/master@{#11309}
This commit is contained in:
Tommi 2016-01-19 22:49:49 +01:00
parent cd255cc07b
commit f01ea4f847
2 changed files with 7 additions and 33 deletions

View File

@ -50,7 +50,7 @@ UdpSocket2Windows::UdpSocket2Windows(const int32_t id,
_outstandingCallComplete(0), _outstandingCallComplete(0),
_terminate(false), _terminate(false),
_addedToMgr(false), _addedToMgr(false),
_safeTodelete(false), delete_event_(true, false),
_outstandingCallsDisabled(false), _outstandingCallsDisabled(false),
_clientHandle(NULL), _clientHandle(NULL),
_flowHandle(NULL), _flowHandle(NULL),
@ -69,12 +69,9 @@ UdpSocket2Windows::UdpSocket2Windows(const int32_t id,
_obj = NULL; _obj = NULL;
_incomingCb = NULL; _incomingCb = NULL;
_socket = INVALID_SOCKET; _socket = INVALID_SOCKET;
_pCrit = CriticalSectionWrapper::CreateCriticalSection();
_ptrCbRWLock = RWLockWrapper::CreateRWLock(); _ptrCbRWLock = RWLockWrapper::CreateRWLock();
_ptrDestRWLock = RWLockWrapper::CreateRWLock(); _ptrDestRWLock = RWLockWrapper::CreateRWLock();
_ptrSocketRWLock = RWLockWrapper::CreateRWLock(); _ptrSocketRWLock = RWLockWrapper::CreateRWLock();
_ptrDeleteCrit = CriticalSectionWrapper::CreateCriticalSection();
_ptrDeleteCond = ConditionVariableWrapper::CreateConditionVariable();
// Check if QoS is supported. // Check if QoS is supported.
BOOL bProtocolFound = FALSE; BOOL bProtocolFound = FALSE;
@ -185,17 +182,13 @@ UdpSocket2Windows::~UdpSocket2Windows()
WEBRTC_TRACE(kTraceMemory, kTraceTransport, _id, WEBRTC_TRACE(kTraceMemory, kTraceTransport, _id,
"UdpSocket2Windows::~UdpSocket2Windows()"); "UdpSocket2Windows::~UdpSocket2Windows()");
WaitForOutstandingCalls(); delete_event_.Wait(rtc::Event::kForever);
delete _ptrCbRWLock; delete _ptrCbRWLock;
delete _ptrDeleteCrit;
delete _ptrDeleteCond;
delete _ptrDestRWLock; delete _ptrDestRWLock;
delete _ptrSocketRWLock; delete _ptrSocketRWLock;
if(_pCrit)
delete _pCrit;
if (_flow) if (_flow)
{ {
free(_flow); free(_flow);
@ -667,7 +660,6 @@ void UdpSocket2Windows::CloseBlocking()
// Reclaims the socket and prevents it from being used again. // Reclaims the socket and prevents it from being used again.
InvalidateSocket(); InvalidateSocket();
DisableNewOutstandingCalls(); DisableNewOutstandingCalls();
WaitForOutstandingCalls();
delete this; delete this;
} }
@ -1279,9 +1271,7 @@ void UdpSocket2Windows::OutstandingCallCompleted()
{ {
// Only one thread will enter here. The thread with the last outstanding // Only one thread will enter here. The thread with the last outstanding
// call. // call.
CriticalSectionScoped cs(_ptrDeleteCrit); delete_event_.Set();
_safeTodelete = true;
_ptrDeleteCond->Wake();
} }
} }
@ -1302,18 +1292,7 @@ void UdpSocket2Windows::DisableNewOutstandingCalls()
if(noOutstandingCalls) if(noOutstandingCalls)
{ {
CriticalSectionScoped cs(_ptrDeleteCrit); delete_event_.Set();
_safeTodelete = true;
_ptrDeleteCond->Wake();
}
}
void UdpSocket2Windows::WaitForOutstandingCalls()
{
CriticalSectionScoped cs(_ptrDeleteCrit);
while(!_safeTodelete)
{
_ptrDeleteCond->SleepCS(*_ptrDeleteCrit);
} }
} }

View File

@ -19,9 +19,8 @@
#include <Ntddndis.h> #include <Ntddndis.h>
#include <traffic.h> #include <traffic.h>
#include "webrtc/base/event.h"
#include "webrtc/system_wrappers/include/atomic32.h" #include "webrtc/system_wrappers/include/atomic32.h"
#include "webrtc/system_wrappers/include/condition_variable_wrapper.h"
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
#include "webrtc/system_wrappers/include/event_wrapper.h" #include "webrtc/system_wrappers/include/event_wrapper.h"
#include "webrtc/system_wrappers/include/rw_lock_wrapper.h" #include "webrtc/system_wrappers/include/rw_lock_wrapper.h"
#include "webrtc/system_wrappers/include/trace.h" #include "webrtc/system_wrappers/include/trace.h"
@ -133,22 +132,18 @@ private:
int32_t _iProtocol; int32_t _iProtocol;
UdpSocket2ManagerWindows* _mgr; UdpSocket2ManagerWindows* _mgr;
CriticalSectionWrapper* _pCrit;
Atomic32 _outstandingCalls; Atomic32 _outstandingCalls;
Atomic32 _outstandingCallComplete; Atomic32 _outstandingCallComplete;
volatile bool _terminate; volatile bool _terminate;
volatile bool _addedToMgr; volatile bool _addedToMgr;
CriticalSectionWrapper* _ptrDeleteCrit; rtc::Event delete_event_;
ConditionVariableWrapper* _ptrDeleteCond;
bool _safeTodelete;
RWLockWrapper* _ptrDestRWLock; RWLockWrapper* _ptrDestRWLock;
bool _outstandingCallsDisabled; bool _outstandingCallsDisabled;
bool NewOutstandingCall(); bool NewOutstandingCall();
void OutstandingCallCompleted(); void OutstandingCallCompleted();
void DisableNewOutstandingCalls(); void DisableNewOutstandingCalls();
void WaitForOutstandingCalls();
void RemoveSocketFromManager(); void RemoveSocketFromManager();