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

Bug 444395 - Must synchronize creation of bp extension

It is possible that more than one thread try to fetch the extension of
the same breakpoint.  If that extension is not created yet, both threads
could end up creating two different ones by mistake.

We must synchronize the possible creation of the breakpoint extension to
avoid such a situation.

Change-Id: I51118bdfb9c4215fca14d7b5e18a5963e02cde34
Signed-off-by: Marc Khouzam <marc.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/33620
Tested-by: Hudson CI
This commit is contained in:
Marc Khouzam 2014-09-19 13:31:41 -04:00
parent a3ee0c86f9
commit 0c0b6ef6ff

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2009 QNX Software Systems and others.
* Copyright (c) 2004, 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Marc Khouzam (Ericsson) - Must synchronized creation of breakpoint creation (Bug 444395)
*******************************************************************************/
package org.eclipse.cdt.debug.internal.core.breakpoints;
@ -281,43 +282,49 @@ public abstract class CBreakpoint extends Breakpoint implements ICBreakpoint2, I
* cannot be accessed.
*/
private ICBreakpointExtension[] getExtensionsForModelId(String debugModelId) throws CoreException {
if (!fExtensions.containsKey(debugModelId)) {
// Check to make sure that a marker is present. Extensions can only be created
// once the marker type is known.
IMarker marker = ensureMarker();
// Read the extension registry and create applicable extensions.
List<ICBreakpointExtension> extensions = new ArrayList<ICBreakpointExtension>(4);
IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(CDebugCorePlugin.getUniqueIdentifier(), CDebugCorePlugin.BREAKPOINT_EXTENSION_EXTENSION_POINT_ID);
IConfigurationElement[] elements = ep.getConfigurationElements();
for (int i= 0; i < elements.length; i++) {
if ( elements[i].getName().equals(CDebugCorePlugin.BREAKPOINT_EXTENSION_ELEMENT) ) {
String elementDebugModelId = elements[i].getAttribute("debugModelId"); //$NON-NLS-1$
String elementMarkerType = elements[i].getAttribute("markerType"); //$NON-NLS-1$
if (elementDebugModelId == null) {
CDebugCorePlugin.log(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, "Extension " + elements[i].getDeclaringExtension().getUniqueIdentifier() + " missing required attribute: markerType", null)); //$NON-NLS-1$ //$NON-NLS-2$
} else if (elementMarkerType == null){
CDebugCorePlugin.log(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, "Extension " + elements[i].getDeclaringExtension().getUniqueIdentifier() + " missing required attribute: debugModelId", null)); //$NON-NLS-1$ //$NON-NLS-2$
} else if ( debugModelId.equals(elementDebugModelId) && marker.isSubtypeOf(elementMarkerType)) {
String className = elements[i].getAttribute("class"); //$NON-NLS-1$
if (className == null){
CDebugCorePlugin.log(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, "Extension " + elements[i].getDeclaringExtension().getUniqueIdentifier() + " missing required attribute: className", null)); //$NON-NLS-1$ //$NON-NLS-2$
} else {
ICBreakpointExtension extension;
try {
extension = (ICBreakpointExtension)elements[i].createExecutableExtension("class"); //$NON-NLS-1$
extension.initialize(this);
extensions.add(extension);
} catch (CoreException e) {
CDebugCorePlugin.log(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, "Extension " + elements[i].getDeclaringExtension().getUniqueIdentifier() + " contains an invalid value for attribute: className", e)); //$NON-NLS-1$ //$NON-NLS-2$
}
}
}
}
}
fExtensions.put(debugModelId, extensions.toArray(new ICBreakpointExtension[extensions.size()]));
}
return fExtensions.get(debugModelId);
// Check outside the synchronized lock for efficiency
if (!fExtensions.containsKey(debugModelId)) {
synchronized (fExtensions) {
// Must check again within the synchronized block, in case things were changed by another thread.
if (!fExtensions.containsKey(debugModelId)) {
// Check to make sure that a marker is present. Extensions can only be created
// once the marker type is known.
IMarker marker = ensureMarker();
// Read the extension registry and create applicable extensions.
List<ICBreakpointExtension> extensions = new ArrayList<ICBreakpointExtension>(4);
IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(CDebugCorePlugin.getUniqueIdentifier(), CDebugCorePlugin.BREAKPOINT_EXTENSION_EXTENSION_POINT_ID);
IConfigurationElement[] elements = ep.getConfigurationElements();
for (int i= 0; i < elements.length; i++) {
if ( elements[i].getName().equals(CDebugCorePlugin.BREAKPOINT_EXTENSION_ELEMENT) ) {
String elementDebugModelId = elements[i].getAttribute("debugModelId"); //$NON-NLS-1$
String elementMarkerType = elements[i].getAttribute("markerType"); //$NON-NLS-1$
if (elementDebugModelId == null) {
CDebugCorePlugin.log(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, "Extension " + elements[i].getDeclaringExtension().getUniqueIdentifier() + " missing required attribute: markerType", null)); //$NON-NLS-1$ //$NON-NLS-2$
} else if (elementMarkerType == null){
CDebugCorePlugin.log(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, "Extension " + elements[i].getDeclaringExtension().getUniqueIdentifier() + " missing required attribute: debugModelId", null)); //$NON-NLS-1$ //$NON-NLS-2$
} else if ( debugModelId.equals(elementDebugModelId) && marker.isSubtypeOf(elementMarkerType)) {
String className = elements[i].getAttribute("class"); //$NON-NLS-1$
if (className == null){
CDebugCorePlugin.log(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, "Extension " + elements[i].getDeclaringExtension().getUniqueIdentifier() + " missing required attribute: className", null)); //$NON-NLS-1$ //$NON-NLS-2$
} else {
ICBreakpointExtension extension;
try {
extension = (ICBreakpointExtension)elements[i].createExecutableExtension("class"); //$NON-NLS-1$
extension.initialize(this);
extensions.add(extension);
} catch (CoreException e) {
CDebugCorePlugin.log(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, "Extension " + elements[i].getDeclaringExtension().getUniqueIdentifier() + " contains an invalid value for attribute: className", e)); //$NON-NLS-1$ //$NON-NLS-2$
}
}
}
}
}
fExtensions.put(debugModelId, extensions.toArray(new ICBreakpointExtension[extensions.size()]));
}
}
}
return fExtensions.get(debugModelId);
}
@Override