Use ReadWriteLockSlim instance instead of lock

This commit is contained in:
Travis Nickles 2018-11-02 18:20:27 -05:00
parent 79377ced7f
commit ad7bbe7ea9

View File

@ -71,8 +71,8 @@ namespace DS4Windows
private bool running; private bool running;
private byte[] recvBuffer = new byte[1024]; private byte[] recvBuffer = new byte[1024];
private SocketAsyncEventArgs[] argsList; private SocketAsyncEventArgs[] argsList;
private volatile int listInd = 0; private int listInd = 0;
private object poolLock = new object(); private ReaderWriterLockSlim poolLock = new ReaderWriterLockSlim();
public delegate void GetPadDetail(int padIdx, ref DualShockPadMeta meta); public delegate void GetPadDetail(int padIdx, ref DualShockPadMeta meta);
@ -185,11 +185,10 @@ namespace DS4Windows
//try { udpSock.SendTo(packetData, clientEP); } //try { udpSock.SendTo(packetData, clientEP); }
int temp = 0; int temp = 0;
lock (poolLock) poolLock.EnterWriteLock();
{ listInd = ++listInd % 20;
listInd = ++listInd % 20; temp = listInd;
temp = listInd; poolLock.ExitWriteLock();
}
SocketAsyncEventArgs args = argsList[temp]; SocketAsyncEventArgs args = argsList[temp];
args.RemoteEndPoint = clientEP; args.RemoteEndPoint = clientEP;
@ -651,11 +650,10 @@ namespace DS4Windows
{ {
//try { udpSock.SendTo(outputData, cl); } //try { udpSock.SendTo(outputData, cl); }
int temp = 0; int temp = 0;
lock (poolLock) poolLock.EnterWriteLock();
{ listInd = ++listInd % 20;
listInd = ++listInd % 20; temp = listInd;
temp = listInd; poolLock.ExitWriteLock();
}
SocketAsyncEventArgs args = argsList[temp]; SocketAsyncEventArgs args = argsList[temp];
args.RemoteEndPoint = cl; args.RemoteEndPoint = cl;