Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 public PriorityFileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options, FileIOPriority ioPriority) :
     base(path, mode, access, share, bufferSize, options)
 {
     _priority = ioPriority;
 }
Ejemplo n.º 4
0
 public PriorityFileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options) :
     base(path, mode, access, share, bufferSize, options)
 {
     _priority = ThreadUtility.InBackgorundMode() ? FileIOPriority.Background : FileIOPriority.Default;
 }