|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2003, 2012 IBM Corporation and others. |
2 |
* Copyright (c) 2003, 2013 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 10-18
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.core.internal.jobs; |
11 |
package org.eclipse.core.internal.jobs; |
| 12 |
|
12 |
|
| 13 |
import org.eclipse.core.runtime.Assert; |
13 |
import org.eclipse.core.internal.runtime.RuntimeLog; |
| 14 |
import org.eclipse.core.runtime.IStatus; |
14 |
import org.eclipse.core.runtime.*; |
| 15 |
import org.eclipse.core.runtime.jobs.Job; |
15 |
import org.eclipse.core.runtime.jobs.*; |
| 16 |
|
16 |
|
| 17 |
/** |
17 |
/** |
| 18 |
* Maintains a pool of worker threads. Threads are constructed lazily as |
18 |
* Maintains a pool of worker threads. Threads are constructed lazily as |
|
Lines 81-86
Link Here
|
| 81 |
threads[numThreads++] = worker; |
81 |
threads[numThreads++] = worker; |
| 82 |
} |
82 |
} |
| 83 |
|
83 |
|
|
|
84 |
private void cleanWorker(InternalJob job) { |
| 85 |
//there should be no locks owned by the current thread at this moment, release if there are any left |
| 86 |
ISchedulingRule[] locks = manager.getLockManager().getOwnedLocks(Thread.currentThread()); |
| 87 |
if (locks != null && locks.length > 0) { |
| 88 |
String msg = "Worker thread ended job: " + job + ", but still holds locks: ["; //$NON-NLS-1$ //$NON-NLS-2$ |
| 89 |
for (int i = 0; i < locks.length; i++) { |
| 90 |
//it is allowed to call ILock#release here because it is called in the same thread in |
| 91 |
//which job was running but failed to release the lock in its Job#run method |
| 92 |
//it is still a bug in client code that they failed to release the lock, but to avoid |
| 93 |
//a deadlock we release it for them |
| 94 |
if (locks[i] instanceof ILock) { |
| 95 |
ILock lock = (ILock) locks[i]; |
| 96 |
int depth = lock.getDepth(); |
| 97 |
for (int j = 0; j < depth; j++) |
| 98 |
lock.release(); |
| 99 |
} |
| 100 |
msg += locks[i].toString(); |
| 101 |
if (i < locks.length - 1) |
| 102 |
msg += ","; //$NON-NLS-1$ |
| 103 |
} |
| 104 |
msg += "]"; //$NON-NLS-1$ |
| 105 |
IStatus error = new Status(IStatus.ERROR, JobManager.PI_JOBS, 1, msg, null); |
| 106 |
try { |
| 107 |
RuntimeLog.log(error); |
| 108 |
} catch (RuntimeException e) { |
| 109 |
//failed to log, so print to console instead |
| 110 |
System.err.println(error.getMessage()); |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 84 |
private synchronized void decrementBusyThreads() { |
115 |
private synchronized void decrementBusyThreads() { |
| 85 |
//impossible to have less than zero busy threads |
116 |
//impossible to have less than zero busy threads |
| 86 |
if (--busyThreads < 0) { |
117 |
if (--busyThreads < 0) { |
|
Lines 106-111
Link Here
|
| 106 |
//ensure this thread no longer owns any scheduling rules |
137 |
//ensure this thread no longer owns any scheduling rules |
| 107 |
manager.implicitJobs.endJob(job); |
138 |
manager.implicitJobs.endJob(job); |
| 108 |
} finally { |
139 |
} finally { |
|
|
140 |
cleanWorker(job); |
| 109 |
decrementBusyThreads(); |
141 |
decrementBusyThreads(); |
| 110 |
} |
142 |
} |
| 111 |
} |
143 |
} |