@@ -0,0 +1,31 | |||
|
1 | using System; | |
|
2 | using System.Threading; | |
|
3 | ||
|
4 | namespace Implab.Parallels { | |
|
5 | /// <summary> | |
|
6 | /// Implements simple signalling logic using <see cref="Monitor.PulseAll(object)"/>. | |
|
7 | /// </summary> | |
|
8 | public class Signal { | |
|
9 | readonly object m_lock = new object(); | |
|
10 | bool m_state; | |
|
11 | ||
|
12 | public void Set() { | |
|
13 | lock(m_lock) { | |
|
14 | m_state = true; | |
|
15 | Monitor.PulseAll(m_lock); | |
|
16 | } | |
|
17 | } | |
|
18 | ||
|
19 | public void Wait() { | |
|
20 | lock (m_lock) | |
|
21 | if (!m_state) | |
|
22 | Monitor.Wait(m_lock); | |
|
23 | } | |
|
24 | ||
|
25 | public bool Wait(int timeout) { | |
|
26 | lock (m_lock) | |
|
27 | return m_state || Monitor.Wait(m_lock, timeout); | |
|
28 | } | |
|
29 | } | |
|
30 | } | |
|
31 |
@@ -155,6 +155,7 | |||
|
155 | 155 | <Compile Include="AbstractPromise.cs" /> |
|
156 | 156 | <Compile Include="Promise.cs" /> |
|
157 | 157 | <Compile Include="PromiseTransientException.cs" /> |
|
158 | <Compile Include="Parallels\Signal.cs" /> | |
|
158 | 159 | </ItemGroup> |
|
159 | 160 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> |
|
160 | 161 | <ItemGroup /> |
@@ -454,7 +454,7 namespace Implab.Parallels { | |||
|
454 | 454 | } while(true); |
|
455 | 455 | } |
|
456 | 456 | |
|
457 | T[] ReadChunks(Chunk chunk, object last) { | |
|
457 | static T[] ReadChunks(Chunk chunk, object last) { | |
|
458 | 458 | var result = new List<T>(); |
|
459 | 459 | var buffer = new T[DEFAULT_CHUNK_SIZE]; |
|
460 | 460 | int actual; |
@@ -36,13 +36,26 namespace Implab | |||
|
36 | 36 | throw new ArgumentOutOfRangeException(paramName); |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | public static void Dispose(params IDisposable[] objects) | |
|
40 | { | |
|
41 | foreach(var d in objects) | |
|
39 | public static void Dispose(params IDisposable[] objects) { | |
|
40 | foreach (var d in objects) | |
|
42 | 41 | if (d != null) |
|
43 | 42 | d.Dispose(); |
|
44 | 43 | } |
|
45 | 44 | |
|
45 | public static void Dispose(params object[] objects) { | |
|
46 | foreach (var obj in objects) { | |
|
47 | var d = obj as IDisposable; | |
|
48 | if (d != null) | |
|
49 | d.Dispose(); | |
|
50 | } | |
|
51 | } | |
|
52 | ||
|
53 | public static void Dispose(object obj) { | |
|
54 | var d = obj as IDisposable; | |
|
55 | if (d != null) | |
|
56 | d.Dispose(); | |
|
57 | } | |
|
58 | ||
|
46 | 59 | [DebuggerStepThrough] |
|
47 | 60 | public static IPromise<T> InvokePromise<T>(Func<T> action) { |
|
48 | 61 | ArgumentNotNull(action, "action"); |
General Comments 0
You need to be logged in to leave comments.
Login now