@@ -23,16 +23,21 namespace Implab.Parallels { | |||
|
23 | 23 | |
|
24 | 24 | public T GetItem(int timeout) { |
|
25 | 25 | T item; |
|
26 | var t1 = Environment.TickCount; | |
|
27 | var dt = timeout; | |
|
28 | while (!TryDequeue(out item)) { | |
|
29 | lock (m_lock) | |
|
30 | if (!Monitor.Wait(m_lock, dt)) | |
|
31 | throw new TimeoutException(); | |
|
32 |
|
|
|
33 | dt = timeout - Environment.TickCount + t1; | |
|
34 | if (dt < 0) | |
|
35 |
|
|
|
26 | ||
|
27 | if (!TryDequeue(out item)) { | |
|
28 | var t1 = Environment.TickCount; | |
|
29 | var dt = timeout; | |
|
30 | ||
|
31 | lock (m_lock) { | |
|
32 | while (!TryDequeue(out item)) { | |
|
33 | if (!Monitor.Wait(m_lock, dt)) | |
|
34 | throw new TimeoutException(); | |
|
35 | if (timeout >= 0) { | |
|
36 | dt = timeout - Environment.TickCount + t1; | |
|
37 | if (dt < 0) | |
|
38 | throw new TimeoutException(); | |
|
39 | } | |
|
40 | } | |
|
36 | 41 | } |
|
37 | 42 | } |
|
38 | 43 | return item; |
@@ -40,9 +45,11 namespace Implab.Parallels { | |||
|
40 | 45 | |
|
41 | 46 | public T GetItem() { |
|
42 | 47 | T item; |
|
43 |
|
|
|
44 | lock (m_lock) | |
|
45 | Monitor.Wait(m_lock); | |
|
48 | if (!TryDequeue(out item)) | |
|
49 | lock (m_lock) { | |
|
50 | while (!TryDequeue(out item)) | |
|
51 | Monitor.Wait(m_lock); | |
|
52 | } | |
|
46 | 53 | return item; |
|
47 | 54 | } |
|
48 | 55 | |
@@ -51,16 +58,22 namespace Implab.Parallels { | |||
|
51 | 58 | |
|
52 | 59 | var buffer = new T[max]; |
|
53 | 60 | int actual; |
|
54 | var t1 = Environment.TickCount; | |
|
55 |
var |
|
|
56 | while (!TryDequeueRange(buffer,0,max,out actual)) { | |
|
57 | lock (m_lock) | |
|
58 |
|
|
|
59 | throw new TimeoutException(); | |
|
60 |
|
|
|
61 | dt = timeout - Environment.TickCount + t1; | |
|
62 | if (dt < 0) | |
|
63 | throw new TimeoutException(); | |
|
61 | if (!TryDequeueRange(buffer, 0, max, out actual)) { | |
|
62 | var t1 = Environment.TickCount; | |
|
63 | var dt = timeout; | |
|
64 | ||
|
65 | lock (m_lock) { | |
|
66 | while (!TryDequeueRange(buffer, 0, max, out actual)) { | |
|
67 | ||
|
68 | if (!Monitor.Wait(m_lock, dt)) | |
|
69 | throw new TimeoutException(); | |
|
70 | ||
|
71 | if (timeout >= 0) { | |
|
72 | dt = timeout - Environment.TickCount + t1; | |
|
73 | if (dt < 0) | |
|
74 | throw new TimeoutException(); | |
|
75 | } | |
|
76 | } | |
|
64 | 77 | } |
|
65 | 78 | } |
|
66 | 79 | |
@@ -74,9 +87,10 namespace Implab.Parallels { | |||
|
74 | 87 | |
|
75 | 88 | var buffer = new T[max]; |
|
76 | 89 | int actual; |
|
77 |
|
|
|
90 | if (!TryDequeueRange(buffer, 0, max, out actual)) | |
|
78 | 91 | lock (m_lock) |
|
79 | Monitor.Wait(m_lock); | |
|
92 | while (!TryDequeueRange(buffer, 0, max, out actual)) | |
|
93 | Monitor.Wait(m_lock); | |
|
80 | 94 | |
|
81 | 95 | var data = new T[actual]; |
|
82 | 96 | Array.Copy(buffer, data, actual); |
General Comments 0
You need to be logged in to leave comments.
Login now