Example #1
0
            public void ExecuteCompletions()
            {
                while (_ring !.TryRead(out Completion completion))
                {
                    ulong key = completion.userData;
                    if (_operations.Remove(key, out Operation? op))
                    {
                        // Clean up
                        op.MemoryHandle.Dispose();

                        // Capture state
                        object?state = op.State;
                        int    data  = op.Data;
                        AsyncExecutionCallback callback = op.Callback !;

                        // Return the operation
                        ReturnOperation(op);

                        // Complete
                        callback(new AsyncOperationResult(completion.result), state, data);
                    }
                    else
                    {
                        Debug.Assert((key & (1UL << 63)) != 0);
                    }
                }
            }
Example #2
0
 public override void AddWrite(SafeHandle handle, Memory <byte> memory, AsyncExecutionCallback callback, object?state, int data)
 {
     if (_scheduledOperations == null)
     {
         _scheduledOperations = new List <Operation>();
     }
     _scheduledOperations.Add(new Operation {
         Handle = handle, Memory = memory, IsReadNotWrite = false, Callback = callback, State = state, Data = data
     });
 }
Example #3
0
            public override void AddPollOut(SafeHandle handle, AsyncExecutionCallback callback, object?state, int data)
            {
                ulong     key       = CalculateKey(handle, data);
                Operation operation = RentOperation();

                operation.Handle        = handle;
                operation.OperationType = OperationType.PollOut;
                operation.Callback      = callback;
                operation.State         = state;
                operation.Data          = data;
                AddNewOperation(key, operation);
            }
Example #4
0
            public override void AddWrite(SafeHandle handle, Memory <byte> memory, AsyncExecutionCallback callback, object?state, int data)
            {
                ulong     key       = CalculateKey(handle, data);
                Operation operation = RentOperation();

                operation.Handle        = handle;
                operation.Memory        = memory;
                operation.OperationType = OperationType.Write;
                operation.Callback      = callback;
                operation.State         = state;
                operation.Data          = data;
                AddNewOperation(key, operation);
            }
Example #5
0
 public override void AddRead(SafeHandle handle, Memory <byte> memory, AsyncExecutionCallback callback, object?state, int data)
 {
     if (memory.Length == 0)
     {
         ThrowHelper.ThrowArgumentException(nameof(memory));
     }
     if (_scheduledOperations == null)
     {
         _scheduledOperations = new List <Operation>();
     }
     _scheduledOperations.Add(new Operation {
         Handle = handle, Memory = memory, IsReadNotWrite = true, Callback = callback, State = state, Data = data
     });
 }
Example #6
0
            public override void AddWrite(SafeHandle handle, Memory <byte> memory, AsyncExecutionCallback callback, object?state, int data)
            {
                ulong     key       = CalculateKey(handle, data);
                Operation operation = RentOperation();

                operation.Handle        = handle;
                operation.Memory        = memory;
                operation.OperationType = OperationType.Write;
                operation.Callback      = callback;
                operation.State         = state;
                operation.Data          = data;

                // Since we can not do linked R/W in 5.5, we'll need to submit a poll first:
                operation.Status = OperationStatus.PollForReadWrite;

                AddNewOperation(key, operation);
            }
Example #7
0
            public override void AddRead(SafeHandle handle, Memory <byte> memory, AsyncExecutionCallback callback, object?state, int data)
            {
                // TODO: maybe consider writing directly to the sq
                //       This requires handling sq full
                //       which may require handling completions
                //       which means we should no longer call this under a lock from the AsyncContext...
                ulong     key       = CalculateKey(handle, data);
                Operation operation = RentOperation();

                operation.Handle        = handle;
                operation.Memory        = memory;
                operation.OperationType = OperationType.Read;
                operation.Callback      = callback;
                operation.State         = state;
                operation.Data          = data;
                AddNewOperation(key, operation);
            }
Example #8
0
            public void ExecuteCompletions()
            {
                while (_ring !.TryRead(out Completion completion))
                {
                    ulong key = completion.userData;
                    if ((key & PollMaskBit) != 0)
                    {
                        // must be a completion for a poll for R/W
                        _operations.TryGetValue(key & ~PollMaskBit, out Operation? op);
                        Debug.Assert(op != null);
                        Debug.Assert(op.Status == OperationStatus.PollForReadWrite);
                        Debug.Assert(completion.result > 0);
                        op.Status = OperationStatus.Execution;

                        // Re-adding the operation to submit R/W:
                        _newOperations.Add(op);
                    }
                    else
                    {
                        _operations.Remove(key, out Operation? op);
                        Debug.Assert(op != null);
                        // Clean up
                        op.MemoryHandle.Dispose();

                        // Capture state
                        object?state = op.State;
                        int    data  = op.Data;
                        AsyncExecutionCallback callback = op.Callback !;

                        // Return the operation
                        ReturnOperation(op);

                        // Complete
                        callback(new AsyncOperationResult(completion.result), state, data);
                    }
                }
            }
Example #9
0
 public override void AddPollOut(SafeHandle handle, AsyncExecutionCallback asyncExecutionCallback, object?state, int data)
 {
     throw new NotSupportedException();
 }
 // Add a poll out.
 public abstract void AddPollOut(SafeHandle handle, AsyncExecutionCallback asyncExecutionCallback, object?state, int data);
 // Add a write.
 public abstract void AddWrite(SafeHandle handle, Memory <byte> memory, AsyncExecutionCallback callback, object?state, int data);