Lines 152-168
Link Here
|
152 |
* reads and concurrent writes, write access to the tree is governed |
152 |
* reads and concurrent writes, write access to the tree is governed |
153 |
* by {@link WorkManager}. |
153 |
* by {@link WorkManager}. |
154 |
*/ |
154 |
*/ |
155 |
protected ElementTree tree; |
155 |
protected ElementTree tree; |
156 |
|
156 |
|
|
|
157 |
/** |
158 |
* Synchronize access to the treeLocked field. Only one thread at a time |
159 |
* can lock the tree for resource change notifications. |
160 |
*/ |
161 |
private final Object treeLockMonitor = new Object(); |
162 |
|
157 |
/** |
163 |
/** |
158 |
* This field is used to control access to the workspace tree during |
164 |
* This field is used to control access to the workspace tree during |
159 |
* resource change notifications. It tracks which thread, if any, is |
165 |
* resource change notifications. It tracks which thread, if any, is |
160 |
* in the middle of a resource change notification. This is used to cause |
166 |
* in the middle of a resource change notification. This is used to cause |
161 |
* attempts to modify the workspace during notifications to fail. |
167 |
* attempts to modify the workspace during notifications to fail. |
|
|
168 |
* |
169 |
* guardedBy: treeLockMonitor |
162 |
*/ |
170 |
*/ |
163 |
protected Thread treeLocked = null; |
171 |
private Thread treeLocked = null; |
164 |
|
172 |
|
165 |
/** |
173 |
/** |
166 |
* The currently installed file modification validator. |
174 |
* The currently installed file modification validator. |
167 |
*/ |
175 |
*/ |
168 |
protected IFileModificationValidator validator = null; |
176 |
protected IFileModificationValidator validator = null; |
Lines 225-235
Link Here
|
225 |
super(); |
233 |
super(); |
226 |
localMetaArea = new LocalMetaArea(); |
234 |
localMetaArea = new LocalMetaArea(); |
227 |
tree = new ElementTree(); |
235 |
tree = new ElementTree(); |
228 |
/* tree should only be modified during operations */ |
236 |
/* tree should only be modified during operations */ |
229 |
tree.immutable(); |
237 |
tree.immutable(); |
230 |
treeLocked = Thread.currentThread(); |
238 |
synchronized (treeLockMonitor) { |
|
|
239 |
treeLocked = Thread.currentThread(); |
240 |
} |
231 |
tree.setTreeData(newElement(IResource.ROOT)); |
241 |
tree.setTreeData(newElement(IResource.ROOT)); |
232 |
} |
242 |
} |
233 |
|
243 |
|
234 |
/** |
244 |
/** |
235 |
* Indicates that a build is about to occur. Broadcasts the necessary |
245 |
* Indicates that a build is about to occur. Broadcasts the necessary |
Lines 1437-1447
Link Here
|
1437 |
|
1447 |
|
1438 |
/* (non-Javadoc) |
1448 |
/* (non-Javadoc) |
1439 |
* @see IWorkspace#isTreeLocked() |
1449 |
* @see IWorkspace#isTreeLocked() |
1440 |
*/ |
1450 |
*/ |
1441 |
public boolean isTreeLocked() { |
1451 |
public boolean isTreeLocked() { |
1442 |
return treeLocked == Thread.currentThread(); |
1452 |
synchronized (treeLockMonitor) { |
|
|
1453 |
return treeLocked == Thread.currentThread(); |
1454 |
} |
1443 |
} |
1455 |
} |
1444 |
|
1456 |
|
1445 |
/** |
1457 |
/** |
1446 |
* Link the given tree into the receiver's tree at the specified resource. |
1458 |
* Link the given tree into the receiver's tree at the specified resource. |
1447 |
*/ |
1459 |
*/ |
Lines 1859-1871
Link Here
|
1859 |
buildOrder = null; |
1871 |
buildOrder = null; |
1860 |
description.copyFrom(newDescription); |
1872 |
description.copyFrom(newDescription); |
1861 |
ResourcesPlugin.getPlugin().savePluginPreferences(); |
1873 |
ResourcesPlugin.getPlugin().savePluginPreferences(); |
1862 |
} |
1874 |
} |
1863 |
|
1875 |
|
1864 |
public void setTreeLocked(boolean locked) { |
1876 |
public void setTreeLocked(boolean doLock) { |
1865 |
treeLocked = locked ? Thread.currentThread() : null; |
1877 |
if (doLock) { |
1866 |
} |
1878 |
// true: acquire the tree lock |
|
|
1879 |
synchronized (treeLockMonitor) { |
1880 |
while (treeLocked != null && treeLocked != Thread.currentThread()) { |
1881 |
try { |
1882 |
treeLockMonitor.wait(); |
1883 |
} catch (InterruptedException e) { |
1884 |
Thread.currentThread().interrupt(); |
1885 |
final OperationCanceledException operationCanceledException = |
1886 |
new OperationCanceledException(e.getMessage()); |
1887 |
operationCanceledException.initCause(e); |
1888 |
throw operationCanceledException; |
1889 |
} |
1890 |
} |
1891 |
treeLocked = Thread.currentThread(); |
1892 |
} |
1893 |
} else { |
1894 |
// false: release the tree lock |
1895 |
synchronized (treeLockMonitor) { |
1896 |
if (treeLocked != Thread.currentThread() && treeLocked != null) { |
1897 |
throw new IllegalThreadStateException("tree has not been locked by me: " + Thread.currentThread() |
1898 |
+ ", but by: " + treeLocked); |
1899 |
} |
1900 |
treeLocked = null; |
1901 |
treeLockMonitor.notifyAll(); |
1902 |
} |
1903 |
} |
1904 |
} |
1867 |
|
1905 |
|
1868 |
/** |
1906 |
/** |
1869 |
* @deprecated |
1907 |
* @deprecated |
1870 |
*/ |
1908 |
*/ |
1871 |
public void setWorkspaceLock(WorkspaceLock lock) { |
1909 |
public void setWorkspaceLock(WorkspaceLock lock) { |
Lines 1957-1967
Link Here
|
1957 |
charsetManager.startup(null); |
1995 |
charsetManager.startup(null); |
1958 |
contentDescriptionManager = new ContentDescriptionManager(); |
1996 |
contentDescriptionManager = new ContentDescriptionManager(); |
1959 |
contentDescriptionManager.startup(null); |
1997 |
contentDescriptionManager.startup(null); |
1960 |
} finally { |
1998 |
} finally { |
1961 |
//unlock tree even in case of failure, otherwise shutdown will also fail |
1999 |
//unlock tree even in case of failure, otherwise shutdown will also fail |
1962 |
treeLocked = null; |
2000 |
synchronized (treeLockMonitor) { |
|
|
2001 |
treeLocked = null; |
2002 |
} |
1963 |
} |
2003 |
} |
1964 |
} |
2004 |
} |
1965 |
|
2005 |
|
1966 |
/** |
2006 |
/** |
1967 |
* Returns a string representation of this working state's |
2007 |
* Returns a string representation of this working state's |