@@ -139,7 +139,9 @@ private void processJsonNode(ObjectMapper mapper, JsonNode node) {
139
139
return ;
140
140
}
141
141
142
- portList .clear ();
142
+ synchronized (portList ) {
143
+ portList .clear ();
144
+ }
143
145
portsNode .forEach (portNode -> {
144
146
BoardPort port = mapJsonNodeToBoardPort (mapper , node );
145
147
if (port != null ) {
@@ -246,45 +248,41 @@ private void write(String command) {
246
248
}
247
249
}
248
250
249
- private synchronized void addOrUpdate (BoardPort port ) {
250
- // Update the list of discovered ports, which may involve
251
- // adding a new port, replacing the info for a previously
252
- // discovered port, or removing a port. This function
253
- // must be synchronized with listDiscoveredBoards(), to
254
- // avoid changing the list while it's being accessed by
255
- // another thread.
251
+ private void addOrUpdate (BoardPort port ) {
256
252
String address = port .getAddress ();
257
253
if (address == null )
258
254
return ; // address required for "add" & "remove"
259
255
260
- // if address already on the list, discard old info
261
- portList .removeIf (bp -> address .equals (bp .getAddress ()));
262
-
263
- portList .add (port );
256
+ synchronized (portList ) {
257
+ // if address already on the list, discard old info
258
+ portList .removeIf (bp -> address .equals (bp .getAddress ()));
259
+ portList .add (port );
260
+ }
264
261
}
265
262
266
- private synchronized void remove (BoardPort port ) {
263
+ private void remove (BoardPort port ) {
267
264
String address = port .getAddress ();
268
265
if (address == null )
269
266
return ; // address required for "add" & "remove"
270
- portList .removeIf (bp -> address .equals (bp .getAddress ()));
267
+ synchronized (portList ) {
268
+ portList .removeIf (bp -> address .equals (bp .getAddress ()));
269
+ }
271
270
}
272
271
273
272
@ Override
274
- public synchronized List <BoardPort > listDiscoveredBoards () {
275
- // return the ports discovered so far. Because the list of
276
- // ports may change at any moment, a copy of the list is
277
- // returned for use by the rest of the IDE. This copy
278
- // operation must be synchronized with update() to assure
279
- // a clean copy.
280
- return new ArrayList <>(portList );
273
+ public List <BoardPort > listDiscoveredBoards () {
274
+ synchronized (portList ) {
275
+ return new ArrayList <>(portList );
276
+ }
281
277
}
282
278
283
279
@ Override
284
280
public List <BoardPort > listDiscoveredBoards (boolean complete ) {
285
281
// XXX: parameter "complete "is really needed?
286
282
// should be checked on all existing discoveries
287
- return new ArrayList <>(portList );
283
+ synchronized (portList ) {
284
+ return new ArrayList <>(portList );
285
+ }
288
286
}
289
287
290
288
@ Override
0 commit comments