internal static void RegisteredWaitCallback(IntPtr instance, IntPtr context, IntPtr wait, uint waitResult)
        {
            var wrapper = ThreadPoolCallbackWrapper.Enter();
            GCHandle handle = (GCHandle)context;
            RegisteredWaitHandle registeredWaitHandle = (RegisteredWaitHandle)handle.Target;
            Debug.Assert((handle == registeredWaitHandle._gcHandle) && (wait == registeredWaitHandle._tpWait));

            bool timedOut = (waitResult == (uint)Interop.Kernel32.WAIT_TIMEOUT);
            registeredWaitHandle.PerformCallback(timedOut);
            ThreadPool.IncrementCompletedWorkItemCount();
            wrapper.Exit();
        }
Example #2
0
        internal static void RegisteredWaitCallback(IntPtr instance, IntPtr context, IntPtr wait, uint waitResult)
        {
            var                  wrapper = ThreadPoolCallbackWrapper.Enter();
            GCHandle             handle  = (GCHandle)context;
            RegisteredWaitHandle registeredWaitHandle = (RegisteredWaitHandle)handle.Target;

            Debug.Assert((handle == registeredWaitHandle._gcHandle) && (wait == registeredWaitHandle._tpWait));

            bool timedOut = (waitResult == (uint)Interop.Constants.WaitTimeout);

            registeredWaitHandle.PerformCallback(timedOut);
            wrapper.Exit();
        }
Example #3
0
        private static void DispatchCallback(IntPtr instance, IntPtr context, IntPtr work)
        {
            var wrapper = ThreadPoolCallbackWrapper.Enter();

            Debug.Assert(s_work == work);
            ThreadBooleanCounter workingThreadCounter = s_workingThreadCounter;

            workingThreadCounter.Set();
            ThreadPoolWorkQueue.Dispatch();
            workingThreadCounter.Clear();
            // We reset the thread after executing each callback
            wrapper.Exit(resetThread: false);
        }
Example #4
0
        private static void DispatchCallback(IntPtr instance, IntPtr context, IntPtr work)
        {
            var wrapper = ThreadPoolCallbackWrapper.Enter();

            Debug.Assert(s_work == work);
            Interlocked.Increment(ref numWorkingThreads);
            ThreadPoolWorkQueue.Dispatch();
            int numWorkers = Interlocked.Decrement(ref numWorkingThreads);

            Debug.Assert(numWorkers >= 0);
            // We reset the thread after executing each callback
            wrapper.Exit(resetThread: false);
        }
Example #5
0
        private static IntPtr ThreadPoolDispatchCallback(IntPtr context)
        {
            var wrapper = ThreadPoolCallbackWrapper.Enter();

            do
            {
                // Handle pending requests
                ThreadPoolWorkQueue.Dispatch();

                // Wait for new requests to arrive
                s_semaphore.Wait();
            } while (true);

            //wrapper.Exit(resetThread: false);
        }
        private static unsafe void OnNativeIOCompleted(IntPtr instance, IntPtr context, IntPtr overlappedPtr, uint ioResult, UIntPtr numberOfBytesTransferred, IntPtr ioPtr)
        {
            var wrapper = ThreadPoolCallbackWrapper.Enter();
            Win32ThreadPoolNativeOverlapped *overlapped = (Win32ThreadPoolNativeOverlapped *)overlappedPtr;

            ThreadPoolBoundHandle boundHandle = overlapped->Data._boundHandle;

            if (boundHandle == null)
            {
                throw new InvalidOperationException(SR.Argument_NativeOverlappedAlreadyFree);
            }

            boundHandle.Release();

            Win32ThreadPoolNativeOverlapped.CompleteWithCallback(ioResult, (uint)numberOfBytesTransferred, overlapped);
            wrapper.Exit();
        }