mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Fix race condition issue on AdhocMatching
This commit is contained in:
parent
329c1c5e43
commit
ee7383193b
2 changed files with 8 additions and 8 deletions
|
@ -2252,7 +2252,7 @@ bool resolveIP(uint32_t ip, SceNetEtherAddr * mac) {
|
|||
}
|
||||
|
||||
// Multithreading Lock
|
||||
peerlock.lock();
|
||||
std::lock_guard<std::recursive_mutex> peer_guard(peerlock);
|
||||
|
||||
// Peer Reference
|
||||
SceNetAdhocctlPeerInfo * peer = friends;
|
||||
|
@ -2264,17 +2264,11 @@ bool resolveIP(uint32_t ip, SceNetEtherAddr * mac) {
|
|||
// Copy Data
|
||||
*mac = peer->mac_addr;
|
||||
|
||||
// Multithreading Unlock
|
||||
peerlock.unlock();
|
||||
|
||||
// Return Success
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Multithreading Unlock
|
||||
peerlock.unlock();
|
||||
|
||||
// Peer not found
|
||||
return false;
|
||||
}
|
||||
|
@ -2293,7 +2287,7 @@ bool resolveMAC(SceNetEtherAddr * mac, uint32_t * ip) {
|
|||
}
|
||||
|
||||
// Multithreading Lock
|
||||
std::lock_guard<std::recursive_mutex> guard(peerlock);
|
||||
std::lock_guard<std::recursive_mutex> peer_guard(peerlock);
|
||||
|
||||
// Peer Reference
|
||||
SceNetAdhocctlPeerInfo * peer = friends;
|
||||
|
|
|
@ -5390,6 +5390,9 @@ int sceNetAdhocMatchingSendData(int matchingId, const char *mac, int dataLen, u3
|
|||
void* data = NULL;
|
||||
if (Memory::IsValidAddress(dataAddr)) data = Memory::GetPointer(dataAddr);
|
||||
|
||||
// Lock the peer
|
||||
std::lock_guard<std::recursive_mutex> peer_guard(peerlock);
|
||||
|
||||
// Find Target Peer
|
||||
SceNetAdhocMatchingMemberInternal* peer = findPeer(context, (SceNetEtherAddr*)mac);
|
||||
|
||||
|
@ -7306,9 +7309,12 @@ int matchingInputThread(int matchingId) // TODO: The MatchingInput thread is usi
|
|||
// FIXME: When using JPCSP + prx files, the "SceNetAdhocMatchingInput" thread is using blocking PdpRecv with infinite(0) timeout, which can be stopped/aborted using SetSocketAlert, while "SceNetAdhocMatchingEvent" thread is using non-blocking for sending
|
||||
rxbuflen = context->rxbuflen;
|
||||
senderport = 0;
|
||||
// Lock the peer first before locking the socket to avoid race condiion
|
||||
peerlock.lock();
|
||||
context->socketlock->lock();
|
||||
int recvresult = sceNetAdhocPdpRecv(context->socket, &sendermac, &senderport, context->rxbuf, &rxbuflen, 0, ADHOC_F_NONBLOCK);
|
||||
context->socketlock->unlock();
|
||||
peerlock.unlock();
|
||||
|
||||
// Received Data from a Sender that interests us
|
||||
// Note: There are cases where the sender port might be re-mapped by router or ISP, so we shouldn't check the source port.
|
||||
|
|
Loading…
Add table
Reference in a new issue