Bug 469566

Summary: Provide lock free RepositoryProvider.getProvider() API
Product: [Eclipse Project] Platform Reporter: Andrey Loskutov <loskutov>
Component: TeamAssignee: Platform Team Inbox <platform-team-inbox>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3    
Version: 4.5   
Target Milestone: ---   
Hardware: All   
OS: All   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=469555
https://bugs.eclipse.org/bugs/show_bug.cgi?id=468270
Whiteboard:

Description Andrey Loskutov CLA 2015-06-07 09:48:19 EDT
In EGit we had at least 2 bugs with deadlocks where the root cause was that  RepositoryProvider.getProvider() not only "gets" the provider but tries to map one in some cases. So a call to getProvider() can ends up in call to RepositoryProvider.mapExistingProvider() which takes "mappingLock" lock, independently if the calling thread already owns workspace locks.

This way we cannot actually use RepositoryProvider.getProvider() API from IResourceListener.resourceChanged() code, but we want to do so to know if the resource is mapped to EGit or not.

This is pity, since the API of IResourceListener.resourceChanged() explicitly states that:

"IResourceChangeEvent object (and the resource delta within it) is valid only for the duration of the invocation of this method."

So we are forced to do a two-pass event handling (in different threads!) where in the first pass we must somehow try to find interesting resources *without* using RepositoryProvider.getProvider() API, and for the second pass start a new job to find out if the resources are mapped to EGit or not. This is, honestly speaking, an overkill.

So I would like to request here a new 

public static RepositoryProvider getProvider(IProject project, String id, boolean mapIfNeeded) 

API (or something like this) which does NOT involve any locks and simply returns the provider mapped to the project if the flag is set to false.