public Queue(IOUringThread thread, IOUringAsyncContext context, bool readNotWrite)
 {
     _thread  = thread;
     _context = context;
     // This is used to distinguish on-going read from write when cancelling.
     _keyForOperation = readNotWrite ? POLLIN : POLLOUT;
 }
            private unsafe void EventLoop()
            {
                try
                {
                    IOUringExecutionQueue iouring = _iouring !;
                    while (!_disposed)
                    {
                        bool mayWait;
                        lock (_actionQueueGate)
                        {
                            // We can only wait when there are no scheduled actions we must run.
                            mayWait = _scheduledActions.Count == 0;
                            if (mayWait)
                            {
                                Volatile.Write(ref _blockedState, StateBlocked);
                            }
                        }
                        iouring.SubmitAndWait(mayWait);
                        Volatile.Write(ref _blockedState, StateNotBlocked);

                        iouring.ExecuteCompletions();

                        ExecuteScheduledActions();
                    }

                    // Execute actions that got posted before we were disposed.
                    ExecuteScheduledActions();

                    // Complete pending async operations.
                    iouring.Dispose();

                    IOUringAsyncContext[] contexts;
                    lock (_asyncContexts)
                    {
                        contexts = new IOUringAsyncContext[_asyncContexts.Count];
                        _asyncContexts.Values.CopyTo(contexts, 0);
                        _asyncContexts.Clear();
                    }
                    foreach (var context in contexts)
                    {
                        context.Dispose();
                    }

                    FreeResources();
                }
                catch (Exception e)
                {
                    Environment.FailFast(e.ToString());
                }
            }
            internal AsyncContext CreateContext(SafeHandle handle)
            {
                lock (_asyncContexts)
                {
                    if (_disposed)
                    {
                        ThrowHelper.ThrowObjectDisposedException <IOUringThread>();
                    }

                    IOUringAsyncContext context = new IOUringAsyncContext(this, handle);

                    _asyncContexts.Add(context.Key, context);

                    return(context);
                }
            }
 public Queue(IOUringThread thread, IOUringAsyncContext context)
 {
     _thread  = thread;
     _context = context;
 }