public unsafe void FreeNativeOverlapped(NativeOverlapped *overlapped) { if (overlapped == null) { throw new ArgumentNullException(nameof(overlapped)); } Win32ThreadPoolNativeOverlapped *threadPoolOverlapped = Win32ThreadPoolNativeOverlapped.FromNativeOverlapped(overlapped); Win32ThreadPoolNativeOverlapped.OverlappedData data = GetOverlappedData(threadPoolOverlapped, this); if (!data._completed) { Interop.mincore.CancelThreadpoolIo(_threadPoolHandle); Release(); } data._boundHandle = null; data._completed = false; if (data._preAllocated != null) { data._preAllocated.Release(); } else { Win32ThreadPoolNativeOverlapped.Free(threadPoolOverlapped); } }
public static unsafe object GetNativeOverlappedState(NativeOverlapped *overlapped) { if (overlapped == null) { throw new ArgumentNullException(nameof(overlapped)); } Win32ThreadPoolNativeOverlapped *threadPoolOverlapped = Win32ThreadPoolNativeOverlapped.FromNativeOverlapped(overlapped); Win32ThreadPoolNativeOverlapped.OverlappedData data = GetOverlappedData(threadPoolOverlapped, null); return(threadPoolOverlapped->Data._state); }
private static unsafe Win32ThreadPoolNativeOverlapped.OverlappedData GetOverlappedData(Win32ThreadPoolNativeOverlapped *overlapped, ThreadPoolBoundHandle expectedBoundHandle) { Win32ThreadPoolNativeOverlapped.OverlappedData data = overlapped->Data; if (data._boundHandle == null) { throw new ArgumentException(SR.Argument_NativeOverlappedAlreadyFree, nameof(overlapped)); } if (expectedBoundHandle != null && data._boundHandle != expectedBoundHandle) { throw new ArgumentException(SR.Argument_NativeOverlappedWrongBoundHandle, nameof(overlapped)); } return(data); }
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; } }