122
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2004, 2006 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM - Initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.core.runtime.jobs.LockListener;
|
|
14
|
167
|
15 import dwtx.dwtxhelper.JThread;
|
122
|
16 import dwt.dwthelper.utils;
|
|
17
|
|
18 import dwtx.core.internal.jobs.JobManager;
|
|
19 import dwtx.core.internal.jobs.LockManager;
|
|
20 import dwtx.core.runtime.jobs.Job;
|
|
21
|
|
22 /**
|
|
23 * A lock listener is notified whenever a thread is about to wait
|
|
24 * on a lock, and when a thread is about to release a lock.
|
|
25 * <p>
|
|
26 * This class is for internal use by the platform-related plug-ins.
|
|
27 * Clients outside of the base platform should not reference or subclass this class.
|
|
28 * </p>
|
|
29 *
|
|
30 * @see IJobManager#setLockListener(LockListener)
|
|
31 * @since 3.0
|
|
32 */
|
|
33 public class LockListener {
|
|
34 private const LockManager manager;
|
|
35
|
|
36 public this(){
|
|
37 manager = (cast(JobManager)Job.getJobManager()).getLockManager();
|
|
38 }
|
|
39
|
|
40 /**
|
|
41 * Notification that a thread is about to block on an attempt to acquire a lock.
|
|
42 * Returns whether the thread should be granted immediate access to the lock.
|
|
43 * <p>
|
|
44 * This default implementation always returns <code>false</code>.
|
|
45 * Subclasses may override.
|
|
46 *
|
|
47 * @param lockOwner the thread that currently owns the lock this thread is
|
|
48 * waiting for, or <code>null</code> if unknown.
|
|
49 * @return <code>true</code> if the thread should be granted immediate access,
|
|
50 * and <code>false</code> if it should wait for the lock to be available
|
|
51 */
|
167
|
52 public bool aboutToWait(JThread lockOwner) {
|
122
|
53 return false;
|
|
54 }
|
|
55
|
|
56 /**
|
|
57 * Notification that a thread is about to release a lock.
|
|
58 * <p>
|
|
59 * This default implementation does nothing. Subclasses may override.
|
|
60 */
|
|
61 public void aboutToRelease() {
|
|
62 //do nothing
|
|
63 }
|
|
64
|
|
65 /**
|
|
66 * Returns whether this thread currently owns any locks
|
|
67 * @return <code>true</code> if this thread owns any locks, and
|
|
68 * <code>false</code> otherwise.
|
|
69 */
|
|
70 protected final bool isLockOwnerThread() {
|
|
71 return manager.isLockOwner();
|
|
72 }
|
|
73 }
|