comparison org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/LockManager.d @ 19:52184e4b815c

no more direct tango.core.Thread. Rename JThread to java.lang.Thread.
author Frank Benoit <benoit@tionex.de>
date Wed, 18 Mar 2009 10:55:25 +0100
parents bc29606a740c
children
comparison
equal deleted inserted replaced
18:735224fcc45f 19:52184e4b815c
10 * Port to the D programming language: 10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de> 11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/ 12 *******************************************************************************/
13 module org.eclipse.core.internal.jobs.LockManager; 13 module org.eclipse.core.internal.jobs.LockManager;
14 14
15 import java.lang.JThread; 15 import java.lang.Thread;
16 import java.lang.all; 16 import java.lang.all;
17 import java.util.Stack; 17 import java.util.Stack;
18 import java.util.HashMap; 18 import java.util.HashMap;
19 import java.util.Set; 19 import java.util.Set;
20 20
115 } 115 }
116 116
117 /* (non-Javadoc) 117 /* (non-Javadoc)
118 * Method declared on LockListener 118 * Method declared on LockListener
119 */ 119 */
120 public bool aboutToWait(JThread lockOwner) { 120 public bool aboutToWait(Thread lockOwner) {
121 if (lockListener is null) 121 if (lockListener is null)
122 return false; 122 return false;
123 try { 123 try {
124 return lockListener.aboutToWait(lockOwner); 124 return lockListener.aboutToWait(lockOwner);
125 } catch (Exception e) { 125 } catch (Exception e) {
131 } 131 }
132 132
133 /** 133 /**
134 * This thread has just acquired a lock. Update graph. 134 * This thread has just acquired a lock. Update graph.
135 */ 135 */
136 void addLockThread(JThread thread, ISchedulingRule lock) { 136 void addLockThread(Thread thread, ISchedulingRule lock) {
137 if (locks is null) 137 if (locks is null)
138 return; 138 return;
139 try { 139 try {
140 synchronized (locks) { 140 synchronized (locks) {
141 locks.lockAcquired(thread, lock); 141 locks.lockAcquired(thread, lock);
146 } 146 }
147 147
148 /** 148 /**
149 * This thread has just been refused a lock. Update graph and check for deadlock. 149 * This thread has just been refused a lock. Update graph and check for deadlock.
150 */ 150 */
151 void addLockWaitThread(JThread thread, ISchedulingRule lock) { 151 void addLockWaitThread(Thread thread, ISchedulingRule lock) {
152 if (locks is null) 152 if (locks is null)
153 return; 153 return;
154 try { 154 try {
155 Deadlock found = null; 155 Deadlock found = null;
156 synchronized (locks) { 156 synchronized (locks) {
220 * Returns true IFF this thread either owns, or is waiting for, any locks or rules. 220 * Returns true IFF this thread either owns, or is waiting for, any locks or rules.
221 */ 221 */
222 public bool isLockOwner() { 222 public bool isLockOwner() {
223 //all job threads have to be treated as lock owners because UI thread 223 //all job threads have to be treated as lock owners because UI thread
224 //may try to join a job 224 //may try to join a job
225 JThread current = JThread.currentThread(); 225 Thread current = Thread.currentThread();
226 if (cast(Worker)current ) 226 if (cast(Worker)current )
227 return true; 227 return true;
228 if (locks is null) 228 if (locks is null)
229 return false; 229 return false;
230 synchronized (locks) { 230 synchronized (locks) {
231 return locks.contains(JThread.currentThread()); 231 return locks.contains(Thread.currentThread());
232 } 232 }
233 } 233 }
234 234
235 /** 235 /**
236 * Creates and returns a new lock. 236 * Creates and returns a new lock.
240 } 240 }
241 241
242 /** 242 /**
243 * Releases all the acquires that were called on the given rule. Needs to be called only once. 243 * Releases all the acquires that were called on the given rule. Needs to be called only once.
244 */ 244 */
245 void removeLockCompletely(JThread thread, ISchedulingRule rule) { 245 void removeLockCompletely(Thread thread, ISchedulingRule rule) {
246 if (locks is null) 246 if (locks is null)
247 return; 247 return;
248 try { 248 try {
249 synchronized (locks) { 249 synchronized (locks) {
250 locks.lockReleasedCompletely(thread, rule); 250 locks.lockReleasedCompletely(thread, rule);
255 } 255 }
256 256
257 /** 257 /**
258 * This thread has just released a lock. Update graph. 258 * This thread has just released a lock. Update graph.
259 */ 259 */
260 void removeLockThread(JThread thread, ISchedulingRule lock) { 260 void removeLockThread(Thread thread, ISchedulingRule lock) {
261 try { 261 try {
262 synchronized (locks) { 262 synchronized (locks) {
263 locks.lockReleased(thread, lock); 263 locks.lockReleased(thread, lock);
264 } 264 }
265 } catch (Exception e) { 265 } catch (Exception e) {
268 } 268 }
269 269
270 /** 270 /**
271 * This thread has just stopped waiting for a lock. Update graph. 271 * This thread has just stopped waiting for a lock. Update graph.
272 */ 272 */
273 void removeLockWaitThread(JThread thread, ISchedulingRule lock) { 273 void removeLockWaitThread(Thread thread, ISchedulingRule lock) {
274 try { 274 try {
275 synchronized (locks) { 275 synchronized (locks) {
276 locks.lockWaitStop(thread, lock); 276 locks.lockWaitStop(thread, lock);
277 } 277 }
278 } catch (Exception e) { 278 } catch (Exception e) {
281 } 281 }
282 282
283 /** 283 /**
284 * Resumes all the locks that were suspended while this thread was waiting to acquire another lock. 284 * Resumes all the locks that were suspended while this thread was waiting to acquire another lock.
285 */ 285 */
286 void resumeSuspendedLocks(JThread owner) { 286 void resumeSuspendedLocks(Thread owner) {
287 LockState[] toResume; 287 LockState[] toResume;
288 synchronized (suspendedLocks) { 288 synchronized (suspendedLocks) {
289 Stack prevLocks = cast(Stack) suspendedLocks.get(owner); 289 Stack prevLocks = cast(Stack) suspendedLocks.get(owner);
290 if (prevLocks is null) 290 if (prevLocks is null)
291 return; 291 return;