public void EnterLock(QueuedMessage request) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); bool freshlyCreated = false; bool alreadyProcessed = false; var opid = request.Opid; var localkey = (PartitionKey <TKey>)request.GetPartitionKey(process); var parent = request.Parent; var messageType = request.MessageType; if (request.LockedByCaller) { // lock has already been acquired - so we need not touch the queue Entering(opid, localkey.Key, request, stopwatch, messageType, parent); } else { if (!lockqueues.TryGetValue(localkey.Key, out var queue)) { queue = new LockQueue(); queue.Process = process; freshlyCreated = true; } if (queue.IsEmpty) { if (Entering(opid, localkey.Key, request, stopwatch, messageType, parent)) { queue.Enqueue(request, stopwatch); if (freshlyCreated) { lockqueues[localkey.Key] = queue; } } else { alreadyProcessed = true; } } else { queue.Enqueue(request, stopwatch); } if (!alreadyProcessed && messageType.IsFork()) { if (!process.FinishStates.TryGetValue(parent, out var finishState)) { process.FinishStates[parent] = finishState = new FinishState(process, parent); } finishState.AddPending(opid); } } }
public void RestoreLockQueue(object keyValue, LockQueue queue) { queue.Process = process; lockqueues[(TKey)keyValue] = queue; }
public void EnterLock(QueuedMessage request) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); bool exitsImmediately = false; var opid = request.Opid; var parent = request.Parent; var messageType = request.MessageType; var partitionkey = request.GetPartitionKey(process); TKey localkey = ((PartitionKey <TKey>)partitionkey).Key; if (request.LockedByCaller) { request.OnEnter(process); request.Enter(process, localkey, stopwatch, out exitsImmediately); if (exitsImmediately) { request.OnExit(process); } else { ((AcquireLock)lockqueues[localkey].Holder).Add(request); } } else { if (!lockqueues.TryGetValue(localkey, out var queue) || queue.IsEmpty) { request.OnEnter(process); request.Enter(process, localkey, stopwatch, out exitsImmediately); if (exitsImmediately) { request.OnExit(process); } else { if (queue == null) { queue = new LockQueue() { Process = process }; lockqueues[localkey] = queue; } queue.Enqueue(request, stopwatch); } } else { queue.Enqueue(request, stopwatch); } } if (!exitsImmediately && messageType.IsFork()) { if (!process.FinishStates.TryGetValue(parent, out var finishState)) { process.FinishStates[parent] = finishState = new FinishState(process, parent); } finishState.AddPending(opid); } }