OLD | NEW |
---|---|
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...) Loading... | |
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 delete_event_(true, false), | |
53 _safeTodelete(false), | 54 _safeTodelete(false), |
54 _outstandingCallsDisabled(false), | 55 _outstandingCallsDisabled(false), |
55 _clientHandle(NULL), | 56 _clientHandle(NULL), |
56 _flowHandle(NULL), | 57 _flowHandle(NULL), |
57 _filterHandle(NULL), | 58 _filterHandle(NULL), |
58 _flow(NULL), | 59 _flow(NULL), |
59 _gtc(NULL), | 60 _gtc(NULL), |
60 _pcp(-2), | 61 _pcp(-2), |
61 _receiveBuffers(0) | 62 _receiveBuffers(0) |
62 { | 63 { |
63 WEBRTC_TRACE(kTraceMemory, kTraceTransport, _id, | 64 WEBRTC_TRACE(kTraceMemory, kTraceTransport, _id, |
64 "UdpSocket2Windows::UdpSocket2Windows()"); | 65 "UdpSocket2Windows::UdpSocket2Windows()"); |
65 | 66 |
66 _wantsIncoming = false; | 67 _wantsIncoming = false; |
67 _mgr = static_cast<UdpSocket2ManagerWindows *>(mgr); | 68 _mgr = static_cast<UdpSocket2ManagerWindows *>(mgr); |
68 | 69 |
69 _obj = NULL; | 70 _obj = NULL; |
70 _incomingCb = NULL; | 71 _incomingCb = NULL; |
71 _socket = INVALID_SOCKET; | 72 _socket = INVALID_SOCKET; |
72 _pCrit = CriticalSectionWrapper::CreateCriticalSection(); | |
73 _ptrCbRWLock = RWLockWrapper::CreateRWLock(); | 73 _ptrCbRWLock = RWLockWrapper::CreateRWLock(); |
74 _ptrDestRWLock = RWLockWrapper::CreateRWLock(); | 74 _ptrDestRWLock = RWLockWrapper::CreateRWLock(); |
75 _ptrSocketRWLock = RWLockWrapper::CreateRWLock(); | 75 _ptrSocketRWLock = RWLockWrapper::CreateRWLock(); |
76 _ptrDeleteCrit = CriticalSectionWrapper::CreateCriticalSection(); | |
77 _ptrDeleteCond = ConditionVariableWrapper::CreateConditionVariable(); | |
78 | 76 |
79 // Check if QoS is supported. | 77 // Check if QoS is supported. |
80 BOOL bProtocolFound = FALSE; | 78 BOOL bProtocolFound = FALSE; |
81 WSAPROTOCOL_INFO *lpProtocolBuf = NULL; | 79 WSAPROTOCOL_INFO *lpProtocolBuf = NULL; |
82 WSAPROTOCOL_INFO pProtocolInfo; | 80 WSAPROTOCOL_INFO pProtocolInfo; |
83 | 81 |
84 if(!disableGQOS) | 82 if(!disableGQOS) |
85 { | 83 { |
86 DWORD dwBufLen = 0; | 84 DWORD dwBufLen = 0; |
87 // Set dwBufLen to the size needed to retreive all the requested | 85 // Set dwBufLen to the size needed to retreive all the requested |
(...skipping 93 matching lines...) Loading... | |
181 } | 179 } |
182 | 180 |
183 UdpSocket2Windows::~UdpSocket2Windows() | 181 UdpSocket2Windows::~UdpSocket2Windows() |
184 { | 182 { |
185 WEBRTC_TRACE(kTraceMemory, kTraceTransport, _id, | 183 WEBRTC_TRACE(kTraceMemory, kTraceTransport, _id, |
186 "UdpSocket2Windows::~UdpSocket2Windows()"); | 184 "UdpSocket2Windows::~UdpSocket2Windows()"); |
187 | 185 |
188 WaitForOutstandingCalls(); | 186 WaitForOutstandingCalls(); |
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 1063 matching lines...) Loading... | |
1272 // disabled it is time to terminate. | 1265 // disabled it is time to terminate. |
1273 _terminate = true; | 1266 _terminate = true; |
1274 } | 1267 } |
1275 _ptrDestRWLock->ReleaseLockShared(); | 1268 _ptrDestRWLock->ReleaseLockShared(); |
1276 | 1269 |
1277 if((--_outstandingCallComplete == 0) && | 1270 if((--_outstandingCallComplete == 0) && |
1278 (_terminate)) | 1271 (_terminate)) |
1279 { | 1272 { |
1280 // Only one thread will enter here. The thread with the last outstanding | 1273 // Only one thread will enter here. The thread with the last outstanding |
1281 // call. | 1274 // call. |
1282 CriticalSectionScoped cs(_ptrDeleteCrit); | |
1283 _safeTodelete = true; | 1275 _safeTodelete = true; |
1284 _ptrDeleteCond->Wake(); | 1276 delete_event_.Set(); |
1285 } | 1277 } |
1286 } | 1278 } |
1287 | 1279 |
1288 void UdpSocket2Windows::DisableNewOutstandingCalls() | 1280 void UdpSocket2Windows::DisableNewOutstandingCalls() |
1289 { | 1281 { |
1290 _ptrDestRWLock->AcquireLockExclusive(); | 1282 _ptrDestRWLock->AcquireLockExclusive(); |
1291 if(_outstandingCallsDisabled) | 1283 if(_outstandingCallsDisabled) |
1292 { | 1284 { |
1293 // Outstandning calls are already disabled. | 1285 // Outstandning calls are already disabled. |
1294 _ptrDestRWLock->ReleaseLockExclusive(); | 1286 _ptrDestRWLock->ReleaseLockExclusive(); |
1295 return; | 1287 return; |
1296 } | 1288 } |
1297 _outstandingCallsDisabled = true; | 1289 _outstandingCallsDisabled = true; |
1298 const bool noOutstandingCalls = (_outstandingCalls.Value() == 0); | 1290 const bool noOutstandingCalls = (_outstandingCalls.Value() == 0); |
1299 _ptrDestRWLock->ReleaseLockExclusive(); | 1291 _ptrDestRWLock->ReleaseLockExclusive(); |
1300 | 1292 |
1301 RemoveSocketFromManager(); | 1293 RemoveSocketFromManager(); |
1302 | 1294 |
1303 if(noOutstandingCalls) | 1295 if(noOutstandingCalls) |
1304 { | 1296 { |
1305 CriticalSectionScoped cs(_ptrDeleteCrit); | |
1306 _safeTodelete = true; | 1297 _safeTodelete = true; |
1307 _ptrDeleteCond->Wake(); | 1298 delete_event_.Set(); |
1308 } | 1299 } |
1309 } | 1300 } |
1310 | 1301 |
1311 void UdpSocket2Windows::WaitForOutstandingCalls() | 1302 void UdpSocket2Windows::WaitForOutstandingCalls() |
1312 { | 1303 { |
1313 CriticalSectionScoped cs(_ptrDeleteCrit); | 1304 if (!_safeTodelete) |
pbos-webrtc
2016/01/19 20:36:51
Racy read, this was protected by the critical sect
pbos-webrtc
2016/01/19 20:41:09
OTOH, just remove this variable, the event is stil
tommi
2016/01/19 21:06:25
Yes, will do.
This code is riddled with races thou
| |
1314 while(!_safeTodelete) | 1305 delete_event_.Wait(rtc::Event::kForever); |
1315 { | |
1316 _ptrDeleteCond->SleepCS(*_ptrDeleteCrit); | |
1317 } | |
1318 } | 1306 } |
1319 | 1307 |
1320 void UdpSocket2Windows::RemoveSocketFromManager() | 1308 void UdpSocket2Windows::RemoveSocketFromManager() |
1321 { | 1309 { |
1322 // New outstanding calls should be disabled at this point. | 1310 // New outstanding calls should be disabled at this point. |
1323 assert(_outstandingCallsDisabled); | 1311 assert(_outstandingCallsDisabled); |
1324 | 1312 |
1325 if(_addedToMgr) | 1313 if(_addedToMgr) |
1326 { | 1314 { |
1327 WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id, | 1315 WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id, |
(...skipping 37 matching lines...) Loading... | |
1365 "UdpSocket2Windows(%d)::InvalidateSocket() WSAerror: %d", | 1353 "UdpSocket2Windows(%d)::InvalidateSocket() WSAerror: %d", |
1366 (int32_t)this, WSAGetLastError()); | 1354 (int32_t)this, WSAGetLastError()); |
1367 } | 1355 } |
1368 _socket = INVALID_SOCKET; | 1356 _socket = INVALID_SOCKET; |
1369 _ptrSocketRWLock->ReleaseLockExclusive(); | 1357 _ptrSocketRWLock->ReleaseLockExclusive(); |
1370 return true; | 1358 return true; |
1371 } | 1359 } |
1372 | 1360 |
1373 } // namespace test | 1361 } // namespace test |
1374 } // namespace webrtc | 1362 } // namespace webrtc |
OLD | NEW |