package NET.worlds.scape; class SoundResource { private static SoundResource instance = null; public static final int RSX = 1; public static final int RA = 2; private int currentPlayer = 0; private int counter = 0; private boolean isShutdownTime = false; private SoundResource() { } private static void debugOut(int n, String s) { if (Sound.debugLevel > n) { System.out.println(s); } } public static SoundResource instance() { if (instance == null) { debugOut(6, "Instantiating a new SoundResource"); instance = new SoundResource(); } return instance; } public boolean syncLock(int type) { debugOut(6, "Calling syncLock with type " + type + " counter " + this.counter); if (this.isShutdownTime) { return false; } else { if (type != this.currentPlayer) { this.currentPlayer = type; if (this.counter > 0) { this.isShutdownTime = true; } else { this.currentPlayer = type; this.counter = 1; } } else { this.counter++; } return true; } } public synchronized void asyncLock() { debugOut(6, "SoundResource::asyncLock with " + this.isShutdownTime); boolean shutdown = false; while (this.isShutdownTime) { shutdown = true; Thread.yield(); debugOut(6, "asyncLock yield"); } if (shutdown) { debugOut(6, "asyncLock: adding artificial delay"); try { Thread.sleep(500L); } catch (InterruptedException var3) { } } } public boolean syncUnlock() { debugOut(6, "SoundResource::syncUnlock with " + this.counter); boolean rv = false; this.counter--; if (this.counter <= 0) { rv = true; } if (this.counter <= 0 && this.isShutdownTime) { this.counter = 1; this.isShutdownTime = false; } return rv; } public boolean isOK() { return !this.isShutdownTime; } }