1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
@@ -75,9 +75,9 namespace Implab.Diagnostics { | |||||
75 | /// <summary> |
|
75 | /// <summary> | |
76 | /// Создает постоянную копию текущего контекста, данную копию можно хранить и использовать для передачи через <see cref="Transfer(TraceContext)"/> |
|
76 | /// Создает постоянную копию текущего контекста, данную копию можно хранить и использовать для передачи через <see cref="Transfer(TraceContext)"/> | |
77 | /// </summary> |
|
77 | /// </summary> | |
78 |
/// <returns>Копия текущего контекста трассировки |
|
78 | /// <returns>Копия текущего контекста трассировки.</returns> | |
79 | public static TraceContext Snapshot() { |
|
79 | public static TraceContext Snapshot() { | |
80 |
return _current == null ? n |
|
80 | return _current == null ? new TraceContext() : new TraceContext(_current); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | /// <summary> |
|
83 | /// <summary> |
@@ -1,4 +1,5 | |||||
1 | using System; |
|
1 | using Implab.Diagnostics; | |
|
2 | using System; | |||
2 | using System.Collections.Generic; |
|
3 | using System.Collections.Generic; | |
3 | using System.Diagnostics; |
|
4 | using System.Diagnostics; | |
4 | using System.Linq; |
|
5 | using System.Linq; | |
@@ -11,6 +12,7 namespace Implab.Parallels { | |||||
11 | readonly Action<TSrc> m_action; |
|
12 | readonly Action<TSrc> m_action; | |
12 | readonly TSrc[] m_source; |
|
13 | readonly TSrc[] m_source; | |
13 | readonly Promise<int> m_promise = new Promise<int>(); |
|
14 | readonly Promise<int> m_promise = new Promise<int>(); | |
|
15 | readonly TraceContext m_traceContext; | |||
14 |
|
16 | |||
15 | int m_pending; |
|
17 | int m_pending; | |
16 | int m_next; |
|
18 | int m_next; | |
@@ -21,6 +23,7 namespace Implab.Parallels { | |||||
21 | Debug.Assert(source != null); |
|
23 | Debug.Assert(source != null); | |
22 | Debug.Assert(action != null); |
|
24 | Debug.Assert(action != null); | |
23 |
|
25 | |||
|
26 | m_traceContext = TraceContext.Snapshot(); | |||
24 | m_next = 0; |
|
27 | m_next = 0; | |
25 | m_source = source; |
|
28 | m_source = source; | |
26 | m_pending = source.Length; |
|
29 | m_pending = source.Length; | |
@@ -38,6 +41,11 namespace Implab.Parallels { | |||||
38 | } |
|
41 | } | |
39 | } |
|
42 | } | |
40 |
|
43 | |||
|
44 | protected override void Worker() { | |||
|
45 | TraceContext.Transfer(m_traceContext); | |||
|
46 | base.Worker(); | |||
|
47 | } | |||
|
48 | ||||
41 | protected override bool TryDequeue(out int unit) { |
|
49 | protected override bool TryDequeue(out int unit) { | |
42 | unit = Interlocked.Increment(ref m_next) - 1; |
|
50 | unit = Interlocked.Increment(ref m_next) - 1; | |
43 | return unit >= m_source.Length ? false : true; |
|
51 | return unit >= m_source.Length ? false : true; | |
@@ -60,6 +68,7 namespace Implab.Parallels { | |||||
60 | readonly TSrc[] m_source; |
|
68 | readonly TSrc[] m_source; | |
61 | readonly TDst[] m_dest; |
|
69 | readonly TDst[] m_dest; | |
62 | readonly Promise<TDst[]> m_promise = new Promise<TDst[]>(); |
|
70 | readonly Promise<TDst[]> m_promise = new Promise<TDst[]>(); | |
|
71 | readonly TraceContext m_traceContext; | |||
63 |
|
72 | |||
64 | int m_pending; |
|
73 | int m_pending; | |
65 | int m_next; |
|
74 | int m_next; | |
@@ -75,6 +84,7 namespace Implab.Parallels { | |||||
75 | m_dest = new TDst[source.Length]; |
|
84 | m_dest = new TDst[source.Length]; | |
76 | m_pending = source.Length; |
|
85 | m_pending = source.Length; | |
77 | m_transform = transform; |
|
86 | m_transform = transform; | |
|
87 | m_traceContext = TraceContext.Snapshot(); | |||
78 |
|
88 | |||
79 | m_promise.Anyway(() => Dispose()); |
|
89 | m_promise.Anyway(() => Dispose()); | |
80 | m_promise.Cancelled(() => Dispose()); |
|
90 | m_promise.Cancelled(() => Dispose()); | |
@@ -88,6 +98,11 namespace Implab.Parallels { | |||||
88 | } |
|
98 | } | |
89 | } |
|
99 | } | |
90 |
|
100 | |||
|
101 | protected override void Worker() { | |||
|
102 | TraceContext.Transfer(m_traceContext); | |||
|
103 | base.Worker(); | |||
|
104 | } | |||
|
105 | ||||
91 | protected override bool TryDequeue(out int unit) { |
|
106 | protected override bool TryDequeue(out int unit) { | |
92 | unit = Interlocked.Increment(ref m_next) - 1; |
|
107 | unit = Interlocked.Increment(ref m_next) - 1; | |
93 | return unit >= m_source.Length ? false : true; |
|
108 | return unit >= m_source.Length ? false : true; |
@@ -274,7 +274,7 namespace Implab.Parallels { | |||||
274 |
|
274 | |||
275 | protected abstract void InvokeUnit(TUnit unit); |
|
275 | protected abstract void InvokeUnit(TUnit unit); | |
276 |
|
276 | |||
277 | void Worker() { |
|
277 | protected virtual void Worker() { | |
278 | TUnit unit; |
|
278 | TUnit unit; | |
279 | //Console.WriteLine("{0}: Active", Thread.CurrentThread.ManagedThreadId); |
|
279 | //Console.WriteLine("{0}: Active", Thread.CurrentThread.ManagedThreadId); | |
280 | Interlocked.Increment(ref m_activeThreads); |
|
280 | Interlocked.Increment(ref m_activeThreads); |
General Comments 0
You need to be logged in to leave comments.
Login now