1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 22:25:25 +02:00

[368454] provide thread safety for cachedRemoteFiles hashmap

This commit is contained in:
David McKnight 2012-02-02 14:33:53 +00:00
parent 9df17e06e3
commit 0ea623ad32
2 changed files with 26 additions and 7 deletions

View file

@ -1154,10 +1154,9 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe
if (newConfig instanceof IFileServiceSubSystemConfiguration) {
IHost host = getHost();
IFileServiceSubSystemConfiguration config = (IFileServiceSubSystemConfiguration) newConfig;
// file subsystem specific bits
synchronized (_cachedRemoteFiles){
_cachedRemoteFiles.clear();
}
clearRemoteFileCache();
_languageUtilityFactory = null;
setFileService(config.getFileService(host));
setHostFileToRemoteFileAdapter(config.getHostFileAdapter());

View file

@ -124,9 +124,20 @@ public abstract class RemoteFileSubSystem extends SubSystem implements IRemoteFi
protected ArrayList _searchHistory;
/**
* All created IRemoteFiles are mapped in a cache for quick retrieval.
* This is a HashMap so any access to it needs to be synchronized otherwise
* thread-safety could be compromised.
* The _cachedRemoteFiles map is used to store queried IRemoteFiles
* for quick retrieval. This is a HashMap so any access to it needs
* to be synchronized; otherwise thread-safety could be compromised.
*
* The _cachedRemoteFiles HashMap should be synchronized on like this:
* <code>
* synchronized (_cachedRemoteFiles){
* // call to _cachedRemoteFiles
* ...
* }
* </code>
* @deprecated going forward, this field will be non-API. A new
* protected clearRemoteFileCache() method allows cache
* clearing.
*/
protected HashMap _cachedRemoteFiles = new HashMap();
@ -1394,6 +1405,15 @@ public abstract class RemoteFileSubSystem extends SubSystem implements IRemoteFi
_cachedRemoteFiles.remove(path);
}
}
/**
* @since 3.3
*/
protected void clearRemoteFileCache(){
synchronized (_cachedRemoteFiles){
_cachedRemoteFiles.clear();
}
}
public void communicationsStateChange(CommunicationsEvent e)