Replace old lock with ReaderWriterLockSlim instance

This commit is contained in:
Travis Nickles 2019-02-19 04:24:52 -06:00
parent f828eb888c
commit a8c722d604

View File

@ -2,10 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
using static DS4Windows.Global;
namespace DS4Windows
{
public class Mapping
@ -77,6 +79,8 @@ namespace DS4Windows
new Queue<ControlToXInput>(), new Queue<ControlToXInput>()
};
static ReaderWriterLockSlim syncStateLock = new ReaderWriterLockSlim();
public static SyntheticState globalState = new SyntheticState();
public static SyntheticState[] deviceState = new SyntheticState[4]
{ new SyntheticState(), new SyntheticState(), new SyntheticState(),
@ -190,8 +194,8 @@ namespace DS4Windows
public static void Commit(int device)
{
SyntheticState state = deviceState[device];
lock (globalState)
{
syncStateLock.EnterWriteLock();
globalState.currentClicks.leftCount += state.currentClicks.leftCount - state.previousClicks.leftCount;
globalState.currentClicks.middleCount += state.currentClicks.middleCount - state.previousClicks.middleCount;
globalState.currentClicks.rightCount += state.currentClicks.rightCount - state.previousClicks.rightCount;
@ -389,7 +393,8 @@ namespace DS4Windows
}
}
globalState.SaveToPrevious(false);
}
syncStateLock.ExitWriteLock();
state.SaveToPrevious(true);
}