comparison org.eclipse.core.jobs/src/org/eclipse/core/runtime/jobs/ILock.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
1 /*******************************************************************************
2 * Copyright (c) 2003, 2008 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 org.eclipse.core.runtime.jobs.ILock;
14
15 import java.lang.all;
16
17 /**
18 * A lock is used to control access to an exclusive resource.
19 * <p>
20 * Locks are reentrant. That is, they can be acquired multiple times by the same thread
21 * without releasing. Locks are only released when the number of successful acquires
22 * equals the number of successful releases.
23 * </p><p>
24 * Locks are capable of detecting and recovering from programming errors that cause
25 * circular waiting deadlocks. When a deadlock between two or more <tt>ILock</tt>
26 * instances is detected, detailed debugging information is printed to the log file. The
27 * locks will then automatically recover from the deadlock by employing a release
28 * and wait strategy. One thread will lose control of the locks it owns, thus breaking
29 * the deadlock and allowing other threads to proceed. Once that thread's locks are
30 * all available, it will be given exclusive access to all its locks and allowed to proceed.
31 * A thread can only lose locks while it is waiting on an <tt>acquire()</tt> call.
32 *
33 * </p><p>
34 * Successive acquire attempts by different threads are queued and serviced on
35 * a first come, first served basis.
36 * </p><p>
37 * It is very important that acquired locks eventually get released. Calls to release
38 * should be done in a finally block to ensure they execute. For example:
39 * <pre>
40 * try {
41 * lock.acquire();
42 * // ... do work here ...
43 * } finally {
44 * lock.release();
45 * }
46 * </pre>
47 * Note: although <tt>lock.acquire</tt> should never fail, it is good practice to place
48 * it inside the try block anyway. Releasing without acquiring is far less catastrophic
49 * than acquiring without releasing.
50 * </p>
51 *
52 * @see IJobManager#newLock()
53 * @since 3.0
54 * @noimplement This interface is not intended to be implemented by clients.
55 */
56 public interface ILock {
57 /**
58 * Attempts to acquire this lock. If the lock is in use and the specified delay is
59 * greater than zero, the calling thread will block until one of the following happens:
60 * <ul>
61 * <li>This lock is available</li>
62 * <li>The thread is interrupted</li>
63 * <li>The specified delay has elapsed</li>
64 * </ul>
65 * <p>
66 * While a thread is waiting, locks it already owns may be granted to other threads
67 * if necessary to break a deadlock. In this situation, the calling thread may be blocked
68 * for longer than the specified delay. On returning from this call, the calling thread
69 * will once again have exclusive access to any other locks it owned upon entering
70 * the acquire method.
71 *
72 * @param delay the number of milliseconds to delay
73 * @return <code>true</code> if the lock was successfully acquired, and
74 * <code>false</code> otherwise.
75 * @exception InterruptedException if the thread was interrupted
76 */
77 public bool acquire(long delay);
78
79 /**
80 * Acquires this lock. If the lock is in use, the calling thread will block until the lock
81 * becomes available. If the calling thread owns several locks, it will be blocked
82 * until all threads it requires become available, or until the thread is interrupted.
83 * While a thread is waiting, its locks may be granted to other threads if necessary
84 * to break a deadlock. On returning from this call, the calling thread will
85 * have exclusive access to this lock, and any other locks it owned upon
86 * entering the acquire method.
87 * <p>
88 * This implementation ignores attempts to interrupt the thread. If response to
89 * interruption is needed, use the method <code>acquire(long)</code>
90 */
91 public void acquire();
92
93 /**
94 * Returns the number of nested acquires on this lock that have not been released.
95 * This is the number of times that release() must be called before the lock is
96 * freed.
97 *
98 * @return the number of nested acquires that have not been released
99 */
100 public int getDepth();
101
102 /**
103 * Releases this lock. Locks must only be released by the thread that currently
104 * owns the lock.
105 */
106 public void release();
107 }