1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Don't synchronize on Boolean/Integer object

This fixes numerous warnings like this:
Boolean is a value-based type which is a discouraged argument
for the synchronized statement
and:
Integer is a value-based type which is a discouraged argument
for the synchronized statement
This commit is contained in:
Jonah Graham 2022-10-09 14:55:46 -04:00
parent 161b57f9ed
commit 3b3f29c93a
4 changed files with 8 additions and 15 deletions

View file

@ -217,7 +217,7 @@ public class GDBRemoteTracepointsTest extends BaseParametrizedTestCase {
// *********************************************************************
// Below are utility methods.
// *********************************************************************
private static Boolean lock = true;
private static Object lock = new Object();
enum Events {
BP_ADDED, BP_UPDATED, BP_REMOVED, BP_HIT

View file

@ -109,7 +109,7 @@ public class MIBreakpointsTest extends BaseParametrizedTestCase {
protected IExpressions fExpressionService;
protected IGDBControl fCommandControl;
// Event Management
protected static Boolean lock = true;
protected static Object lock = new Object();
protected enum Events {
BP_ADDED, BP_UPDATED, BP_REMOVED, BP_HIT, WP_HIT, WP_OOS

View file

@ -104,7 +104,7 @@ public class MICatchpointsTest extends BaseParametrizedTestCase {
private IExpressions fExpressionService;
// Event Management
private static Boolean fEventHandlerLock = true;
private static Object fEventHandlerLock = new Object();
private enum Events {
BP_ADDED, BP_UPDATED, BP_REMOVED, BP_HIT

View file

@ -25,6 +25,7 @@ import static org.junit.Assert.assertEquals;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.cdt.core.IAddress;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
@ -86,7 +87,7 @@ public class MIMemoryTest extends BaseParametrizedTestCase {
// Keeps track of the MemoryChangedEvents
private final int BLOCK_SIZE = 256;
private IAddress fBaseAddress;
private Integer fMemoryChangedEventCount = 0;
private AtomicInteger fMemoryChangedEventCount = new AtomicInteger(0);
private boolean[] fMemoryAddressesChanged = new boolean[BLOCK_SIZE];
@Rule
@ -168,9 +169,7 @@ public class MIMemoryTest extends BaseParametrizedTestCase {
*/
@DsfServiceEventHandler
public void eventDispatched(IMemoryChangedEvent e) {
synchronized (fMemoryChangedEventCount) {
fMemoryChangedEventCount++;
}
fMemoryChangedEventCount.incrementAndGet();
IAddress[] addresses = e.getAddresses();
for (int i = 0; i < addresses.length; i++) {
int offset = Math.abs(addresses[i].distanceTo(fBaseAddress).intValue());
@ -183,9 +182,7 @@ public class MIMemoryTest extends BaseParametrizedTestCase {
// Clears the counters
private void clearEventCounters() {
synchronized (fMemoryChangedEventCount) {
fMemoryChangedEventCount = 0;
}
fMemoryChangedEventCount.set(0);
synchronized (fMemoryAddressesChanged) {
for (int i = 0; i < BLOCK_SIZE; i++)
fMemoryAddressesChanged[i] = false;
@ -194,11 +191,7 @@ public class MIMemoryTest extends BaseParametrizedTestCase {
// Returns the total number of events received
private int getEventCount() {
int count;
synchronized (fMemoryChangedEventCount) {
count = fMemoryChangedEventCount;
}
return count;
return fMemoryChangedEventCount.get();
}
// Returns the number of distinct addresses reported