public AccountLock GetAccountLock(int accountId) { lock (AccountLocks) { AccountLock accountLock; if (AccountLocks.TryGetValue(accountId, out accountLock)) accountLock.Counter += 1; else { accountLock = new AccountLock(); AccountLocks[accountId] = accountLock; } return accountLock; } }
public void ReleaseAccountLock(int accountId, AccountLock accountLock) { lock (AccountLocks) { accountLock.Counter -= 1; if (accountLock.Counter <= 0) AccountLocks.Remove(accountId); } }