Sync to avoid concurrent access issues

This commit is contained in:
shagr4th 2016-12-19 22:18:07 +01:00
parent 5cb541b5e4
commit 79d4d7bfcf

View file

@ -1028,27 +1028,31 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
public void key(int code, boolean down, int pointerID) { public void key(int code, boolean down, int pointerID) {
if (code < MAX_TOUCHES) { if (code < MAX_TOUCHES) {
if (down) { synchronized(queuedCodes) {
Integer cI = code + 1; if (down) {
queuedCodes.add(cI); Integer cI = code + 1;
touches[code] = pointerID; queuedCodes.add(cI);
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, touches[code] = pointerID;
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
} else { HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
Integer cI = code + 100; } else {
queuedCodes.add(cI); Integer cI = code + 100;
touches[code] = 0; queuedCodes.add(cI);
touches[code] = 0;
}
} }
x48.flipScreen(); x48.flipScreen();
} }
} }
public int waitEvent() { public int waitEvent() {
if (queuedCodes.size() == 0) { synchronized(queuedCodes) {
return 0; if (queuedCodes.size() == 0) {
} else { return 0;
int c = queuedCodes.remove(0); } else {
return c; int c = queuedCodes.remove(0);
return c;
}
} }
} }