Mercurial > projects > dwt-addons
comparison dwtx/core/internal/jobs/LockManager.d @ 167:862b05e0334a
Add a wrapper for Thread
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 09 Sep 2008 15:59:16 +0200 |
parents | 9d0585bcb7aa |
children |
comparison
equal
deleted
inserted
replaced
163:e5dd0081ccba | 167:862b05e0334a |
---|---|
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 dwtx.core.internal.jobs.LockManager; | 13 module dwtx.core.internal.jobs.LockManager; |
14 | 14 |
15 import tango.core.Thread; | 15 import dwtx.dwtxhelper.JThread; |
16 import dwt.dwthelper.utils; | 16 import dwt.dwthelper.utils; |
17 import dwtx.dwtxhelper.Collection; | 17 import dwtx.dwtxhelper.Collection; |
18 | 18 |
19 import dwtx.core.internal.runtime.RuntimeLog; | 19 import dwtx.core.internal.runtime.RuntimeLog; |
20 import dwtx.core.runtime.CoreException; | 20 import dwtx.core.runtime.CoreException; |
113 } | 113 } |
114 | 114 |
115 /* (non-Javadoc) | 115 /* (non-Javadoc) |
116 * Method declared on LockListener | 116 * Method declared on LockListener |
117 */ | 117 */ |
118 public bool aboutToWait(Thread lockOwner) { | 118 public bool aboutToWait(JThread lockOwner) { |
119 if (lockListener is null) | 119 if (lockListener is null) |
120 return false; | 120 return false; |
121 try { | 121 try { |
122 return lockListener.aboutToWait(lockOwner); | 122 return lockListener.aboutToWait(lockOwner); |
123 } catch (Exception e) { | 123 } catch (Exception e) { |
129 } | 129 } |
130 | 130 |
131 /** | 131 /** |
132 * This thread has just acquired a lock. Update graph. | 132 * This thread has just acquired a lock. Update graph. |
133 */ | 133 */ |
134 void addLockThread(Thread thread, ISchedulingRule lock) { | 134 void addLockThread(JThread thread, ISchedulingRule lock) { |
135 if (locks is null) | 135 if (locks is null) |
136 return; | 136 return; |
137 try { | 137 try { |
138 synchronized (locks) { | 138 synchronized (locks) { |
139 locks.lockAcquired(thread, lock); | 139 locks.lockAcquired(thread, lock); |
144 } | 144 } |
145 | 145 |
146 /** | 146 /** |
147 * This thread has just been refused a lock. Update graph and check for deadlock. | 147 * This thread has just been refused a lock. Update graph and check for deadlock. |
148 */ | 148 */ |
149 void addLockWaitThread(Thread thread, ISchedulingRule lock) { | 149 void addLockWaitThread(JThread thread, ISchedulingRule lock) { |
150 if (locks is null) | 150 if (locks is null) |
151 return; | 151 return; |
152 try { | 152 try { |
153 Deadlock found = null; | 153 Deadlock found = null; |
154 synchronized (locks) { | 154 synchronized (locks) { |
218 * Returns true IFF this thread either owns, or is waiting for, any locks or rules. | 218 * Returns true IFF this thread either owns, or is waiting for, any locks or rules. |
219 */ | 219 */ |
220 public bool isLockOwner() { | 220 public bool isLockOwner() { |
221 //all job threads have to be treated as lock owners because UI thread | 221 //all job threads have to be treated as lock owners because UI thread |
222 //may try to join a job | 222 //may try to join a job |
223 Thread current = Thread.getThis(); | 223 JThread current = JThread.currentThread(); |
224 if (cast(Worker)current ) | 224 if (cast(Worker)current ) |
225 return true; | 225 return true; |
226 if (locks is null) | 226 if (locks is null) |
227 return false; | 227 return false; |
228 synchronized (locks) { | 228 synchronized (locks) { |
229 return locks.contains(Thread.getThis()); | 229 return locks.contains(JThread.currentThread()); |
230 } | 230 } |
231 } | 231 } |
232 | 232 |
233 /** | 233 /** |
234 * Creates and returns a new lock. | 234 * Creates and returns a new lock. |
238 } | 238 } |
239 | 239 |
240 /** | 240 /** |
241 * Releases all the acquires that were called on the given rule. Needs to be called only once. | 241 * Releases all the acquires that were called on the given rule. Needs to be called only once. |
242 */ | 242 */ |
243 void removeLockCompletely(Thread thread, ISchedulingRule rule) { | 243 void removeLockCompletely(JThread thread, ISchedulingRule rule) { |
244 if (locks is null) | 244 if (locks is null) |
245 return; | 245 return; |
246 try { | 246 try { |
247 synchronized (locks) { | 247 synchronized (locks) { |
248 locks.lockReleasedCompletely(thread, rule); | 248 locks.lockReleasedCompletely(thread, rule); |
253 } | 253 } |
254 | 254 |
255 /** | 255 /** |
256 * This thread has just released a lock. Update graph. | 256 * This thread has just released a lock. Update graph. |
257 */ | 257 */ |
258 void removeLockThread(Thread thread, ISchedulingRule lock) { | 258 void removeLockThread(JThread thread, ISchedulingRule lock) { |
259 try { | 259 try { |
260 synchronized (locks) { | 260 synchronized (locks) { |
261 locks.lockReleased(thread, lock); | 261 locks.lockReleased(thread, lock); |
262 } | 262 } |
263 } catch (Exception e) { | 263 } catch (Exception e) { |
266 } | 266 } |
267 | 267 |
268 /** | 268 /** |
269 * This thread has just stopped waiting for a lock. Update graph. | 269 * This thread has just stopped waiting for a lock. Update graph. |
270 */ | 270 */ |
271 void removeLockWaitThread(Thread thread, ISchedulingRule lock) { | 271 void removeLockWaitThread(JThread thread, ISchedulingRule lock) { |
272 try { | 272 try { |
273 synchronized (locks) { | 273 synchronized (locks) { |
274 locks.lockWaitStop(thread, lock); | 274 locks.lockWaitStop(thread, lock); |
275 } | 275 } |
276 } catch (Exception e) { | 276 } catch (Exception e) { |
279 } | 279 } |
280 | 280 |
281 /** | 281 /** |
282 * Resumes all the locks that were suspended while this thread was waiting to acquire another lock. | 282 * Resumes all the locks that were suspended while this thread was waiting to acquire another lock. |
283 */ | 283 */ |
284 void resumeSuspendedLocks(Thread owner) { | 284 void resumeSuspendedLocks(JThread owner) { |
285 LockState[] toResume; | 285 LockState[] toResume; |
286 synchronized (suspendedLocks) { | 286 synchronized (suspendedLocks) { |
287 Stack prevLocks = cast(Stack) suspendedLocks.get(owner); | 287 Stack prevLocks = cast(Stack) suspendedLocks.get(owner); |
288 if (prevLocks is null) | 288 if (prevLocks is null) |
289 return; | 289 return; |