~ubuntu-branches/ubuntu/lucid/monodevelop/lucid

« back to all changes in this revision

Viewing changes to src/core/Mono.Debugging/Mono.Debugging.Evaluation/TimedEvaluator.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-01-10 14:25:59 UTC
  • mfrom: (1.2.5 upstream) (1.3.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100110142559-sorji5exvk9tyknr
Tags: 2.2+dfsg-2
* debian/rules/remove_support_for_non_debian_functionality.patch:
  + Also fix monodevelop-core-addins.pc to remove links to the
    addins we remove in Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
                int runningThreads;
43
43
                bool mainThreadBusy;
44
44
                bool useTimeout;
 
45
                bool disposed;
45
46
                
46
47
                public TimedEvaluator (): this (true)
47
48
                {
55
56
 
56
57
                public int RunTimeout { get; set; }
57
58
 
 
59
                public bool IsEvaluating {
 
60
                        get {
 
61
                                lock (runningLock) {
 
62
                                        return pendingTasks.Count > 0 || mainThreadBusy;
 
63
                                }
 
64
                        }
 
65
                }
 
66
                
 
67
                void OnStartEval ()
 
68
                {
 
69
//                      Console.WriteLine ("Eval Started");
 
70
                }
 
71
                
 
72
                void OnEndEval ()
 
73
                {
 
74
//                      lock (runningLock) {
 
75
//                              Console.WriteLine ("Eval Finished ({0} pending)", pendingTasks.Count);
 
76
//                      }
 
77
                }
 
78
                
58
79
                public bool Run (EvaluatorDelegate evaluator, EvaluatorDelegate delayedDoneCallback)
59
80
                {
60
81
                        if (!useTimeout) {
71
92
                                        if (runningThreads < maxThreads) {
72
93
                                                runningThreads++;
73
94
                                                Thread tr = new Thread (Runner);
 
95
                                                tr.Name = "Debugger evaluator";
74
96
                                                tr.IsBackground = true;
75
97
                                                tr.Start ();
76
98
                                        } else {
84
106
                                mainThreadBusy = true;
85
107
                        }
86
108
                        
 
109
                        OnStartEval ();
87
110
                        currentTask = task;
88
111
                        newTaskEvent.Set ();
89
112
                        task.RunningEvent.WaitOne ();
106
129
                {
107
130
                        Task threadTask = null;
108
131
                        
109
 
                        while (true) {
 
132
                        while (!disposed) {
110
133
 
111
134
                                if (threadTask == null) {
112
135
                                        newTaskEvent.WaitOne ();
 
136
                                        
 
137
                                        lock (runningLock) {
 
138
                                                if (disposed) {
 
139
                                                        runningThreads--;
 
140
                                                        return;
 
141
                                                }
 
142
                                        }
 
143
                                        
113
144
                                        threadTask = currentTask;
114
145
                                        currentTask = null;
115
146
                                }
119
150
                                threadTask.RunFinishedEvent.Set ();
120
151
 
121
152
                                Task curTask = threadTask;
122
 
                                threadTask = null;
 
153
                                threadTask = null;
 
154
                                
 
155
                                OnEndEval ();
123
156
 
 
157
                                lock (runningLock) {
 
158
                                        if (disposed) {
 
159
                                                runningThreads--;
 
160
                                                return;
 
161
                                        }
 
162
                                }
 
163
                                
124
164
                                lock (curTask) {
125
 
                                        if (curTask.TimedOut)
126
 
                                                SafeRun (curTask.FinishedCallback);
127
 
                                        else
 
165
                                        if (!curTask.TimedOut)
128
166
                                                continue; // Done. Keep waiting for more tasks.
 
167
                                        
 
168
                                        SafeRun (curTask.FinishedCallback);
129
169
                                }
130
 
                                
 
170
 
131
171
                                // The task timed out, so more threads may already have
132
172
                                // been created while this one was busy.
133
173
                                
135
175
                                        Monitor.PulseAll (runningLock);
136
176
                                        if (pendingTasks.Count > 0) {
137
177
                                                // There is pending work to do.
 
178
                                                OnStartEval ();
138
179
                                                threadTask = pendingTasks.Dequeue ();
139
180
                                        }
140
181
                                        else if (mainThreadBusy) {
151
192
                                }
152
193
                        }
153
194
                }
 
195
                
 
196
                public void Dispose ()
 
197
                {
 
198
                        disposed = true;
 
199
                        CancelAll ();
 
200
                        newTaskEvent.Set ();
 
201
                }
154
202
 
155
203
                public void CancelAll ()
156
204
                {
157
205
                        lock (runningLock) {
158
206
                                pendingTasks.Clear ();
 
207
                                Monitor.PulseAll (runningLock);
159
208
                        }
160
209
                }
161
210