Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6f2bc17

Browse files
committed
Merge pull request taimos#20 from 21Net/master
race condition between calling thread and SocketThread
2 parents a5237a9 + 45caf3b commit 6f2bc17

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/main/java/de/taimos/gpsd4java/backend/GPSdEndpoint.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class GPSdEndpoint {
6666

6767
private final List<IObjectListener> listeners = new ArrayList<IObjectListener>(1);
6868

69-
private IGPSObject asnycResult = null;
69+
private IGPSObject asyncResult = null;
7070

7171
private final Object asyncMutex = new Object();
7272

@@ -255,17 +255,17 @@ private void voidCommand(final String command) throws IOException {
255255
*/
256256
private IGPSObject waitForResult() {
257257
synchronized (this.asyncWaitMutex) {
258-
this.asnycResult = null;
259-
try {
260-
this.asyncWaitMutex.wait(1000);
261-
} catch (final InterruptedException e) {
262-
GPSdEndpoint.LOG.info("Interrupted while waiting for result", e);
263-
}
264-
if (this.asnycResult != null) {
265-
return this.asnycResult;
258+
if (this.asyncResult == null) {
259+
try {
260+
this.asyncWaitMutex.wait(1000);
261+
} catch (final InterruptedException e) {
262+
GPSdEndpoint.LOG.info("Interrupted while waiting for result", e);
263+
}
266264
}
265+
final IGPSObject result = this.asyncResult;
266+
this.asyncResult = null;
267+
return result;
267268
}
268-
return null;
269269
}
270270

271271
/*
@@ -299,7 +299,7 @@ void handle(final IGPSObject object) {
299299
} else {
300300
// object was requested, so put it in the response object
301301
synchronized (this.asyncWaitMutex) {
302-
this.asnycResult = object;
302+
this.asyncResult = object;
303303
this.asyncWaitMutex.notifyAll();
304304
}
305305
}

0 commit comments

Comments
 (0)