Skip to content

Commit

Permalink
Don't synchronize on Boolean/Integer object
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jonahgraham committed Oct 9, 2022
1 parent 6ed1631 commit daafa51
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public void doAfterTest() throws Exception {
// *********************************************************************
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -168,9 +169,7 @@ public void doAfterTest() throws Exception {
*/
@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());
Expand All @@ -183,9 +182,7 @@ public void eventDispatched(IMemoryChangedEvent e) {

// 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;
Expand All @@ -194,11 +191,7 @@ private void clearEventCounters() {

// 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
Expand Down

0 comments on commit daafa51

Please sign in to comment.