summaryrefslogtreecommitdiffstats
path: root/src/java/net
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/net')
-rw-r--r--src/java/net/java/games/joal/ALC.java2
-rw-r--r--src/java/net/java/games/joal/ALCImpl.java52
2 files changed, 37 insertions, 17 deletions
diff --git a/src/java/net/java/games/joal/ALC.java b/src/java/net/java/games/joal/ALC.java
index bb53bc5..2da7f2d 100644
--- a/src/java/net/java/games/joal/ALC.java
+++ b/src/java/net/java/games/joal/ALC.java
@@ -91,6 +91,8 @@ public interface ALC extends ALCConstants {
*/
public int alcMakeContextCurrent(Context context);
+ public void alcFreeCurrentContext();
+
/**
* This method tells a context to begin processing. <br>
* <br>
diff --git a/src/java/net/java/games/joal/ALCImpl.java b/src/java/net/java/games/joal/ALCImpl.java
index d621a0a..6e7ccc5 100644
--- a/src/java/net/java/games/joal/ALCImpl.java
+++ b/src/java/net/java/games/joal/ALCImpl.java
@@ -37,16 +37,16 @@ import java.util.HashMap;
final class ALCImpl implements ALC {
private final HashMap contextMap = new HashMap();
- private static Object lock = new Object();
+ private static Mutex lock = new Mutex();
ALCImpl() {
System.loadLibrary("joal");
-
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run() {
exit();
}
}));
+
}
public Device alcOpenDevice(String deviceName) {
@@ -84,26 +84,18 @@ final class ALCImpl implements ALC {
public int alcMakeContextCurrent(Context context) {
int result = 0;
- synchronized(lock) {
- int pointer = 0;
- if (context != null) {
- pointer = context.pointer;
- }
- result = makeContextCurrentNative(pointer);
- try {
- lock.wait();
- } catch (InterruptedException e) {
- result = 0;
- }
+ int pointer = 0;
+ if (context != null) {
+ pointer = context.pointer;
}
+ lock.acquire();
+ result = makeContextCurrentNative(pointer);
return result;
}
public void alcFreeCurrentContext() {
- synchronized(lock) {
- makeContextCurrentNative(0);
- lock.notifyAll();
- }
+ makeContextCurrentNative(0);
+ lock.release();
}
private native int makeContextCurrentNative(int pointer);
@@ -204,4 +196,30 @@ final class ALCImpl implements ALC {
alcCloseDevice(alcDevice);
}
}
+
+ private static class Mutex {
+ Thread owner = null;
+ public synchronized void acquire() {
+ boolean interrupted = false;
+ while(owner != null) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ interrupted = true;
+ }
+ }
+ owner = Thread.currentThread();
+ if(interrupted) {
+ owner.interrupt();
+ }
+ }
+
+ public synchronized void release() {
+ if(!owner.equals(Thread.currentThread())) {
+ throw new IllegalMonitorStateException("Not Owner");
+ }
+ owner = null;
+ notify();
+ }
+ }
}