Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1299)

Side by Side Diff: webrtc/test/channel_transport/udp_socket2_win.cc

Issue 1606993002: Remove use of ConditionVariableWrapper and CriticalSectionWrapper from UdpSocket2Windows. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Remove unnecessary variable Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/test/channel_transport/udp_socket2_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 UdpSocket2Windows::UdpSocket2Windows(const int32_t id, 43 UdpSocket2Windows::UdpSocket2Windows(const int32_t id,
44 UdpSocketManager* mgr, bool ipV6Enable, 44 UdpSocketManager* mgr, bool ipV6Enable,
45 bool disableGQOS) 45 bool disableGQOS)
46 : _id(id), 46 : _id(id),
47 _qos(true), 47 _qos(true),
48 _iProtocol(0), 48 _iProtocol(0),
49 _outstandingCalls(0), 49 _outstandingCalls(0),
50 _outstandingCallComplete(0), 50 _outstandingCallComplete(0),
51 _terminate(false), 51 _terminate(false),
52 _addedToMgr(false), 52 _addedToMgr(false),
53 _safeTodelete(false), 53 delete_event_(true, false),
54 _outstandingCallsDisabled(false), 54 _outstandingCallsDisabled(false),
55 _clientHandle(NULL), 55 _clientHandle(NULL),
56 _flowHandle(NULL), 56 _flowHandle(NULL),
57 _filterHandle(NULL), 57 _filterHandle(NULL),
58 _flow(NULL), 58 _flow(NULL),
59 _gtc(NULL), 59 _gtc(NULL),
60 _pcp(-2), 60 _pcp(-2),
61 _receiveBuffers(0) 61 _receiveBuffers(0)
62 { 62 {
63 WEBRTC_TRACE(kTraceMemory, kTraceTransport, _id, 63 WEBRTC_TRACE(kTraceMemory, kTraceTransport, _id,
64 "UdpSocket2Windows::UdpSocket2Windows()"); 64 "UdpSocket2Windows::UdpSocket2Windows()");
65 65
66 _wantsIncoming = false; 66 _wantsIncoming = false;
67 _mgr = static_cast<UdpSocket2ManagerWindows *>(mgr); 67 _mgr = static_cast<UdpSocket2ManagerWindows *>(mgr);
68 68
69 _obj = NULL; 69 _obj = NULL;
70 _incomingCb = NULL; 70 _incomingCb = NULL;
71 _socket = INVALID_SOCKET; 71 _socket = INVALID_SOCKET;
72 _pCrit = CriticalSectionWrapper::CreateCriticalSection();
73 _ptrCbRWLock = RWLockWrapper::CreateRWLock(); 72 _ptrCbRWLock = RWLockWrapper::CreateRWLock();
74 _ptrDestRWLock = RWLockWrapper::CreateRWLock(); 73 _ptrDestRWLock = RWLockWrapper::CreateRWLock();
75 _ptrSocketRWLock = RWLockWrapper::CreateRWLock(); 74 _ptrSocketRWLock = RWLockWrapper::CreateRWLock();
76 _ptrDeleteCrit = CriticalSectionWrapper::CreateCriticalSection();
77 _ptrDeleteCond = ConditionVariableWrapper::CreateConditionVariable();
78 75
79 // Check if QoS is supported. 76 // Check if QoS is supported.
80 BOOL bProtocolFound = FALSE; 77 BOOL bProtocolFound = FALSE;
81 WSAPROTOCOL_INFO *lpProtocolBuf = NULL; 78 WSAPROTOCOL_INFO *lpProtocolBuf = NULL;
82 WSAPROTOCOL_INFO pProtocolInfo; 79 WSAPROTOCOL_INFO pProtocolInfo;
83 80
84 if(!disableGQOS) 81 if(!disableGQOS)
85 { 82 {
86 DWORD dwBufLen = 0; 83 DWORD dwBufLen = 0;
87 // Set dwBufLen to the size needed to retreive all the requested 84 // Set dwBufLen to the size needed to retreive all the requested
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 WSAerror: %d", 175 WSAerror: %d",
179 WSAGetLastError()); 176 WSAGetLastError());
180 } 177 }
181 } 178 }
182 179
183 UdpSocket2Windows::~UdpSocket2Windows() 180 UdpSocket2Windows::~UdpSocket2Windows()
184 { 181 {
185 WEBRTC_TRACE(kTraceMemory, kTraceTransport, _id, 182 WEBRTC_TRACE(kTraceMemory, kTraceTransport, _id,
186 "UdpSocket2Windows::~UdpSocket2Windows()"); 183 "UdpSocket2Windows::~UdpSocket2Windows()");
187 184
188 WaitForOutstandingCalls(); 185 delete_event_.Wait(rtc::Event::kForever);
186
189 187
190 delete _ptrCbRWLock; 188 delete _ptrCbRWLock;
191 delete _ptrDeleteCrit;
192 delete _ptrDeleteCond;
193 delete _ptrDestRWLock; 189 delete _ptrDestRWLock;
194 delete _ptrSocketRWLock; 190 delete _ptrSocketRWLock;
195 191
196 if(_pCrit)
197 delete _pCrit;
198
199 if (_flow) 192 if (_flow)
200 { 193 {
201 free(_flow); 194 free(_flow);
202 _flow = NULL; 195 _flow = NULL;
203 } 196 }
204 197
205 if (_gtc) 198 if (_gtc)
206 { 199 {
207 if(_filterHandle) 200 if(_filterHandle)
208 { 201 {
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 setsockopt(_socket, SOL_SOCKET, SO_LINGER, 653 setsockopt(_socket, SOL_SOCKET, SO_LINGER,
661 reinterpret_cast<const char*>(&lingerStruct), 654 reinterpret_cast<const char*>(&lingerStruct),
662 sizeof(lingerStruct)); 655 sizeof(lingerStruct));
663 ReleaseSocket(); 656 ReleaseSocket();
664 } 657 }
665 658
666 _wantsIncoming = false; 659 _wantsIncoming = false;
667 // Reclaims the socket and prevents it from being used again. 660 // Reclaims the socket and prevents it from being used again.
668 InvalidateSocket(); 661 InvalidateSocket();
669 DisableNewOutstandingCalls(); 662 DisableNewOutstandingCalls();
670 WaitForOutstandingCalls();
671 delete this; 663 delete this;
672 } 664 }
673 665
674 bool UdpSocket2Windows::SetQos(int32_t serviceType, 666 bool UdpSocket2Windows::SetQos(int32_t serviceType,
675 int32_t tokenRate, 667 int32_t tokenRate,
676 int32_t bucketSize, 668 int32_t bucketSize,
677 int32_t peekBandwith, 669 int32_t peekBandwith,
678 int32_t minPolicedSize, 670 int32_t minPolicedSize,
679 int32_t maxSduSize, 671 int32_t maxSduSize,
680 const SocketAddress &stRemName, 672 const SocketAddress &stRemName,
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 // disabled it is time to terminate. 1264 // disabled it is time to terminate.
1273 _terminate = true; 1265 _terminate = true;
1274 } 1266 }
1275 _ptrDestRWLock->ReleaseLockShared(); 1267 _ptrDestRWLock->ReleaseLockShared();
1276 1268
1277 if((--_outstandingCallComplete == 0) && 1269 if((--_outstandingCallComplete == 0) &&
1278 (_terminate)) 1270 (_terminate))
1279 { 1271 {
1280 // Only one thread will enter here. The thread with the last outstanding 1272 // Only one thread will enter here. The thread with the last outstanding
1281 // call. 1273 // call.
1282 CriticalSectionScoped cs(_ptrDeleteCrit); 1274 delete_event_.Set();
1283 _safeTodelete = true;
1284 _ptrDeleteCond->Wake();
1285 } 1275 }
1286 } 1276 }
1287 1277
1288 void UdpSocket2Windows::DisableNewOutstandingCalls() 1278 void UdpSocket2Windows::DisableNewOutstandingCalls()
1289 { 1279 {
1290 _ptrDestRWLock->AcquireLockExclusive(); 1280 _ptrDestRWLock->AcquireLockExclusive();
1291 if(_outstandingCallsDisabled) 1281 if(_outstandingCallsDisabled)
1292 { 1282 {
1293 // Outstandning calls are already disabled. 1283 // Outstandning calls are already disabled.
1294 _ptrDestRWLock->ReleaseLockExclusive(); 1284 _ptrDestRWLock->ReleaseLockExclusive();
1295 return; 1285 return;
1296 } 1286 }
1297 _outstandingCallsDisabled = true; 1287 _outstandingCallsDisabled = true;
1298 const bool noOutstandingCalls = (_outstandingCalls.Value() == 0); 1288 const bool noOutstandingCalls = (_outstandingCalls.Value() == 0);
1299 _ptrDestRWLock->ReleaseLockExclusive(); 1289 _ptrDestRWLock->ReleaseLockExclusive();
1300 1290
1301 RemoveSocketFromManager(); 1291 RemoveSocketFromManager();
1302 1292
1303 if(noOutstandingCalls) 1293 if(noOutstandingCalls)
1304 { 1294 {
1305 CriticalSectionScoped cs(_ptrDeleteCrit); 1295 delete_event_.Set();
1306 _safeTodelete = true;
1307 _ptrDeleteCond->Wake();
1308 } 1296 }
1309 } 1297 }
1310 1298
1311 void UdpSocket2Windows::WaitForOutstandingCalls()
1312 {
1313 CriticalSectionScoped cs(_ptrDeleteCrit);
1314 while(!_safeTodelete)
1315 {
1316 _ptrDeleteCond->SleepCS(*_ptrDeleteCrit);
1317 }
1318 }
1319
1320 void UdpSocket2Windows::RemoveSocketFromManager() 1299 void UdpSocket2Windows::RemoveSocketFromManager()
1321 { 1300 {
1322 // New outstanding calls should be disabled at this point. 1301 // New outstanding calls should be disabled at this point.
1323 assert(_outstandingCallsDisabled); 1302 assert(_outstandingCallsDisabled);
1324 1303
1325 if(_addedToMgr) 1304 if(_addedToMgr)
1326 { 1305 {
1327 WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id, 1306 WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id,
1328 "calling UdpSocketManager::RemoveSocket()"); 1307 "calling UdpSocketManager::RemoveSocket()");
1329 if(_mgr->RemoveSocket(this)) 1308 if(_mgr->RemoveSocket(this))
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 "UdpSocket2Windows(%d)::InvalidateSocket() WSAerror: %d", 1344 "UdpSocket2Windows(%d)::InvalidateSocket() WSAerror: %d",
1366 (int32_t)this, WSAGetLastError()); 1345 (int32_t)this, WSAGetLastError());
1367 } 1346 }
1368 _socket = INVALID_SOCKET; 1347 _socket = INVALID_SOCKET;
1369 _ptrSocketRWLock->ReleaseLockExclusive(); 1348 _ptrSocketRWLock->ReleaseLockExclusive();
1370 return true; 1349 return true;
1371 } 1350 }
1372 1351
1373 } // namespace test 1352 } // namespace test
1374 } // namespace webrtc 1353 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/test/channel_transport/udp_socket2_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698