public Task <int> Operation( FileOperationType operation, string systemPath, long position, int length, FileIOPriority priority, byte[] buffer, int bufferOffset, PriorityFileStream fs = null) { var drive = Path.GetPathRoot(systemPath); DriveIOScheduler scheduler; lock (_drives) scheduler = _drives.FirstOrDefault(p => p.Key == drive).Value; if (scheduler == null) { scheduler = new DriveIOScheduler(); lock (_drives) _drives.Add(new KeyValuePair <string, DriveIOScheduler>(drive, scheduler)); } return(scheduler.Operation(operation, systemPath, position, length, priority, buffer, bufferOffset, fs)); }
public Task <int> Operation( FileOperationType operation, string systemPath, long position, int length, FileIOPriority priority, byte[] buffer, int bufferOffset, PriorityFileStream fs = null) { var op = new FileIOOperation { SystemPath = systemPath, Buffer = buffer, BufferOffset = bufferOffset, Position = position, Length = length, Operation = operation, TaskCompletionSource = new TaskCompletionSource <int>(), FileStream = fs }; switch (priority) { case FileIOPriority.Default: lock (_defaultQueue) _defaultQueue.Enqueue(op); break; case FileIOPriority.Background: lock (_backgroundQueue) _backgroundQueue.Enqueue(op); break; default: throw new ArgumentOutOfRangeException(nameof(priority), priority, null); } if (Interlocked.Increment(ref _activeOperations) <= FileIOScheduler.Instance.MaxConcurrentOperations) { StartNewReadTask(); } else { Interlocked.Decrement(ref _activeOperations); } return(op.TaskCompletionSource.Task); }