// call back helper static internal void PerformTimerCallback(Object state) { _TimerCallback helper = (_TimerCallback)state; BCLDebug.Assert(helper != null, "Null state passed to PerformTimerCallback!"); // call directly if EC flow is suppressed if (helper._executionContext == null) { TimerCallback callback = helper._timerCallback; callback(helper._state); } else { // From this point on we can use useExecutionContext for this callback ExecutionContext.Run(helper._executionContext.CreateCopy(), _ccb, helper); } }
private void FinishPhase(bool observedSense) { // Execute the PHA in try/finally block to reset the variables back in case of it threw an exception if (_postPhaseAction != null) { try { // Capture the caller thread ID to check if the Add/RemoveParticipant(s) is called from the PHA _actionCallerID = Environment.CurrentManagedThreadId; if (_ownerThreadContext != null) { var currentContext = _ownerThreadContext; ContextCallback handler = s_invokePostPhaseAction; if (handler == null) { s_invokePostPhaseAction = handler = InvokePostPhaseAction; } ExecutionContext.Run(_ownerThreadContext, handler, this); } else { _postPhaseAction(this); } _exception = null; // reset the exception if it was set previously } catch (Exception ex) { _exception = ex; } finally { _actionCallerID = 0; SetResetEvents(observedSense); if (_exception != null) { throw new BarrierPostPhaseException(_exception); } } } else { SetResetEvents(observedSense); } }
internal static void PerformWaitOrTimerCallback(object state, bool timedOut) { _ThreadPoolWaitOrTimerCallback callback = (_ThreadPoolWaitOrTimerCallback)state; if (callback._executionContext == null) { callback._waitOrTimerCallback(callback._state, timedOut); } else if (timedOut) { ExecutionContext.Run(callback._executionContext.CreateCopy(), _ccbt, callback); } else { ExecutionContext.Run(callback._executionContext.CreateCopy(), _ccbf, callback); } }
internal void CallCallback() { if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.ThreadTransfer)) { FrameworkEventSource.Log.ThreadTransferReceiveObj(this, 1, string.Empty); } // call directly if EC flow is suppressed if (m_executionContext == null) { m_timerCallback(m_state); } else { ExecutionContext.Run(m_executionContext, s_callCallbackInContext, this); } }
private void FinishPhase(bool observedSense) { ContextCallback callback = null; if (this.m_postPhaseAction != null) { try { try { this.m_actionCallerID = Thread.CurrentThread.ManagedThreadId; if (this.m_ownerThreadContext != null) { if (callback == null) { callback = i => this.m_postPhaseAction(this); } ExecutionContext.Run(this.m_ownerThreadContext.CreateCopy(), callback, null); } else { this.m_postPhaseAction(this); } this.m_exception = null; } catch (Exception exception) { this.m_exception = exception; } return; } finally { this.m_actionCallerID = 0; this.SetResetEvents(observedSense); if (this.m_exception != null) { throw new BarrierPostPhaseException(this.m_exception); } } } this.SetResetEvents(observedSense); }
internal void CallCallback() { ContextCallback callback = s_callCallbackInContext; if (callback == null) { s_callCallbackInContext = callback = new ContextCallback(CallCallbackInContext); } // call directly if EC flow is suppressed if (_executionContext == null) { _timerCallback(_state); } else { ExecutionContext.Run(_executionContext, callback, this); } }
/// <summary>Registers a signal with the event, decrementing its count.</summary> public void Signal() { ContextCallback callback = null; if (this._event.Signal()) { if (this._context != null) { if (callback == null) { callback = _ => this._action(); } ExecutionContext.Run(this._context, callback, null); } else { this._action(); } } }
internal static unsafe void PerformIOCompletionCallback(uint errorCode, uint numBytes, NativeOverlapped *pOVERLAP) { do { Overlapped overlapped = OverlappedData.GetOverlappedFromNative(pOVERLAP).m_overlapped; _IOCompletionCallback iocbHelper = overlapped.iocbHelper; if (((iocbHelper == null) || (iocbHelper._executionContext == null)) || iocbHelper._executionContext.IsDefaultFTContext()) { overlapped.UserCallback(errorCode, numBytes, pOVERLAP); } else { iocbHelper._errorCode = errorCode; iocbHelper._numBytes = numBytes; iocbHelper._pOVERLAP = pOVERLAP; ExecutionContext.Run(iocbHelper._executionContext.CreateCopy(), _ccb, iocbHelper); } OverlappedData.CheckVMForIOPacket(out pOVERLAP, out errorCode, out numBytes); }while (pOVERLAP != null); }
internal static unsafe void PerformIOCompletionCallback(uint errorCode, uint numBytes, NativeOverlapped *pOVERLAP) { do { Overlapped overlapped = OverlappedData.GetOverlappedFromNative(pOVERLAP).m_overlapped; _IOCompletionCallback iocbHelper = overlapped.iocbHelper; if (iocbHelper == null || iocbHelper._executionContext == null || iocbHelper._executionContext.IsDefaultFTContext(true)) { overlapped.UserCallback(errorCode, numBytes, pOVERLAP); } else { iocbHelper._errorCode = errorCode; iocbHelper._numBytes = numBytes; iocbHelper._pOVERLAP = pOVERLAP; using (ExecutionContext copy = iocbHelper._executionContext.CreateCopy()) ExecutionContext.Run(copy, _IOCompletionCallback._ccb, (object)iocbHelper, true); } OverlappedData.CheckVMForIOPacket(out pOVERLAP, out errorCode, out numBytes); }while ((IntPtr)pOVERLAP != IntPtr.Zero); }
internal void CallCallback() { if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, (EventKeywords)16L)) { FrameworkEventSource.Log.ThreadTransferReceiveObj(this, 1, string.Empty); } if (this.m_executionContext == null) { this.m_timerCallback(this.m_state); return; } using (ExecutionContext executionContext = this.m_executionContext.IsPreAllocatedDefault ? this.m_executionContext : this.m_executionContext.CreateCopy()) { ContextCallback contextCallback = TimerQueueTimer.s_callCallbackInContext; if (contextCallback == null) { contextCallback = (TimerQueueTimer.s_callCallbackInContext = new ContextCallback(TimerQueueTimer.CallCallbackInContext)); } ExecutionContext.Run(executionContext, contextCallback, this, true); } }
internal static void PerformWaitOrTimerCallback(object state, bool timedOut) { _ThreadPoolWaitOrTimerCallback threadPoolWaitOrTimerCallback = (_ThreadPoolWaitOrTimerCallback)state; if (threadPoolWaitOrTimerCallback._executionContext == null) { WaitOrTimerCallback waitOrTimerCallback = threadPoolWaitOrTimerCallback._waitOrTimerCallback; waitOrTimerCallback(threadPoolWaitOrTimerCallback._state, timedOut); return; } using (ExecutionContext executionContext = threadPoolWaitOrTimerCallback._executionContext.CreateCopy()) { if (timedOut) { ExecutionContext.Run(executionContext, _ThreadPoolWaitOrTimerCallback._ccbt, threadPoolWaitOrTimerCallback, true); } else { ExecutionContext.Run(executionContext, _ThreadPoolWaitOrTimerCallback._ccbf, threadPoolWaitOrTimerCallback, true); } } }
void IThreadPoolWorkItem.ExecuteWorkItem() { #if DEBUG MarkExecuted(); #endif try { if (context == null) { callback(state); } else { ExecutionContext.Run(context, ccb, this); } } catch (Exception e) { RuntimeAugments.ReportUnhandledException(e); throw; //unreachable } }
public override void ExecuteWorkItem() { base.ExecuteWorkItem(); try { if (_context == null) { WaitCallback c = _callback; _callback = null; c(_state); } else { ExecutionContext.Run(_context, s_executionContextShim, this); } } catch (Exception e) { RuntimeAugments.ReportUnhandledException(e); throw; //unreachable } }
/// <summary> /// Finish the phase by invoking the post phase action, and setting the event, this must be called by the /// last arrival thread /// </summary> /// <param name="observedSense">The current phase sense</param> private void FinishPhase(bool observedSense) { // Execute the PHA in try/finally block to reset the variables back in case of it threw an exception if (m_postPhaseAction != null) { try { // Capture the caller thread ID to check if the Add/RemoveParticipant(s) is called from the PHA m_actionCallerID = Thread.CurrentThread.ManagedThreadId; if (m_ownerThreadContext != null) { ExecutionContext.Run(m_ownerThreadContext.CreateCopy(), i => m_postPhaseAction(this), null); } else { m_postPhaseAction(this); } m_exception = null; // reset the exception if it was set previously } catch (Exception ex) { m_exception = ex; } finally { m_actionCallerID = 0; SetResetEvents(observedSense); if (m_exception != null) { throw new BarrierPostPhaseException(m_exception); } } } else { SetResetEvents(observedSense); } }
// call back helper static unsafe internal void PerformIOCompletionCallback(uint errorCode, // Error code uint numBytes, // No. of bytes transferred NativeOverlapped *pOVERLAP // ptr to OVERLAP structure ) { Overlapped overlapped = OverlappedData.GetOverlappedFromNative(pOVERLAP).m_overlapped; _IOCompletionCallback helper = overlapped.iocbHelper; if (helper == null || helper._executionContext == null || helper._executionContext.IsDefaultFTContext()) { // We got here because of UnsafePack (or) Pack with EC flow supressed IOCompletionCallback callback = overlapped.UserCallback; callback(errorCode, numBytes, pOVERLAP); } else { // We got here because of Pack helper._errorCode = errorCode; helper._numBytes = numBytes; helper._pOVERLAP = pOVERLAP; ExecutionContext.Run(helper._executionContext.CreateCopy(), _ccb, helper); } }
// call back helper static internal void PerformWaitOrTimerCallback(Object state, bool timedOut) { _ThreadPoolWaitOrTimerCallback helper = (_ThreadPoolWaitOrTimerCallback)state; BCLDebug.Assert(helper != null, "Null state passed to PerformWaitOrTimerCallback!"); // call directly if it is an unsafe call OR EC flow is suppressed if (helper._executionContext == null) { WaitOrTimerCallback callback = helper._waitOrTimerCallback; callback(helper._state, timedOut); } else { if (timedOut) { ExecutionContext.Run(helper._executionContext.CreateCopy(), _ccbt, helper); } else { ExecutionContext.Run(helper._executionContext.CreateCopy(), _ccbf, helper); } } }
internal static void PerformWaitOrTimerCallback(object state, bool timedOut) { _ThreadPoolWaitOrTimerCallback waitOrTimerCallback = (_ThreadPoolWaitOrTimerCallback)state; if (waitOrTimerCallback._executionContext == null) { waitOrTimerCallback._waitOrTimerCallback(waitOrTimerCallback._state, timedOut); } else { using (ExecutionContext copy = waitOrTimerCallback._executionContext.CreateCopy()) { if (timedOut) { ExecutionContext.Run(copy, _ThreadPoolWaitOrTimerCallback._ccbt, (object)waitOrTimerCallback, true); } else { ExecutionContext.Run(copy, _ThreadPoolWaitOrTimerCallback._ccbf, (object)waitOrTimerCallback, true); } } } }
internal static unsafe void CompleteWithCallback(uint errorCode, uint bytesWritten, Win32ThreadPoolNativeOverlapped *overlapped) { OverlappedData data = overlapped->Data; Debug.Assert(!data._completed); data._completed = true; if (data._executionContext == null) { data._callback(errorCode, bytesWritten, ToNativeOverlapped(overlapped)); return; } ContextCallback callback = s_executionContextCallback; if (callback == null) { s_executionContextCallback = callback = OnExecutionContextCallback; } // Get an args object from the per-thread cache. ExecutionContextCallbackArgs args = t_executionContextCallbackArgs; if (args == null) { args = new ExecutionContextCallbackArgs(); } t_executionContextCallbackArgs = null; args._errorCode = errorCode; args._bytesWritten = bytesWritten; args._overlapped = overlapped; args._data = data; ExecutionContext.Run(data._executionContext, callback, args); }
public void Invoke() { if (FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.ThreadTransfer)) { EtwFireThreadTransferReceiveObj(this); } if (_executionContext == null) { InvokeCore(); } else { ExecutionContext.Run(_executionContext, s_contextCallback, this); } // If there was an ETW event that fired at the top of the winrt event handling loop, ETW listeners could // use it as a marker of completion of the previous request. Since such an event does not exist we need to // fire the "done handling off-thread request" event in order to enable correct work item assignment. if (FrameworkEventSource.Log.IsEnabled(EventLevel.Informational, FrameworkEventSource.Keywords.ThreadTransfer)) { EtwFireThreadTransferReceiveHandledObj(this); } }