Beispiel #1
0
 unsafe void IDeferredDisposable.OnFinalRelease(bool disposed)
 {
     if (_overlapped != null)
     {
         if (disposed)
         {
             Win32ThreadPoolNativeOverlapped.Free(_overlapped);
         }
         else
         {
             *Win32ThreadPoolNativeOverlapped.ToNativeOverlapped(_overlapped) = default(NativeOverlapped);
         }
     }
 }
Beispiel #2
0
        public unsafe NativeOverlapped *AllocateNativeOverlapped(PreAllocatedOverlapped preAllocated)
        {
            if (preAllocated == null)
            {
                throw new ArgumentNullException(nameof(preAllocated));
            }

            bool addedRefToThis         = false;
            bool addedRefToPreAllocated = false;

            try
            {
                addedRefToThis         = AddRef();
                addedRefToPreAllocated = preAllocated.AddRef();

                Win32ThreadPoolNativeOverlapped.OverlappedData data = preAllocated._overlapped->Data;
                if (data._boundHandle != null)
                {
                    throw new ArgumentException(SR.Argument_PreAllocatedAlreadyAllocated, nameof(preAllocated));
                }

                data._boundHandle = this;

                Interop.mincore.StartThreadpoolIo(_threadPoolHandle);

                return(Win32ThreadPoolNativeOverlapped.ToNativeOverlapped(preAllocated._overlapped));
            }
            catch
            {
                if (addedRefToPreAllocated)
                {
                    preAllocated.Release();
                }
                if (addedRefToThis)
                {
                    Release();
                }
                throw;
            }
        }
Beispiel #3
0
        public unsafe NativeOverlapped *AllocateNativeOverlapped(IOCompletionCallback callback, object state, object pinData)
        {
            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            AddRef();
            try
            {
                Win32ThreadPoolNativeOverlapped *overlapped = Win32ThreadPoolNativeOverlapped.Allocate(callback, state, pinData, preAllocated: null);
                overlapped->Data._boundHandle = this;

                Interop.mincore.StartThreadpoolIo(_threadPoolHandle);

                return(Win32ThreadPoolNativeOverlapped.ToNativeOverlapped(overlapped));
            }
            catch
            {
                Release();
                throw;
            }
        }