Mercurial > pub > ImplabNet
comparison Implab/Parallels/ArrayTraits.cs @ 92:4c0e5ef99986 v2
rewritten tracing
author | cin |
---|---|
date | Wed, 22 Oct 2014 18:37:56 +0400 |
parents | ce0171cacec4 |
children | 279e226dffdd |
comparison
equal
deleted
inserted
replaced
91:cdaaf4792c22 | 92:4c0e5ef99986 |
---|---|
10 public static class ArrayTraits { | 10 public static class ArrayTraits { |
11 class ArrayIterator<TSrc> : DispatchPool<int> { | 11 class ArrayIterator<TSrc> : DispatchPool<int> { |
12 readonly Action<TSrc> m_action; | 12 readonly Action<TSrc> m_action; |
13 readonly TSrc[] m_source; | 13 readonly TSrc[] m_source; |
14 readonly Promise<int> m_promise = new Promise<int>(); | 14 readonly Promise<int> m_promise = new Promise<int>(); |
15 readonly TraceContext m_traceContext; | 15 readonly LogicalOperation m_logicalOperation; |
16 | 16 |
17 int m_pending; | 17 int m_pending; |
18 int m_next; | 18 int m_next; |
19 | 19 |
20 public ArrayIterator(TSrc[] source, Action<TSrc> action, int threads) | 20 public ArrayIterator(TSrc[] source, Action<TSrc> action, int threads) |
21 : base(threads) { | 21 : base(threads) { |
22 | 22 |
23 Debug.Assert(source != null); | 23 Debug.Assert(source != null); |
24 Debug.Assert(action != null); | 24 Debug.Assert(action != null); |
25 | 25 |
26 m_traceContext = TraceContext.Snapshot(); | 26 m_logicalOperation = TraceContext.Instance.CurrentOperation; |
27 m_next = 0; | 27 m_next = 0; |
28 m_source = source; | 28 m_source = source; |
29 m_pending = source.Length; | 29 m_pending = source.Length; |
30 m_action = action; | 30 m_action = action; |
31 | 31 |
39 return m_promise; | 39 return m_promise; |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 protected override void Worker() { | 43 protected override void Worker() { |
44 TraceContext.Fork(m_traceContext); | 44 TraceContext.Instance.EnterLogicalOperation(m_logicalOperation, false); |
45 base.Worker(); | 45 try { |
46 base.Worker(); | |
47 } finally { | |
48 TraceContext.Instance.Leave(); | |
49 } | |
46 } | 50 } |
47 | 51 |
48 protected override bool TryDequeue(out int unit) { | 52 protected override bool TryDequeue(out int unit) { |
49 unit = Interlocked.Increment(ref m_next) - 1; | 53 unit = Interlocked.Increment(ref m_next) - 1; |
50 return unit < m_source.Length; | 54 return unit < m_source.Length; |
65 class ArrayMapper<TSrc, TDst>: DispatchPool<int> { | 69 class ArrayMapper<TSrc, TDst>: DispatchPool<int> { |
66 readonly Func<TSrc, TDst> m_transform; | 70 readonly Func<TSrc, TDst> m_transform; |
67 readonly TSrc[] m_source; | 71 readonly TSrc[] m_source; |
68 readonly TDst[] m_dest; | 72 readonly TDst[] m_dest; |
69 readonly Promise<TDst[]> m_promise = new Promise<TDst[]>(); | 73 readonly Promise<TDst[]> m_promise = new Promise<TDst[]>(); |
70 readonly TraceContext m_traceContext; | 74 readonly LogicalOperation m_logicalOperation; |
71 | 75 |
72 int m_pending; | 76 int m_pending; |
73 int m_next; | 77 int m_next; |
74 | 78 |
75 public ArrayMapper(TSrc[] source, Func<TSrc, TDst> transform, int threads) | 79 public ArrayMapper(TSrc[] source, Func<TSrc, TDst> transform, int threads) |
81 m_next = 0; | 85 m_next = 0; |
82 m_source = source; | 86 m_source = source; |
83 m_dest = new TDst[source.Length]; | 87 m_dest = new TDst[source.Length]; |
84 m_pending = source.Length; | 88 m_pending = source.Length; |
85 m_transform = transform; | 89 m_transform = transform; |
86 m_traceContext = TraceContext.Snapshot(); | 90 m_logicalOperation = TraceContext.Instance.CurrentOperation; |
87 | 91 |
88 m_promise.Anyway(Dispose); | 92 m_promise.Anyway(Dispose); |
89 | 93 |
90 InitPool(); | 94 InitPool(); |
91 } | 95 } |
95 return m_promise; | 99 return m_promise; |
96 } | 100 } |
97 } | 101 } |
98 | 102 |
99 protected override void Worker() { | 103 protected override void Worker() { |
100 TraceContext.Fork(m_traceContext); | 104 TraceContext.Instance.EnterLogicalOperation(m_logicalOperation,false); |
101 base.Worker(); | 105 try { |
106 base.Worker(); | |
107 } finally { | |
108 TraceContext.Instance.Leave(); | |
109 } | |
102 } | 110 } |
103 | 111 |
104 protected override bool TryDequeue(out int unit) { | 112 protected override bool TryDequeue(out int unit) { |
105 unit = Interlocked.Increment(ref m_next) - 1; | 113 unit = Interlocked.Increment(ref m_next) - 1; |
106 return unit >= m_source.Length ? false : true; | 114 return unit < m_source.Length; |
107 } | 115 } |
108 | 116 |
109 protected override void InvokeUnit(int unit) { | 117 protected override void InvokeUnit(int unit) { |
110 try { | 118 try { |
111 m_dest[unit] = m_transform(m_source[unit]); | 119 m_dest[unit] = m_transform(m_source[unit]); |