Mercurial > pub > ImplabNet
changeset 41:2fc0fbe7d58b
Added TraceContext support to array traits
author | cin |
---|---|
date | Tue, 15 Apr 2014 18:06:34 +0400 |
parents | fe33f4e02ad5 |
children | 3ba6778ed336 |
files | Implab.v11.suo Implab/Diagnostics/TraceContext.cs Implab/Parallels/ArrayTraits.cs Implab/Parallels/DispatchPool.cs |
diffstat | 4 files changed, 19 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/Implab/Diagnostics/TraceContext.cs Tue Apr 15 17:52:09 2014 +0400 +++ b/Implab/Diagnostics/TraceContext.cs Tue Apr 15 18:06:34 2014 +0400 @@ -75,9 +75,9 @@ /// <summary> /// Создает постоянную копию текущего контекста, данную копию можно хранить и использовать для передачи через <see cref="Transfer(TraceContext)"/> /// </summary> - /// <returns>Копия текущего контекста трассировки или <c>null</c> если таковой не был создан.</returns> + /// <returns>Копия текущего контекста трассировки.</returns> public static TraceContext Snapshot() { - return _current == null ? null : new TraceContext(_current); + return _current == null ? new TraceContext() : new TraceContext(_current); } /// <summary>
--- a/Implab/Parallels/ArrayTraits.cs Tue Apr 15 17:52:09 2014 +0400 +++ b/Implab/Parallels/ArrayTraits.cs Tue Apr 15 18:06:34 2014 +0400 @@ -1,4 +1,5 @@ -using System; +using Implab.Diagnostics; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -11,6 +12,7 @@ readonly Action<TSrc> m_action; readonly TSrc[] m_source; readonly Promise<int> m_promise = new Promise<int>(); + readonly TraceContext m_traceContext; int m_pending; int m_next; @@ -21,6 +23,7 @@ Debug.Assert(source != null); Debug.Assert(action != null); + m_traceContext = TraceContext.Snapshot(); m_next = 0; m_source = source; m_pending = source.Length; @@ -38,6 +41,11 @@ } } + protected override void Worker() { + TraceContext.Transfer(m_traceContext); + base.Worker(); + } + protected override bool TryDequeue(out int unit) { unit = Interlocked.Increment(ref m_next) - 1; return unit >= m_source.Length ? false : true; @@ -60,6 +68,7 @@ readonly TSrc[] m_source; readonly TDst[] m_dest; readonly Promise<TDst[]> m_promise = new Promise<TDst[]>(); + readonly TraceContext m_traceContext; int m_pending; int m_next; @@ -75,6 +84,7 @@ m_dest = new TDst[source.Length]; m_pending = source.Length; m_transform = transform; + m_traceContext = TraceContext.Snapshot(); m_promise.Anyway(() => Dispose()); m_promise.Cancelled(() => Dispose()); @@ -88,6 +98,11 @@ } } + protected override void Worker() { + TraceContext.Transfer(m_traceContext); + base.Worker(); + } + protected override bool TryDequeue(out int unit) { unit = Interlocked.Increment(ref m_next) - 1; return unit >= m_source.Length ? false : true;
--- a/Implab/Parallels/DispatchPool.cs Tue Apr 15 17:52:09 2014 +0400 +++ b/Implab/Parallels/DispatchPool.cs Tue Apr 15 18:06:34 2014 +0400 @@ -274,7 +274,7 @@ protected abstract void InvokeUnit(TUnit unit); - void Worker() { + protected virtual void Worker() { TUnit unit; //Console.WriteLine("{0}: Active", Thread.CurrentThread.ManagedThreadId); Interlocked.Increment(ref m_activeThreads);