void ThreadStart() { /* Allow scheduler to break fairness of deque ordering without * breaking its semantic (the task can be executed twice but the * second time it will return immediately */ if (!executing.TryRelaxedSet()) { return; } // Disable CancellationToken direct cancellation if (cancellationRegistration != null) { cancellationRegistration.Value.Dispose(); cancellationRegistration = null; } // If Task are ran inline on the same thread we might trash these values var saveCurrent = current; var saveScheduler = TaskScheduler.Current; current = this; TaskScheduler.Current = scheduler; if (!token.IsCancellationRequested) { status = TaskStatus.Running; try { InnerInvoke(); } catch (OperationCanceledException oce) { if (token != CancellationToken.None && oce.CancellationToken == token) { CancelReal(); } else { HandleGenericException(oce); } } catch (Exception e) { HandleGenericException(e); } } else { CancelReal(); } if (saveCurrent != null) { current = saveCurrent; } if (saveScheduler != null) { TaskScheduler.Current = saveScheduler; } Finish(); }
public void Execute() { if (!executed.TryRelaxedSet()) { return; } bool owner_notified = false; for (int i = 0; i < tasks.Count; ++i) { var task = tasks[i]; if (!task.IsCompleted) { task.RemoveContinuation(this); continue; } if (owner_notified) { continue; } owner.TrySetResult(task); owner_notified = true; } }
public DataflowMessageStatus OfferMessage(DataflowMessageHeader messageHeader, T messageValue, ISourceBlock <T> source, bool consumeToAccept) { if (written.TryRelaxedSet()) { Thread.MemoryBarrier(); finalValue = messageValue; Thread.MemoryBarrier(); ready = true; return(messageBox.OfferMessage(this, messageHeader, finalValue, source, consumeToAccept)); } else { return(DataflowMessageStatus.DecliningPermanently); } }
public void Execute() { if (!executed.TryRelaxedSet()) { return; } for (int i = 0; i < tasks.Count; ++i) { var task = tasks[i]; if (!task.IsCompleted) { continue; } owner.TrySetResult(task); return; } }
protected virtual void Dispose(bool disposing) { if (!disposed.TryRelaxedSet()) { return; } if (handle != null) { var tmpHandle = Interlocked.Exchange(ref handle, null); if (used > 0) { SpinWait wait = new SpinWait(); while (used > 0) { wait.SpinOnce(); } } ((IDisposable)tmpHandle).Dispose(); } }
public void Dispose() { TargetWaiter t; Disabled = true; Thread.MemoryBarrier(); if (queue.TryPeek(out t) && t == this && removed.TryRelaxedSet()) { queue.TryDequeue(out t); } else { SpinWait wait = new SpinWait(); while (queue.TryPeek(out t) && t == this) { wait.SpinOnce(); } } }
void ThreadStart() { /* Allow scheduler to break fairness of deque ordering without * breaking its semantic (the task can be executed twice but the * second time it will return immediately */ if (!executing.TryRelaxedSet()) { return; } current = this; TaskScheduler.Current = scheduler; if (!token.IsCancellationRequested) { status = TaskStatus.Running; try { InnerInvoke(); } catch (OperationCanceledException oce) { if (oce.CancellationToken == token) { CancelReal(); } else { HandleGenericException(oce); } } catch (Exception e) { HandleGenericException(e); } } else { CancelReal(); } Finish(); }
protected virtual void Dispose(bool disposing) { if (!disposed.TryRelaxedSet()) { return; } if (handle != null) { var tmpHandle = Interlocked.Exchange(ref handle, null); if (used > 0) { // A tiny wait (just a few cycles normally) before releasing SpinWait wait = new SpinWait(); while (used > 0) { wait.SpinOnce(); } } tmpHandle.Dispose(); } }
protected virtual void Dispose(bool disposing) { if (!disposed.TryRelaxedSet()) { return; } if (handle != null) { var tmpHandle = AotInterlocked.Exchange(ref handle, null); if (used > 0) { // A tiny wait (just a few cycles normally) before releasing SpinWait wait = new SpinWait(); while (used > 0) { wait.SpinOnce(); } } // Spicy Pixel: Must use the public interface (e.g. Close) tmpHandle.Close(); // tmpHandle.Dispose (); } }